How to build a robot: Robot with a brain! Part II

Part II tutorial shows you:

  • How to avoid objects using switches.
  • Connect and use a wireless receiver.

  1. It is very simple to install switches on the front of your robot. I used screws to mount mine since this is the most sturdy way to do it, but you could hot glue them if you wanted to for a not-so-permanent installation. Interfacing the switches with the microcontroller is also very simple. Picaxe publishes a PDF on how to interface with inputs and outputs: Interfacing Circuits. Using a switch as an input requires a switch, 1k ohm resistor, and a 10k ohm resistor. Connect the 1k resistor from an input pin and connect the other end to an open row on your breadboard. Connect the 10k resistor from the 1k in the empty row to ground. This makes 11k ohms between the input pin and ground which means that the normal state is always LOW. You can arrange it to be always HIGH, but I just prefer the normal LOW state. Then connect the common tab of your switch to +5 volts. Connect the NO (normally open) tab of your switch to the junction of the 1k and 10k resistors.
    I used two switches for the bumper, but I only connected them to one input. You could use two inputs and make your robot more intelligent by knowing which side is being bumped. I’ll keep this ‘bot simple for now. Below is the code for my switch. Change the comments where you want your other operational or avoidance actions to be.

    MAIN:
    //other code here
    IF PIN0 = 1 THEN GOSUB OBSTACLEAVOID
    //more code here
    GOTO MAIN
    OBSTACLEAVOID:
    //code to go backwards? spin around? fly?
    RETURN
  2. Just in case you were wondering about our PIR, we installed it and learned how to use it, but for now we will just let it be. It will be more useful when we can have “programs” for our robot.
  3. Next, let’s give our ‘bot manual control with a 433MHz remote control system. This is too easy. It plugs right into 7 slots in the solderless breadboard. Connect pin 1 to +5 volts and pin 3 to ground. The outputs are as follows: Pin 2 is data ok, Pin 4 is B, pin 5 is D, Pin 6 is C, and pin 7 is A. The datasheet from HVWTECH.COM is wrong for my receiver. Check yours to be sure it is correct before assigning functions.
    Connect the outputs from the receiver to inputs on your Picaxe. Make a note of what goes where. Now, you can program your ‘bot to respond accordingly to each button. The code below is just an example. There are many ways to implement your functionality. Using the IF statement is just one way to do it.
    MAIN:
    //OTHER CODE

    IF PIN1 = 1 THEN
    //DRIVE FORWARD
    ELSE IF PIN2 = 1 THEN
    //DRIVE REVERSE?
    ELSE IF PIN3 = 1 THEN
    //LAUNCH TORPEDO
    ELSE IF PIN4 = 1 THEN
    //TOGGLE HEADLIGHTS
    ENDIF
    //MORE CODE
  4. I wanted to have the line follower installed, but I do not have a good enough soldering iron yet to assemble the wires. It is an advanced project, and I think I might have messed mine up with a bad solder/desolder/solder point. With small PCBs there is no room for error.
  5. Let us make our ‘bot be able to tell the difference in light conditions. LDRs or Light Dependent Resistors are a low cost way to do this. It’s also very simple. We will use 2 ADC inputs. But first, let’s solder some leads to our LDRs and drill two holes for the LDRs to stick out of our ‘bot. Once you finish soldering the leads to the LDRs, thread them through the holes that you drilled. Plug one end of each LDR into the +5V rail. then insert the other end of the LDR into an empty row of the solderless breadboard. Then connect a 100k resistor to each end of the LDR and connect the other end of the 10k resistors to ground. Finally, at the junction of the LDR and the 10k resistor connect a jumper wire from there to the ADC input of the Picaxe. Now all we need is a program snippet to use the LDRs.
    You might want to debug the LDRs first to get a feel for the light in your house/shop. The ADC ranges from 0 to 255. 255 is bright light on your LDR, if you bought the CDS photocell from HVWTECH.com. 0 is complete darkness. I like my ‘bot to have little programs that search out either the lightest or darkest spot.
    MAIN:
    READADC2,B0
    READADC3,B1
    DEBUG
    GOTO MAIN
    This will help you to know what is going on with your LDRs. You can be creative with what you do with this info. If B0 (right side) is larger than b1 (brighter), do you want to drive toward it or away from it? Do we want to use some advanced techniques to store the brightest light found and the location of it in case we can’t find anything brighter? Anything is possible with the right sensors and programming. I only show the simple here to teach you how to use these things, but it can be taken much further.
This entry was posted in Electronics and tagged , , , by robbie. Bookmark the permalink.

About robbie

I am an electronics enthusiest and a ham radio operator (W1RCP). I like to play with electronics. It's fun and educational. I looked forward to working in the engineering field in the future. I have a BS in Electronics Engineering Technology from DeVry University. I also have an Associate's degree in Marketing Management from Moultrie Tech, and a diploma in Electronics from MTC.

Comments are closed.