PicBasic Pro Demo Version
Simple
Remote Control


 Back To Index

This project shows how to construct a 4-button remote control system for use with Micro-Bot using the PicBasic Pro demo version compiler. We'll use the Ming 4-button TX-99K4A transmitter, Ming RE-99 receiver, and Holtek HT-12D decoder IC just like in the full version compiler RF remote control project shown HERE.

We can't add all the bells & whistles like the full version project, but this does give you a good trial run with the free demo version compiler. With a few simple components and the demo compiler you can still build a lot of nifty gadgets like this, or remote control servo positioning systems, remote window blind controllers, programmable logic ICs, and more. It's certainly worth grabbing the full version compiler at some point, but there's still a lot you can squeeze out of the free version if you're creative.


TX-99K4A 4-Button RF Transmitter


The Holtek 4-Bit Decoder IC


The Ming RE-99 V3.0A RF Receiver

The TX-99K4A transmitter uses the Holtek HT-12E 4-bit encoder IC, so we'll need the matching Holtek HT-12D decoder IC for the receiver circuit. The Ming RE-99 300MHz RF receiver module operates at the same frequency as the TX-99K4A, so we have a perfect match between transmitter & receiver. The CD-ROM has datasheets for the TX-99K4A Schematic , TX-99K4A DatasheetHT-12D, and Ming RE-99 in Adobe .PDF format.

With the demo version compiler we're limited to 31 lines of code so we'll keep it simple here. In this experiment Micro-Bot will be 100% under remote control. Review some of the other projects for code snippets you can modify and add to this project code for more functionality.

The Decoder IC:

The HT-12D decoder IC has four latching data outputs, and one momentary output. The 4-bit data pattern on output pins D0-D3 will latch, and stay at the last transmitted 4-bit value until we press another button on the transmitter sending a different 4-bit logic pattern.

Note: We can't use output pin D3 of the HT-12D. The TX-99K4A transmitter does not change this bit. As shown below in Figure#1, the HT-12E encoder inside the TX-99K4A does not have a switch connected to data input pin #13 or D3.

Switch SW-1 [button A] connects to D2, SW-2 [button B] connects to both D1 and D2, SW-3 [button C] to D1, and SW-4 [button D] to D0. There are no switch connections to D3.


Figure #1 Partial TX-99K4A Schematic

It's not shown in the partial schematic in Figure #1, but when any button is pressed power is supplied to the encoder circuit initiating the transmission of data. Releasing a button ends the transmission by removing power from the HT-12E encoder.

At the receiver end the decoders VT output pin idles at logic 0. When a transmission from an encoder with the same address is being received, the decoders VT output will transition from ground to +5V during the transmission. When we release the transmitter button and end the transmission VT returns to ground. Hence, VT gives us a momentary bit to use with the 3 latching data bits.

We'll sample the decoders VT output pin with PortA3 looking for logic 1 or +5V. If the VT output pin is logic 1 we'll jump to a sub-routine named Check_Remote to read the 4-bit binary value present on the decoders latching outputs D0, D1, D2 and the momentary VT output. Within the Ckeck_Remote sub-routine we'll determine which button on the TX-99K4A transmitter is being pressed, and alter Micro-Bots direction or command him to stop if Button D is being pressed.

To control Micro-Bot with the TX-99K4A remote transmitter, we'll want at least four basic control functions or commands. We'll assign each the of the transmitter buttons a single function as follows --:
 

  1. Button A = Reverse

  2. Button B = Left

  3. Button C = Right

  4. Button D = Stop

Whoa..! Where's forward..? We'll make forward the default direction if the VT output is idle or logic 0 since this condition indicates we're not pressing any of the transmitter buttons. This turns control back over to Micro-Bot, and he continues moving forward. Our program code will occasionally check the status of the VT output connected to PortA.3 for logic 1 to determine if any buttons on the transmitter are being pressed. If VT=0 Micro-Bot will load the value for forward motor direction, jump over the Check_Remote sub-routine, and go to the Move sub-routine to continue moving forward until we press a button on the transmitter initiating a turn or stop.

If a button is pressed PortA.3 [aliased as VT] will be logic 1, and we jump to Check_Remote, determine the button that's being pressed, and execute the command assigned to that specific button.

