Home | Store | Showcase | Forums | Examples | Guides | Reviews | Support | Download | About Us

Beginner's Robotics on $50 a Month - Online Project Instructions, Part 2


CIRCBot

Building the CIRC Bot

This project accompanies Part 2 of Servo Magazine's series, Beginner's Robotics on $50 a Month. It covers the top-side assembly, programming, and troubleshooting of the CIRC Bot. The instructions for building the programming cable and base assemblies were included in the magazine article.

The Part 2 kit is available here.

Click here for the Bascom source code used for  CircBot (zipped).

Top Assembly


Figure 20 
(Click for Larger Image)

The top assembly consists of the microcontroller and several supporting circuits: programming, power, H-bridge, & Light Sensors. The schematic for the complete circuit is shown in Figure 20 and in the top view picture Figure 21 which is a repeat of Figure 1 in the magazine article. 

For each of the following sections, there will be a build table that lists what to add and where to put it. For wires listed in the table, a length is included. The length listed is the length of the insulated portion of the wire. Add 10 mm (just under a half inch) to this length when you cut the wire. Once the wire is cut, strip the insulation off of 5 mm (a little less than a quarter inch) of the wire on each end and bend the stripped pieces ninety degrees. The stripped ends will be what you push into the sockets on the breadboard.

The rows on the power and ground rails may not exactly match up with the rows for the rest of the sockets on the breadboard. For components that connect into these rails I have listed the row number that is closest to the correct location on the rails I used. This is a matter of interpretation and may vary from board to board. You may look at the same location on your breadboard and say that it is one row higher or lower. When in doubt, look at the pictures. Remember, this bot is easy to reconfigure. If you place something in the wrong place, all you have to do is pull it out and move it,


Figure 21: CIRCBot

Power Circuit


Figure 22: Regulator with Bent Lead

We will start by building the power circuit at the back end of the bot, which is the end with the wheels and is the end furthest away from row 1. The power circuit consists of the battery holder that you attached to the bottom of the bot, a large capacitor, several small capacitors, a voltage regulator, and the wires to connect everything to the power and ground rails. You will have to bend a lead on the voltage regulator as shown in Figure 22 to get it to fit into the breadboard in the correct place. Figure 23 lists what goes where.

 

 

 

 

Piece Connection Points Length or Comments
Wire (black) A62 to Upper GND 61 7mm
L7805CV voltage regulator A60, Upper GND & V+ 60 see Figure 22 for orientation and how to bend leads
Wire (red) E60 to F60 7mm
Wire (black) Upper GND 59 to Lower GND 59 45mm
Wire (red) Upper V+59 to Lower V+59 45mm Twist with red wire
2200 uF Capacitor C60 & C62 negative lead at C62
Red Battery Lead G60  
Black Battery Lead E62  
0.1 uf Capacitor Lower V+58 to Lower GND 58  
0.1 uf Capacitor Upper V+58 to Upper GND 58  
0.1 uf Capacitor Upper V+41 to Upper GND 41  
0.1 uf Capacitor Lower V+42 to Lower GND 42  
0.1 uf Capacitor Upper V+33 to Upper GND 33  
Figure 23: Power Circuit

Microcontroller and Programming Circuit

This circuit contains the microcontroller and the wires that connect microcontroller to the sockets where the programming cable is connected to the breadboard. The programming cable will be plugged into H46 through H50. It is a good idea to take a marker and mark these socket holes. The programming cable is plugged in with the ground wire in socket H46. Mark H46 with a different color than the other sockets. This will make it easier to remember which way to plug the cable into the socket. Figure 24 list what goes where.

