Ben the Light Following Breadboard Arduino Robot is the second robot I have made to help teach robotics to high school students in a class I teach voluntarily. The first robot also has its own Instructable which can be found here: https://www.instructables.com/id/James-Your-first-Arduino-Robot/
The video shows the construction process however it is in fast motion and I will cover some of the more complicated things here more in depth.

So to make ben you will need the following components:
·         A small sheet of acrylic
·         A breadboard
·         An Arduino Nano
·         Two Continuous Rotation Servos
·         Two hobby wheels (I used model aeroplane wheels)
·         A castor wheel
·         9V battery
·         4.8V rechargeable battery pack (or just 4 AA’s in a battery case)
·         Two Light Dependant Resistors
·         Two 10,000 ohm Resistors
·         Some breadboard jumper cables
·         Double Sided Foam Tape
·         Adhesive Velcro dots
·         A Power Switch (not necessary but would be handy)

You won’t need any tools for the construction however you could replace the Double Sided Foam Tape with Hot Glue in which case you would need a Hot Glue Gun.

Now the first thing that may need further explanation is the use of the Light Dependant Resistors. Light Dependant Resistors (or LDR’s) are resistors whose value changes depending on the amount of ambient light, but how can we detect resistance with Arduino? Well you can’t really, however you can detect voltage levels using the analog pins, which can measure (in basic use) between 0-5V. Now you may be asking “Well how do we convert resistance values into voltage changes?”, it’s simple, we make a voltage divider. A voltage divider takes in a voltage and then outputs a fraction of that voltage proportional to the input voltage and the ratio of the two values of resistors used. The equation for which is:
Output Voltage = Input Voltage * ( R2 / (R1 + R2) )
Where R1 is the value of the first resistor and R2 is the value of the second.
The circuit schematic for which looks like this
A diagram of this in our situation looks a little something like this

Now this still begs the question “But what resistance values does the LDR have?”, good question. The less amount of ambient light the higher the resistance, more ambient light means a lower resistance. Now for the particular LDR’s I used their resistance range was from 200 – 10 kilo ohms, but this changes for different ones so make sure to look up where you bought them from and try to find a datasheet or something of the sort.

Now in this case R1 is actually our LDR, so let’s bring back that equation and do some math-e-magic (mathematical electrical magic).

Now first we need to convert those kilo ohm values into ohms:
200 kilo-ohms = 200,000 ohms
10 kilo-ohms = 10,000 ohms
So to find what the output voltage is when we are in pitch black we plug in the following numbers:
5 * ( 10000 / (200000 + 10000) )
The input is 5V as that is what we are getting from the Arduino.
The above gives 0.24V (rounded off).
Now we find what the output voltage is in peak brightness by using the following numbers:
5 * ( 10000 / (10000 + 10000) )
And this gives us 2.5V exactly.

So these are the voltage values that we are going to get into the Arduino’s analog pins, but these are not the values that will be seen in the program, “But why?” you may ask. The Arduino uses an Analog to Digital Chip which converts the analog voltage into usable digital data. Unlike the digital pins on the Arduino that can only read a HIGH or LOW state being 0 and 5V the analog pins can read from 0-5V and convert this into a number range of 0-1023.

Now with some more math-e-magic we can actually calculate what values the Arduino will actually read. Because this will be a linear function we can use the following formula:
Y = mX + C
Where; Y = Digital Value
Where; m = slope, (rise / run), (digital value / analog value)
Where; C = Y intercept
The Y intercept is 0 so that gives us:
Y = mX
m = 1023 / 5 = 204.6
Digital value = 204.6 * Analog value
So in pitch black the digital value will be:
204.6 * 0.24
Which gives approximately 49.
And in peak brightness it will be:
204.6 * 2.5
Which gives approximately 511.
Now with two of these set up on two analog pins we can create two integer variables to store their values two and do comparison operators to see which one has the lowest value, turning the robot in that direction.
Now that was probably the most complex thing about the whole robot build however there is just one more thing that I would like to mention and it’s to do with using servos with Arduino.
There are several tutorials and diagrams on the internet showing that you must connect the voltage in of the servo up to the 5V rail of the Arduino and the ground of the servo to the ground of the Arduino, this is dangerous! Servos can draw a lot of current, and in most cases that current draw will be more than the voltage regulator on the Arduino can supply, this will lead to bad things happening. The proper way to hook servos to your Arduino is to use an external power supply. In Bens cause I am running the continuous rotation servos of a 4.8V rechargeable Ni-Cd battery pack, this is ideal as the servos operate well from 4.8-6V, 6V being the peak charge voltage of the battery pack.

