Light Following Robot (Lighttode)

by robotuck_98 in Circuits > Arduino

3853 Views, 23 Favorites, 0 Comments

Light Following Robot (Lighttode)

10168381_528206840633803_1785644021_n.jpg
10168365_528206843967136_2120144981_n.jpg
I made this light following robot some time ago. It's a really simple robot with simple parts.
 
PARTS:

arduino uno
3 photoresistors
3  2.2k resistors
 jumper cable wires 
2  servos (continuous 360 rotation)
9v battery






10149397_528206837300470_1435778822_n.jpg
1422534_603496763073984_1023224670963966420_n.jpg
First, take a piece of cardboard, or something that you could use as a base.

Then, place an arduino uno on it.

Also, place 2 servos on the back of the cardboard.

*You can use double sided tape to do so.

 To test the servos use the following code:

#include <Servo.h>

Servo servo;

void setup()
{
  servo.attach(12);
}

void loop()
{
  servo.write(0);
}

arduino_ldr.png
Now, if you have tested the servos, then it's time to test the photoresistors!
 
First, take a photoresistor and connect one side to the vcc, or you can also connect it to pin 3. 

Connect the other side to the 2.2k resistor and connect the resistor to gnd. 
 
Connect the same side to pin A0.

Test this code if you are using pin 3:

int sensor1=3; //  vcc pin
int input1=0;
int LDRvalue=0;
int light_sensetivity=500;
void setup()
{
  Serial.begin(9600);
  pinMode(sensor1,OUTPUT); 
  digitalWrite(sensor1,HIGH);
}
void loop()
{
  LDRvalue = analogRead(input1);
  Serial.println(LDRvalue);
  delay(50);
}

test this if you are using vcc
 
int input1=0;
int LDRvalue=0;
int light_sensetivity=500; // for further use
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  LDRvalue = analogRead(input1);
  Serial.println(LDRvalue);
  delay(50);
}


10003384_603496819740645_5652850508737411192_n.jpg
10003892_603496789740648_994853200225392557_n.jpg
10168468_528206847300469_1739992251_n.jpg
10151691_528206833967137_1382737395_n.jpg
Now it's a time to put everything together.

First, connect the servos to the arduino uno:
 red = vcc ,black = gnd, white = 12 or 13 for servo1 12 and for servo 2 13

Connect first side of the photoresistor1 to pin3, photoresistor2 to pin2, photoresistor3 to pin4. 

Connect second side of the photoresistor1 to pin A1, photoresistor2 to pin A2, photoresistor3 to pin A0.

Connect all of the second sides to 2.2k resistors and the resistors to gnd.


To support the robot, we need to put something under it so it can move without any problems! 
 
You can use anything that can support the robot, like a wheel, but in this case, i have used two bottle caps.
 
Use a duct tape to connect the bottle caps.

Now place them under the robot using double sided tape.

Use this code to start your own light following robot :

#include ;
Servo servo1;
Servo servo2;
int sensor1=3;
int input1=1;
int sensor2=2;
int input2=2;
int sensor3=4;
int input3=0;
int s1ldrvalue=0;
int s2ldrvalue=0;
int s3ldrvalue=0;
void setup ()
{
   pinMode(sensor1,OUTPUT);
     digitalWrite(sensor1,HIGH);
     pinMode(sensor2,OUTPUT);
     digitalWrite(sensor2,HIGH);
     pinMode(sensor3,OUTPUT);
     digitalWrite(sensor3,HIGH);
    servo1.attach(12);
   servo2.attach(13);
}
 
  void loop()
  {
    s1ldrvalue = analogRead(input1);
   s2ldrvalue = analogRead(input2);
   s3ldrvalue = analogRead(input3);
     servo1.write(90);
   servo2.write(90);
  {
   if(s1ldrvalue < 500)                                  
  {
    servo1.write(0);
    servo2.write(180);
    delay(500);
  }
  else
  {
  if(s2ldrvalue < 500)                                  
  {
    servo1.write(0);
    servo2.write(0);
    delay(500);
}
  else                                 
  {
   if (s3ldrvalue < 500)                                
  {
    servo1.write(180);
    servo2.write(180);
   delay(500);
}
    else;                                 
    }}}}




Video of Working Robot