Piece Connection Points Length or Comments
ATMega8 microcontroller Pin1 at E31, pin 15 at F44 Pin 1 is toward the front of the bot.
Wire (green) D31 to F48 47mm bend to go around the microcontroller RESET
Wire (black) Lower GND 45 to J45 10mm GND
Wire (green) I42 to I49 18mm  MOSI
Wire (green) J41 to J46 13mm MISO
Wire (green) J40 to J47 18mm CLOCK
Wire (black) Upper GND39 to C38 13mm 
Wire (red) Upper V+39 to C37 15mm
Wire (red) Lower V+39 to I39 10mm
Wire (red) Lower V+37 to I38 10mm
Wire (black) Lower GND 37 to I37 13mm
100 K Ohm Resistor
Brown-Blac-Yellow
Upper V+30 to B31 12mm
Figure 24: Controller Circuit

H-bridge Circuit

This is the circuit that allows the microcontroller to run the motors. The microcontroller is protected from noise feedback from the motors by the resistors on each of the control lines. Note that you need to add either pieces of shrink tubing or pieces of insulation that you stripped from wires to the leads of the resistors so that the resistors do not short out against each other. Also note that you have an even chance of wiring each motor up backwards. That's OK. You will be able to tell if this has happened when you run the demo program. If the motor is wired wrong, just switch the location where its two wires are connected. Figure 25 lists the items and where they go. Please note that the bent parts of the leads on some of the resistors have to be different lengths so that the resistors can clear each other when you assemble the circuit.

Piece Connection Points Length or Comments
SN754410NE H-Bridge Pin 1 at F57, Pin 9 at E50 Pin1 faces back of bot
Wire (red) Upper V+57 to B57 13mm
Wire (black) Lower GND 54 to I54 13mm
Wire (black) Lower GND 53 to I53 13mm
Wire (black) Upper GND 53 to C53 12mm
Wire (black) Upper GND 54 to C54 12mm
360 Ohm Resistor
Orange-Blue-Brown
D50 to G44 20mm slide heat shrink over the leads
360 Ohm Resistor
Orange-Blue-Brown
G43 to G57 36mm slide heat shrink over the leads
360 Ohm Resistor
Orange-Blue-Brown
D44 to G56 34mm slide heat shrink over the leads 
(double the bent lead length)
360 Ohm Resistor
Orange-Blue-Brown
C43 to C51 21mm slide heat shrink over the leads
360 Ohm Resistor
Orange-Blue-Brown
C42 to I51 29mm slide heat shrink over the leads 
(double the bent lead length)
360 Ohm Resistor
Orange-Blue-Brown
B41 to B56 38mm slide heat shrink over the leads
Wire (red) J50 to J60 26mm
Upper Motor Leads One to D52, One to D55 Switch leads if motor runs in wrong direction
Lower Motor Leads One to J56, One to J52 Switch leads if motor runs in wrong direction
Figure 25: H-Bridge Circuit

Light Sensors' Circuit

Up to now, you have just built a platform. To make a true robot, it has to be able to sense something in its environment and change its actions based on what it senses. The CDS cells in this circuit will sense light intensity in two directions. Install the components shown in Figure 26. When you install the sensors, twist them so that the one on the left side of the bot points forward and slightly to the left and the one on the right side points forward and slightly to the right (Refer to Figure 21). The sensors are connected to analog to digital (A/D) inputs on the microcontroller. This will allow the microcontroller to measure light intensity to the right and left of the bot. With this information, the program can be configured to cause the bot to either turn toward or away from a light source.

Piece Connection Points Length or Comments
Wire (green) F2 to G32 78mm
Wire (green) E2 to G31 75mm
Wire (black) Upper GND 3 to A1 7mm
Wire (black) Lower GND 4 to J1 14mm
360 Ohm Resistor
Orange-Blue-Brown
Upper V+5 toA2 11mm
360 Ohm Resistor
Orange-Blue-Brown
Lower V+5 to J2 12mm
CDS Photocell E1 and D2 Twist cell to the left
CDS Photocell F1 and G2 Twist cell to the right
Figure 26: Light Sensor Circuit

Programming

