New Arduino hobbyist here with no prior programming experience. After reading up on the use of the Narcoleptic library and implementing it, I haven't gotten energy savings (based on rough estimates). I expected dramatic results but haven't gotten any to speak of. To briefly describe my project, I am creating a solar powered Arduino Uno controlled chicken coop door that opens in the morning and closes at night. The problem I'm having is that the Arduino eats about 25-30% of my 6000 Mah Lipo battery over night, and my solar panel can't recharge that much in one day of direct sunlight so I turned to Narcoleptic to sleep the board for 8000 ms at a time. I expected this to save a ton of power, but the next morning the board had eaten 25+% again. Can someone look at my code (keeping in mind that I'm at that beginner stage where I'm grabbing code snippets from the web and plugging them in).
#include <Servo.h>
#include <Narcoleptic.h>
Servo servo1;
int photocellPin = 0; // select the input pin for the sensor resistor
int servoPin = 9;
int pos = 0;
void setup()
{
// Serial.begin(9600); // open the serial port to send data back to the computer, OFF
servo1.attach(9);
}
void loop()
{
// Serial.print("Light = "); // for testing purposes only
// Serial.println(analogRead(photocellPin)); // for testing purposes only
pos = analogRead(photocellPin);
pos = constrain (pos, 515, 875);
int servoPos = map(pos, 515, 875, 255, 0);
int servoDegree = map(servoPos, 255, 0, 0, 179);
// Serial.print("Servo Degree = "); // for testing purposes only
// Serial.println(servoDegree); // for testing purposes only
if (pos <600) {
servo1.write(servoDegree); // rotate servo at dark
delay(17000); // duration of rotation
}
if (pos >750) {
servo1.write(servoDegree); // rotate servo depending on light level
delay(17000); // duration of rotation
}
else {
servo1.write(90); // stop and hold servo
// Serial.print("Taking a nap ");
Narcoleptic.delay(8000); // 8 seconds sleepy delay
}
// Serial.print("Servo Degree = "); // for testing purposes only
// Serial.println(servoDegree); // for testing purposes only
}
I have another problem to solve in the code above which I'll be working on while waiting for feedback.