Monday, 12 June 2017

Light seeker robot



Hello dear friends 😊, we are Daniel, Jorge and Esther. We are students of 3ºESO in Dominicos school. We are going to teach you how to build an amazing robot 🤖!! It will detect and follow any light source (such as for example your phone torches) on a traveling path, so cool isn't it?😱

This was supposed to be a video showing how the robot follows a light but we had some problems and it doesen't.



 you have to get all of these things:

- One arduino nano


- One breadboard    













- Two LDRs → It´s a kind of resistor whose value depends on the
light.






- Two resistors
- Some wires (male-female and male-male)
- two DC-motors → It is a rotatory elextrical machine that converts DC electrical energy to a mechanical energy.
Resultado de imagen de dc motors
- two 4.5v batteries or a 9v battery
- One L298n → It is a motor driver, it takes a low-current control signal and then turns it inti a higher-current signal that can drive a motor.















- A plastic platform


Resultado de imagen de plastic platform arduino robot
- Adhesive tape
- A pair of scissors
- Some clips
- A pair of tweezers
- A screwdriver
- Some nuts and some screws
- Two big wheels and an other one smaller

OK, when you get all of these things you have to build the circuit. It is a little difficult, so we give you a scheme here:




Imágenes integradas 1



If you want your robot move correctly you will have to use this code:

//First DC
int enA = 6;
int in1 = 8;
int in2 = 9;
//Second DC
int enB = 10;
int in3 = 2;
int in4 = 3;
int Ldr_Left = 1; //Left Ldr
int Ldr_Right = 0; //Right Ldr
int Ldr_R_sensorValue;
int Ldr_L_sensorValue;
//A variable of 255 values to afford all values of the enA/B
int val;
//A variable from 100-255 to read all regular values on the Ldr
int Ldr_val;
int difference;

void setup(){
  digitalWrite(enA,OUTPUT);
  digitalWrite(in1,OUTPUT);
  digitalWrite(in2,OUTPUT);
  digitalWrite(enB,OUTPUT);
  digitalWrite(in3,OUTPUT);
  digitalWrite(in4,OUTPUT);
  digitalWrite(Ldr_Left,INPUT);
  digitalWrite(Ldr_Right,INPUT);
  Serial.begin(9600); //The Serial.begin Sets the data rate in bits per second (9600 in this case)
}

void loop (){
  Ldr_R_sensorValue = analogRead(Ldr_Right);
  Ldr_L_sensorValue = analogRead(Ldr_Left);
  difference = abs(Ldr_R_sensorValue - Ldr_L_sensorValue);
  Serial.println(Ldr_Right);
  Serial.println(Ldr_Left); //Serial.println print as an ASCII-encoded decimal
  if( difference < 25) //Here we say that if the difference is higher than 25 go ahead
  {
    goAhead();
    
  }
  if(difference > 25 && Ldr_R_sensorValue < Ldr_L_sensorValue){  //Here we say that if the difference is lower than 25 and Ldr_R_sensorValue is lower than Ldr_L_sensorValue turn right
    turnRight();
   
  }
  if(difference < 25 && Ldr_L_sensorValue < Ldr_R_sensorValue){  //Here we say that if the difference is higher than 25 and Ldr_R_sensorValue is lower than Ldr_L_sensorValue turn left
    turnLeft();
    
  } 
}

void goAhead(){ //in this code´s part the robot moves froward
  digitalWrite(in1,HIGH);
  digitalWrite(in2,HIGH);
  analogWrite(enA,255);
 
  digitalWrite(in3,LOW);
  digitalWrite(in4,HIGH);
  analogWrite(enB,255);
  delay(200);
}

void turnRight(){ //in this code´s part the robot turns right
  digitalWrite(in1,HIGH);
  digitalWrite(in2,LOW);
  analogWrite(enA,255);
 
  digitalWrite(in3,LOW);
  digitalWrite(in4,LOW);
  analogWrite(enA,255);
  delay(200);
}

void turnLeft(){ //in this code´s part the robot turns left
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
  analogWrite(enA,255);
 
  digitalWrite(in3,HIGH);
  digitalWrite(in4,LOW);
  analogWrite(enA,255);
delay(200);
}




You have some pictures of the process here:






If you enjoyed this project here you have some links of different robots we think you would like to do:

https://create.arduino.cc/projecthub/projects/tags/robot

http://www.andorobots.com/blog/5-robots-arduino-0

https://randomnerdtutorials.com/19-awesome-robots-you-can-build-with-an-arduino/




We hope you have enjoyed this post, we have worked a lot in the project and... we would like you to tell us if you do this robot some day 😊.








No comments:

Post a Comment