Introduction: PIC Based LF and Avoiding Robot
In this instructable you will learn to make a light following and avoiding robot. My inspiration comes from robots imitating common human behavior, for example you will not just walk into a wall for no reason. Your brain communicates with your muscles/ organs and immediately will stop you. Your brain works very similarly to a basic micro-controller receiving inputs and processing them into outputs, in this case your brain relies on your eyes for information. At the same time it's acceptable to walk into a wall when one is blind. Your brain receives no inputs from your eyes and cannot see the wall. This robot will not only be a complete build at the end but a cool learning experience about basic electronic components, DIY, and design skills to create something, and I know you will enjoy it. I know there are a lot more easier and conventional methods where you don’t have to build circuits yourself and use basic modules to achieve the same result but I took a more different approach, besides if you are a DIY nut like me and looking to learn something new this is the perfect project for you! This robot will follow the light and when a feeler touches the wall it will reverse and turn, so these are the basic functions for this robot. Hope you enjoy me project!
Step 1: List of Materials
· 10K resistor, ¼ watt (x20)
· 2.2K resistor, ¼ watt (x10)
· 4.7K VR (x2)
· 10K VR (x2)
· 1K resistor, ¼ watt (x10)
· 220 ohm resistor, ¼ watt (x4)
· 22K resistor ¼ watt (x10)
· 10pf ceramic (x5)
· 2200uf electrolytic, 25V (x2)
· 10nf ceramic (x4)
· BD 139 NPN power transistor (x4)
· BD 140 PNP power transistor (x4)
· BC 327 PNP transistor (x4)
· LM350 voltage regulators (x2)
· 741 op-amp (x2)
· 4011 Quad NAND (x2)
· PIC16F628A microcontroller (x1)
· LED 5mm (your choice of colour) (x3)
· Plywood board sheets
· 5mm x 60mm spacer nut (x4)
· 5mm x 20mm bolt (x8)
· Geared motors 12V 500mA (x2)
· 60mm foam wheels (x2)
· Female heather (jumper) connectors (x50)
· 12V, 7.2Ah Gate motor battery (optional, smaller battery can be used but make sure that it is 12V).
· 2mm wire (10m)
· Male heather (jumper) connector pins (x50)
· 3mm heat shrink tubing (2m)
Step 2: Building Circuits
Building the circuits is fairly straight forward, this is a great learning experience for those who never done it before and good practice for those who have. You can always try a different method but I prefer using Veroboard because it’s easier with the tracks going across for soldering on. I recommend before building the actual circuit to make a model on the bread board and to design your Veroboard layout for your circuit on paper, this sounds like a lot of work now but it will pay off when building your circuits (especially for the reference points).
The H-Bridge is a circuit that is responsible for the driving of your motors which receives signal from the micro-controller and either stops or reverses the motors (this is a modified H-Bridge with the 4011 which acts as protection circuitry and adds more control features). Below are images of the circuit diagram, the Vera board layout and the final circuit (Remember to build 2 H-Bridges, one for each motor).
Step 3: Building LDR Circuits
The LDR circuits act as eyes to the robot which sense the presence of light and sends a voltage signal to the PIC micro-controller, in order to amplify the voltage signal for the PIC I used an 741 operational-amp. Remember to build 2 circuits, one for each eye of the robot.
Step 4: Building PIC Supporting Circuit
This is the circuit that is the brain of the robot.
Step 5: Building Voltage Regulating Circuits
The main voltage supply coming into the robot will be 12V, this means that there must be a voltage regulator on the H-Bridge circuits because they work on 9V and on the PIC and LDR circuits which both work on 5V. The voltage must also be stable to not damage components, these circuits will regulate the voltage, remember to build 2 circuits. (All the images are below). After you complete the circuits set them to the right voltage by turning the VR and measuring using multi-meter. Remember LDR and PIC circuits need +5V. And H-Bridges need +9V.
Step 6: Adding Pins to Circuit
Now that you have built your circuits it’s time to solder on the header pins. Another method is to solder wire straight to the board, but I find that wire breaks are more common then. To determine where to solder the pins look on the Veroboard layout of every circuit, in the keys underneath the circuit design you will find the symbols for the header pins and then just look on your circuit design, count your holes on the board to follow the layout and then just solder the pin. (The symbol which you must look for will be provided in an image).Remember to choose the correct layout for the correct circuit.
Step 7: Breaking Tracks of Veroboard
Your circuits are almost finished; the most important thing left to do now is to break the tracks on the Veroboard. Again follow the same principle using the keys on each circuit to determine where to break the tracks, make sure you break the tracks all the way through, I used a craft (hobby) knife. (An image of the key and an example of a track break will be provided).
Step 8: Coding the PIC
Now that you have completed your circuits you can start doing the main part of the robot, coding the PIC, coding the PIC is straight forward, the code was written in MPLab X, the source code and firmware file (.hex) is provided in the zip package. To flash the firmware to the PIC controller you can use any programmer available.
Step 9: Inserting Microchips
Now that you have completed most of your work with circuits it’s time for the final thing, inserting the microchips. This is a fairly easy task but it is still tricky, most of your microchips come in weird sponges when you buy them from the store, you might wonder why but the chips are static sensitive which means that you cannot touch them with your hands unless you are wearing a static band. This includes the 4011’s and the PIC, so be careful and do not touch the pins of these microchips otherwise you will damage them. (Make sure that you are inserting the chip to the correct side, an example will be provided).
Step 10: Testing Circuits
Your circuits are now complete; it’s time to test them! To test your circuits you will need a multimeter (a multimeter is a device that measures differences in voltage, current and resistance), fortunately the modern multimeter has a few more functions. First of all you have to do a basic visual inspection of the circuit, checking for any cracks, wire breaks and disconnections. After you are happy about that it’s important to check all the polarities in the circuit, for example: your transistors should be the right way around and your microchips should be inserted properly. After that it’s time to check the underside of the circuit board, check for any shorts in between the tracks visually and then just to make sure take a craft knife and just slice it in between the metal tracks of the board to make sure. The final thing to look out for are your breaks, do a visual inspection of each break in your circuit to make sure that the track is broken all the way through. To check properly you need to adjust your multimeteres setting to continuity (an image will be provided below) and put one lead to the one side of the Brocken track and the other lead to the other side, if your multimeter beeps your break is faulty and you need to re-do it. I advise testing each circuit individually to not get confused. (Fix all your faults before doing the next step). Remember to run the circuits with proper voltage regulation:
· H-Bridges: 9V
· LDR + PIC: 5V
Step 11: Assembling Robot Body
Now that your circuit work is done it’s time to do some DIY, now we will be assembling the top part of the robot. The top part basically consists of all the circuitry and sensors. First of all you need to drill holes in your plywood board for the spacer nuts and screws, drill the one centimeter from side on each corner (it’s not really important where you choose to drill your holes as long as your structure is stable and it corresponds to the holes drilled on the bottom board). Now there is some more drilling to do…..if you choose to mount your board on spacer nuts you need to drill hoes for them (see the diameter of your nut and choose drill bit accordingly), you also need to drill holes in your circuit, be careful when doing that to not damage the board and choose where you want the holes to be according to the layout of your circuit board (to not damage tracks). Another easier method is to just glue the boards onto the plywood (when doing so try to stick to my layout, H-Bridges mounted at the back etc.)
Step 12: Assembling Robot Body (part 2)
Now that you have assembled the top part, its time to assemble the bottom part. The bottom will house all the voltage regulators, the driving motors and capacitors. Your first step will be mounting the motors on the plywood board. I prefer two basic ways to mount motors, either you mount them in the middle of the plywood panel or on one side of your choice. If you choose to mount motors on the side you need to remember to purchase a front flywheel to help the robot balance and maneuver it self properly. Remember to do some basic measurements and checks before properly mounting your motors, I recommend mounting the motor with cable zip ties which is cheap and easy to complete, first hot glue your motor according to your desired measurements then drill two holes on two sides of the motor in the plywood and just use a zip tie to hold it (remember to tighten your zip tie properly). Putting on regulators and the capacitors will be easy (improvise with the space that you have on the plywood) and mount them on using spacer nut method or hot glue, (I recommend gluing the capacitors). Finally drill holes for mounting the top board on (use the same measurements as you did on the top part), I recommend drilling smaller holes and press fitting the spacer nuts in.
Step 13: Wiring
Now that you have soldered, checked and mounted your circuits its time to wire the whole thing together. The basics of the wiring are that all the circuits will eventually be wired to the PIC which will process and send information, remember that your wiring is very important and you must make sure that everything is correct. Ok, now for how to wire, now you get why I chose to go with the heather pin method because it makes it easier. If you have female jumper wire you can quickly connect the boards together, if not you can just solder normal wire on the heather pin (jumpers are better because if you have mistaken pins you don’t have to re-solder). A wiring diagram will be provided in the image.
Step 14: Attaching and Connecting Feelers
Your robot will use two feelers to sense the wall in front of it. Attaching the feelers is fairly simple, its basically two micro switches acting as left and right feeler. Hot glue them on the front of your second board. The circuit diagram of the connections will be provided below. (Remember to figure out micro switch pins eg. COM).
Step 15: Testing Robot
Okay, this is the exiting moment that you have been waiting for, to finally fire up your robot for the first time!! Don’t get too exited now this never works the first time, if it does YOU ARE ONE LUCKY BUILDER!! Now don’t get disappointed if it does not work, don’t worry it will definitely soon. Below I have made a list for all the possible problems that you might face and how to solve them.
· The whole thing does not do anything. Check the power supply circuits and connections to power pins of the board, also check for polarity issues.
· Motors turning in opposite directions. Swap one motors polarity it should send it turning the other way, might also be a programming issue.
· Something starts smoking or you feel that something is realy hot. SHORT CIRCUIT!! Switch off immediately to avoid damage. Check all possible circuits including wire connections.
· Motors turn really slowly. Increase current to robot. Or possible H-Bridge shortage.
· Robot is not sensing light properly. Adjust VR on LDR circuits, can be a programming issue.
· Robot is behaving unusually and doing weird things. Programming! Double check programming code.
· Robot not sensing the wall. Check connections on micro-switches.
So these are the problems that happened to my robot, if you have an unusual problem feel free to change or modify my designs for the better, remember we are all learning and there is no such thing as perfect.
Step 16: Trial and Error
If after many hours of trying, checking and testing your robot still does not work, don’t throw it against the wall or tear it apart and loose hope. Try walking outside just getting some fresh air or just sleep on it, I have had many moments like that, and do you know why? Electronics is one hard hobby, one component fails- everything fails. Don’t forget to break it down into sections while testing and always keep an open mind with design and layout. Be free and creative and never give up!!! If you liked my project please vote me in the make it move contest, hope you guys enjoy it!
We have a be nice policy.
Please be positive and constructive.