Data Patterns:

As mentioned previously, the TX-99K4A transmitter has four buttons labeled A, B, C and D. The four data outputs of the HT-12D decoder will provide the following data patterns corresponding to each button press on the TX-99K4A --:
 
Transmitter Button A B C D
HT-12D Data Pin D3 D2 D1 D0 D3 D2 D1 D0 D3 D2 D1 D0 D3 D2 D1 D0
Binary Logic Value 1 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1

Table #1

Knowing these data patterns Micro-Bot can easily determine which button is being pressed, and quickly react to each command from the transmitter.

The Receiver Schematic:

Below is the receiver schematic. The data output pin of the Ming RE-99 RF receiver connects to the HT-12D decoder IC pin #14. Power for the receiver module is provided by Micro-Bots regulated +5V & ground. You can wire this circuit on the Micro-Bot bread board or directly onto the circuit board.

Once you have the receiver circuit assembled, program the code below into Micro-Bot.

Note: Below we're setting PortB=%00000011. When using the PULSOUT command we want high-going pulses for controlling the servo motors. The PULSOUT command requires you to set the output pin to the compliment of the pulse you require. Hence, "0" = "1" or high pulses on PortB.4 and PortB.5 when we issue the PULSOUT command. If you've put together the infrared navigation project already, setting PortB.0 & PortB.1 to logic 1 turns the infrared LEDs off. Just in case they're still be wired in, we'll make sure they stay off.

If you skipped over the demo compiler project for infrared navigation, review the project HERE for details of how the 16-bit motor control values are being used. This may look confusing if you've skipped over the motor control discussion.

'****************************************************************
'*  Name    : RC_Demo.bas                                       *
'*  Author  : Bruce Reynolds                                    *
'*  Notes   : Micro-Bot PicBasic Pro Demo RF Remote Control     *
'****************************************************************
@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 20           ' We're using a 20MHz crystal
Remote      VAR BYTE    ' Holds data from decoder outputs
Loops       VAR BYTE    ' Loop counter variable
VT          VAR PortA.3 ' Samples HT-12D VT pin
Left_Servo  VAR PortB.4 ' PortB.4 = left servo output
Right_Servo VAR PortB.5 ' PortB.5 = right servo output
MotorDir    VAR WORD    ' Variable for motor direction values
PortB=%00000011         ' RB4 & RB5=0 "compliment of pulses", IR LEDs=Off
TRISB=%00000000         ' All PortB=outputs
TRISA=%00001111         ' Upper 4-bits=outputs, lower 4-bits=inputs

'** Turn 16F62x Comparators OFF **'
CMCON = 7               ' Comparators = OFF, PortA = digital I/O
VRCON = 0               ' Internal A/D Vref disabled

Begin:
  IF VT=1 THEN          ' If VT = active
   GOSUB Check_Remote   ' Then check remote command
  ELSE                  ' Or else
   MotorDir=$3C50       ' Move forward
   GOSUB Move           ' Jump over Check_Remote & move forward
  ENDIF                 ' End if then
  GOTO Begin            ' Keep going until we need new batteries...;o]

Check_Remote:
  Remote=PortA & $0F                        ' Read PortA and mask out upper four bits
  IF Remote=%00001001 THEN Check_Remote     ' Halt motors if button D pressed & VT=1
  IF Remote=%00001010 THEN MotorDir=$5050   ' Right turn if button C pressed & VT=1
  IF Remote=%00001110 THEN MotorDir=$3C3C   ' Left turn if button B pressed & VT=1
  IF Remote=%00001100 THEN MotorDir=$503C   ' Backup if button A pressed & VT=1

Move:  
  FOR Loops=1 TO 4                           ' Change to increase/decrease movement range
   PULSOUT Left_Servo,MotorDir.LowByte*10   ' Compute value for left servo movement & move it
   PULSOUT Right_Servo,MotorDir.HighByte*10 ' Compute value for right servo movement & move it
  PAUSE 20
  NEXT Loops
  RETURN ' Line #28. Only 3 lines left for the demo version compiler


 Back To Index

Copyright © 2007 Reynolds Electronics
http://www.rentron.com