HI guys I need some advice on the coding
I m trying to link 2 LDR to 2 servo motors but there s something wrong with the coding for it to work :
I have attached the breadboard connection
#include <Servo.h>
Servo myservo;
int ldr = A0; //input pin for sensor
int val; //variable for sensor value's
int thresh = 600; //threshold LDR
int pos = 0; //rest position
int ldr = A1; //input pin for sensor
int val; //variable for sensor value's
int thresh = 600; //threshold LDR
int pos = 0; //rest position
void setup()
{
myservo.attach(13); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
pinMode(ldr, INPUT);
myservo.write(pos); //write rest position
myservo.attach(12); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
pinMode(ldr, INPUT);
myservo.write(pos); //write rest position
}
void loop()
{
val = analogRead(ldr);
Serial.println(val);
if (val < thresh) { //compare threshold to sensor value
myservo.write(180); //move servo to position given by the amount of light
delay(300);
}
else if (val > thresh) { //compare threshold to sensor value
myservo.write(0); //move servo to position given by the amount of light
delay(300);
}
}
