I need the servo to turn downward then wait 500ms then turn back up then go into sleep mode then wake up using the watchdog please help I'm a novice in Arduino and it would be a godsend if someone could make this function I commented out everything that didn't work right now the servo does everything I want it too and it uses a delay to wait a day but it uses way too much power.
It’s an arduino mega 2560 R3
#include <Servo.h>
int servoPin=9;
int servoPos1=0;
int servoPos2=160;
Servo myServo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myServo.attach(servoPin);
//setup watchdog timer
//WDTCSR = (24);//change enable and WDE - also resets
//WDTCSR = (33);//prescalers only - get rid of the WDE and WDCE bit
//WDTCSR |= (1<<6);//enable iterrupt mode
for(int i=0; i<10800; i++){//gives 24 hours
//BOD DISABLE
//MCUCR |= (3 << 5);//set both BODS and BODSE at the same time
//MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6);//then set the BODS bit and clear the BODSE bit at the same time
//asmvolatile("sleep");
It’s an arduino mega 2560 R3 and the servo only runs for about 5 seconds then it’s idle for the rest of the day any more questions just ask thank you for responding to my thread and I’ll look into code tags
Would I have to physically press the power switch though because it needs to work for months on end without contact and so you don’t think it’s possible just using sleep mode interrupted by watchdog timer
Do you think it could work with ought any extra parts if I outsourced it to someone who knows more than me since I need it to fit in a compact area and right now all it is is the Arduino and a micro servo and it would mess up my design if I added a bread board a lot of wires and an rtc
A common trick - if accuracy isn’t precise, would be to use a timer interrupt to wake for a moment, and count the timer events until they reach the desired total time. Your CPU would only be running fo a few milliseconds per day to save power.
If you could describe what your servo is connected to, we may be able to suggest an alternative mechanism that would do the same job but not consume power continuously like your servo would.