LIGHT SENSITIVE ROBOT
In this tutorial you will learn how to create a robot thats sensitive to light
MATERIALS REQUIRED
1.Arduino uno
2.Tank chasis
3.Adafruit motor shield
4.screws and spacer stud
5.Male to Female jumper wire x 3
6.Light dependent resister module(LDR)
CIRCUIT
1.LDR analog pin-A0
2.LDR Digital pin-Not connected
3.LDR GND -Arduino GND
4.LDR VCC - Arduino 5v
5.Motor terminals -M1,M2 of Motor sheild
CODE
Library download link-https://github.com/adafruit/Adafruit-Motor-Shield-library.git
#include <AFMotor.h>
const int LDR =A0;
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
Serial.begin(9600);
pinMode(LDR,INPUT);
motor1.setSpeed(200);
motor1.run(RELEASE);
motor2.setSpeed(200);
motor2.run(RELEASE);
}
void loop() {
int LDRstate= analogRead(A0);
Serial.println(LDRstate), delay(200);
if(LDRstate>350){
motor1.run(FORWARD);
motor2.run(BACKWARD);
}
else{
motor1.run(FORWARD);
motor2.run(FORWARD);
}
}
Comments
Post a Comment