Now that you have the CIRC Bot and its programming cable built, it is time to test it. Make a directory on your PC where you are going to save programs for your CIRC Bot. Go to the SERVO website or Click Here to download the program "CIRC_bot_shell.bas" that goes with this article to the directory you just made. 

Install BASCOM AVR on your PC following the instructions at the MCS website. Start the program and click on "Options" on the toolbar. In the dropdown box that opens, pick programmer. This will cause a popup box to open where you can select the type of programmer you have. Select "Sample Electronics programmer" and click OK.

Click on the folder icon in BASCOM. This will open a popup window where you can choose a file to open. Browse to the folder you created and pick "CIRC_bot_shell.bas". A popup window will open showing you the program listing. You will need to compile the program by clicking Program on the toolbar and then compile in the options (or just hit the "F7" function key).

Once the program is compiled, it needs to be transferred into the CIRC Bot. Install four AA batteries into the bot. Take some small blocks and put them under the bot so that the wheels don't touch the table. Attach your programming cable to your PC and to the bot. Remember to put the connector in correct direction (that is why you made the socket hole for the ground wire a different color). Now turn the bot on.

In BASCOM, click Program on the toolbar and then send to chip (or hit "F4'). The programmer window will come up and identify the correct chip, however, it might not actually download the program to the bot. In the programmer window, hit the erase chip button, then the program button, and finally the compare chip to buffer button. If the programmer responds Ok, you have just programmed your robot! Switch the robot off, unhook the programming cable and set the bot on a floor. Now turn the switch back on and see what your bot can do!

The program you loaded is broken up into sections and is commented fairly well so I won't go into much detail about it here. Use the help guide and the BASCOM manual to learn what the individual commands do. 

The program is initially set up to run a blind demo. In this demo mode, the bot will go through a series of motions: 

Turn in place left
Turn in place right
Go forward
Go backward
Go forward & right
Go forward & left

If the bot moves, but does not do these motions in this order, one or both of your motors are connected backward. Simply switch around motor wires and try again.

By changing out some comment marks (') where indicated in the program, you can switch from the blind demo to a turning in place light sensor demo. Notice that the robot does not weathervane directly to the brightest source of light. This is because the two CDS cells are not exactly matched (unless you are incredibly lucky). You could measure each CDS circuit using your multimeter under the same lighting conditions and add a variable resistor to tune the two circuits to match. You could also wait until next month when we add an LCD display and use that to find out what values the two sensors put out under the same conditions. A final option would be trying adding various offset values to the formula in the program that compares the output from the CDS cells, recompiling and running the program with each change and see what happens.

Troubleshooting

Just like last month, there is a possibility that things did not go right. Your robot may either just sit there or one of the motors runs while the other does not turn at all. Worse yet, the programmer may say that the microcontroller is not found and you can not download the program. If any of these things happen, consider yourself lucky. You get to apply the troubleshooting tips described in last month's article to your CIRC Bot.

If a motor refuses to turn, pull its leads from their regular positions and connect them directly to the V+ and GND rails and turn on the power switch. If the motor now turns, the problem is in the connections to the H-bridge. Turn the power off and put the wires back into the correct place and check that all the connections in the H-bridge circuit match what is in the table. If they match the table, look for short circuits between various lines from the microcontroller to the H-bridge chip. Use your multimeter to read resistance between each microcontroller pin that is wired to the H-bridge and all of the pins on the H-bridge chip (with the robot's power turned off). You should only get a reading on one pin of the H-bridge chip. If you get readings on two pins, you have a short. Look at the wires and especially the resistor leads for the two lines that are shorted. Somewhere there is metal touching metal. If you can not find a short, completely reverse the connections for the left and right motors of the H-bridge; both where the motors are connected and where the signals are connected form the microcontroller. 99% of the time, you will find the problem in one of these steps. It is extremely rare that a new motor control chip is fried, but if all else fails, replace the chip.

If you are getting an error while trying to program the microcontroller, start by looking at your programming cable using your multimeter just like you checked your circuits last month. If all the lines are correct (no short circuits, no open circuits, all the ground pins are connected together), your next step is to check the wiring on you bot. Are all of the wires listed in the microcontroller and programming circuit table run between the correct locations? Is the pull up resistor connected between the right pin and V+ ? Are all of the ground lines connected to the correct pins and to GND rails instead of V+ rails? Is the chip in the correct way? Did you have your programming cable plugged in the right way?

If the bot only turns in one direction when you modify the program to do the light sensor test, you should first try removing the CDS cell on the side toward which the bot is turning. The bot should now turn in the opposite direction. Putting the CDS cell back in place should cause it to go back to turning the original direction. Swapping the two cells should cause the direction to reverse. If this happens, there is not a problem; it is just that your cells are nowhere near matched.

If one of those steps is unsuccessful, the problem is in your circuit. Compare all the connections to the build table and trace them using the multimeter.

Variations

The whole point of the CIRC Bot is to learn how to work with the basic components that go into most robots. Up to now, you have been merely following assembly instructions. Now it is time to strike out on your own. Fortunately, it is not uncharted territory. Many nice people have taken the time to explain things that they know about robotics on web sites that you can easily find with Google. Here are some suggestions to get you started:

Better H Bridge Configurations

The H-bridge design I showed you on this robot is fairly common, but it has one drawback, the robot looses torque as it goes slower. This means that below some speed, it will not be able to overcome its own static friction to begin moving. By changing the way the H-bridge is connected to the microcontroller and modifying the program, you can make a locked-antiphase PWM control. To figure out how to do this, start at http://www.barello.net/Papers/h-bridge.pdf where Larry Barello explains what H-bridges are, how PWM works, and how to configure different types of motor control. To figure out how to change the program, go to the BASCOM AVR forums on the MCS Electroincs website http://www.mcselec.com/index2.php?option=com_forum&Itemid=59 and look through past postings.

Fun with CDS Cells

CDS cells are resistors whose resistance values vary with the amount of light. The build instructions had you make two voltage dividers each utilizing a CDS cell and a regular resistor connected in series between V+ and GND. Each of the analog to digital converter inputs read the voltage value between a CDS cell and a regular resistor. This required two A/D converters on the microcontroller. You could make a single voltage divider utilizing both CDS cells (and probably at least one other resistor to balance the circuit) that would tell you which cell was exposed to a brighter light. Such a setup would require only one A/D converter on the microcontroller.

You can also read the cells using a regular digital input instead of an A/D converter. Remember that while we normally consider 0 volts to be a digital 0 and 5 volts to be a digital 1, there is actually a wide band of voltage that the microcontroller will accept for each. Find out what those ranges are and how to tune your voltage divider using a variable resistor (trimmer pot) so that a brighter light on one side would produce a voltage in the digital 0 range and brighter light on the other will produce a voltage in the digital 1 range. 

The voltage where the change occurs is at a slightly different value in each chip manufactured. Your sensors will pick up electrical noise. This will cause their output to vary slightly even in constant lighting. When you are near the switch over voltage, this noise will cause the digital signal to flip back and forth between 1 and 0. There are several ways to remove this undesirable characteristic. One way uses what is called a Schmitt trigger.

All of the examples so far have had the bot switching between turning left and turning right. You really want a third option where the bot goes straight ahead unless the difference in lighting between the two cells is above a certain threshold. There are many ways to do this in both software and hardware.

Finally, you can also make a simple line follower by bending the CDS cell leads so that the cells point downward and adding a light to the front of the bot. 

Conclusion

When you finish the work described in this month's article and online supplement, you can honestly say that you built a robot. Next month we will greatly enhance your robot's sensor suite and we will add a LCD display so your bot can tell you what it is thinking. Until then, have fun with your project!