Hello all,
I am near the end of my proto stage with a device that opens and closes my blinds based on whether it is light or dark outside and the only thing left I have to do is figure out a mount for the servo that will be doing the work and figure out the external power supply.
The bit I am working on now is the power supply. I know it isn't good to run a servo off the 5V pin on the Arduino so I want to hook it to a second power supply and just keep the signal wire going to the Arduino. When I have the servo powered by the Arduino (without any load, which I heard was ok to do) it works perfectly and my code is executed the way it is supposed to be. When I replace the + and - wires coming from the Arduino 5V with the + and - wired coming from a 4x AA battery pack (6V) the servo just rotates seemingly randomly! It is very frustrating. It is like it completely ignores the code. The servo does stop sometimes when I cover the LDR but doesnt perform any of the functions it does when connected to the Arduino 5V
I am using THIS servo
I was under the impression that the servo was only told when to go and stop by the signal wire and changing the power source wouldn't affect it. Ill paste in my code and attach my schematic below. Any pointers would be greatly appreciated! Thanks in advance
- Sky
Code:
#include <Servo.h>
Servo myservo; //name servo
int photocellPin = 0; //define photo cell reading input
int photocellReading; //define photo cell reading variable
int shadeOpen = 0;
int shadeClosed = 0;
void setup()
{
Serial.begin(9600); //initiate serial @ 9600 baud
myservo.attach(11); //define pin 11 as servo signal pin
}
void loop()
{
Serial.print("Brightness = "); //print "Brightness = "
Serial.println(photocellReading); //print the photocell reading
photocellReading = analogRead(photocellPin); //define photocellReading as pin 0 input from LDR
photocellReading = map(photocellReading, 0, 1023, 0, 179); //map the LDR input to a value between 1-180 so the servo can understand it
{
if (photocellReading <= 70 && shadeClosed == 0) //if the LDR is showing darkness and the shade isn't closed already
{
myservo.write(110); //then tell the servo to rotate forwards at a steady rate (close shade)
delay(2500); //2.5 second delay while shade is closing
myservo.write(90); //stop rotation after dalay
shadeClosed = 1; //set shadeClosed var as true
shadeOpen = 0; //set shadeOpen var as false
}
else if (photocellReading >= 110 && shadeOpen == 0) //if the LDR is showing light and the shade isn't open already
{
myservo.write(70); //then tell the servo to rotate backwards at a steady rate (open shade)
delay(2500); //2.5 second delay while shade is opening
myservo.write(90); //stop rotation after dalay
shadeOpen = 1; //set shadeOpen var as true
shadeClosed = 0; //set shadeClosed var as false
}
else if (photocellReading >= 71 && photocellReading <= 109) //if the LDR senses neither new light or new dark (mid-day)
{
myservo.write(90); //stop servo
}
delay(15);
}
}
Schematic: