Hi, im new here and also new to programming.
I needed some help and see what i was typing in wrong.
I am trying to Cycle the LED on and off every 1 second and have the photo cell respond to the LED turning on and off.
So when the LED is off, the servo motor is a one extreme position. When the LED is on, the servo motor should move to its other extreme position.
Here is the coding i have:
Thanks in advance guys!
#include <Servo.h>
Servo servomotor;
int photoresistor = 0; // set photoresistor to analog pin 0
int motor = 9; // servo is connected to I/O pin 9
int ledPin = 2; // LED is connected to pin 2
int val = 0; // Input value
int setpoint = 0; // Trigger Point
void setup()
{
servomotor.attach(motor);
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH); // LED is on
delay(1000); // wait for 1 second
digitalWrite(ledPin,LOW); // LED is off
delay(1000); // wait for 1 second
val = analogRead(photoresistor); // Read analog input value
if(val>setpoint)
servomotor.write(179); // There is light and servo moves to 179 deg.
else
servomotor.write(0); // There no light and servo moves back to 0 deg.
}