This is a smiple project which follow or Avoid Light .
I Made this Simulation in Proteus 8.3 pro .
1) Arduino uno.
2) 3 LDR.
3) 2 Dc Gear Motors.
4) One Servo.
5) Three 1k Resistors.
6) one H-Bridge l290D
7) One on & Off Switch [for changing condition of Program]
8) 9v and 5v Battry
Step 1: Ardunio Code
Arduino Code is Modified a litte -bit Date 23 February 2016]]
This Code is Highly commented i don't want to explain but if u need some help fell free to contact me at (email@example.com)
I use two conditions in this programme
1st for Light Following .
2nd one for Light avoiding.
As far as these Conditions are satisfied Robot will Follow or Avoid Light .
[This is Minimum Value of LDR that i choose . In normal Light it's Range is 80 to 95 but as its Intensity increases more and more voltages induced accros it as it is working on the Principle of Voltage Divider
int a = 400; // Tolarance Value ]
Step 2: Proteus Files
Step 3: How Your H-bridge Works
The L293NE/SN754410 is a very basic H-bridge. It has two bridges, one on the left side of the chip and one on the right, and can control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off a low voltage so this H-bridge will work just fine. The H-bridge has the following pins and features: Pin 1 (1,2EN) enables and disables our motor whether it is give HIGH or LOWPin 2 (1A) is a logic pin for our motor (input is either HIGH or LOW)Pin 3 (1Y) is for one of the motor terminalsPin 4-5 are for groundPin 6 (2Y) is for the other motor terminalPin 7 (2A) is a logic pin for our motor (input is either HIGH or LOW)Pin 8 (VCC2) is the power supply for our motor, this should be given the rated voltage of your motorPin 9-11 are unconnected as you are only using one motor in this labPin 12-13 are for groundPin 14-15 are unconnectedPin 16 (VCC1) is connected to 5V .Above is a diagram of the H-bridge and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).
In this Project, the enable pin connects to a digital pin on your Arduino so you can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins are also connected to designated digital pins on your Arduino so you can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. If your motor can run on 5V and less than 500mA, you can use the Arduino’s 5V output. Most motors require a higher voltage and higher current draw than this, so you will need an external power supply.
Connect the motor to the H-bridge Connect the motor to the H-bridge as shown obve in 2nd picture.
Or, if you are using an external power supply for the Arduino, you can use the Vin pin.
Step 4: How LDR Works
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.
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 ValueWhere; m = slope, (rise / run), (digital value / analog value)Where; C = Y interceptThe Y intercept is 0 so that gives us:Y = mXm = 1023 / 5 = 204.6Therefore: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.