Hello
Currently I am having a problem with my project, and need help. I am making a servo turn on a light switch with a photoresistor. The photo resistor reads fine but when adding the servo elements to it, the servo will not move. The servo I am using is a towerpro micro servo. It works when i use a button press sketch, but will not work with the photo resistor(granted the photoresistor sketch is a different one from the button press).
This will turn on the front porch light automatically when i forget to turn it on, it will stay on until sunrise. I figure i wouldnt need any timers with this but I am thinking i might need them.
#include <Servo.h>
// servo set up
Servo servo1;
//light sensor set up
const int photoSen = 0; //photoresistor pin
const int sunny = 70; // light val for sunny, can be changed
int lightLevel; //light level
void setup() {
// put your setup code here, to run once:
pinMode(photoSen, INPUT);
lightLevel = analogRead(photoSen);
servo1.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
int position;
if(lightLevel >= sunny){ //stays off if sunny
servo1.write(180);
}
else(lightLevel <= sunny);{//turn on
servo1.write(120);
}
}
Thanks for looking.