Now you may be tempted to just hook up V+ of the battery to the V+ of the servos and the GND of the battery pack to the GND of servos and the signal pins to the Arduino, this won’t work either! You need to remember that electricity needs to flow from one ‘point’ back to its original point, not connecting the ground of the servos and battery pack to the Arduino’s ground won’t allow the electricity to flow from the signal pins.
Here is a diagram showing the proper circuitry

Combining the two diagrams shown earlier gives the complete circuitry required to make Ben.
Now I won’t explain the code as it is heavily commented and should pretty much explain itself.

<p>Hello , we have some problems with our school project. We also build a light following robot and we really want to see you circuit and arduino code if it's possible? We hope you can help us?</p>
Error occuring in code link :(<br>
Error occuring in code link :(<br>
<p>black holer</p>
<p>Arduino: 1.6.7 (Windows 10), Board: &quot;Arduino Nano, ATmega168&quot;</p><p>Build options changed, rebuilding all<br>Multiple libraries were found for &quot;Servo.h&quot;<br> Used: C:\Users\Shane\Documents\Arduino\libraries\Servo<br> Not used: D:\Shane\Arduino\libraries\Servo</p><p>Sketch uses 2,552 bytes (17%) of program storage space. Maximum is 14,336 bytes.<br>Global variables use 65 bytes (6%) of dynamic memory, leaving 959 bytes for local variables. Maximum is 1,024 bytes.<br>avrdude: ser_open(): can't open device &quot;\\.\COM1&quot;: The system cannot find the file specified.</p><p><br>Problem uploading to board. See <a href="http://www.arduino.cc/en/Guide/Troubleshooting#upload" rel="nofollow"> http://www.arduino.cc/en/Guide/Troubleshooting#up...</a> for suggestions.</p><div> This report would have more information with<br> &quot;Show verbose output during compilation&quot;<br> enabled in File &gt; Preferences.</div><p>this is what coming</p>
<p>I cant program aurdino nano what will iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii doooooooooooooooooooooooooooooooo</p>
<p>Is it possible for you to re-upload the circuit schematics and code? Also would this work with a MEGA arduino board instead of a NANO?</p>
<p>I have just found the chickenparmi robotic resource-a-rama. I am a robo-newbie so i will be bookmarking, breadboard, and prototyping all I can to learn more about fascinating part of the hobby of electronics </p>
<p>But the links are not working? Maybe I was wrong about the value of the chickenparmi robot knowledge repository? I will dig a bit more.</p>
<p>does it matter if they are female to female or male to male jumper cables</p>
<p>when i put in the black jumper cable into the servo cable i put the tip in and the the servo goes but putting the whole thing in the servos don&rsquo;t go</p>
I am totally new with arduino. So if I use arduino uno instead of nano then do I just have use the power jack for adrino uno. Is there any changes further? <br>
Could this also work with an ardunio UNO instead of a nano?
Ofcourse! The Uno and Nano are essentially the same thing just with a different form factor. It would make its placement on the board a little more difficult but it would work all the same.
How about there Wiring? <br>Does Nano have the same Pins as Uno?

About This Instructable




Bio: Robot fanatic.YouTuber. Robotics teacher.
More by chickenparmi:Making an Arduino Powered Curtain Automation Arduino Powered Jack-O'-lantern Toilet Paper Roll Spooky Eyes 
Add instructable to: