Hi to all, i am a newbie on arduino world, i have written a small piece of code which will move the servo motor every 8sec or 10min or 1hr with increment of 15o angle. at the initial setup loop i have registered the pin no 9 and set the intervalTime variable to 1 (this variable can be increased based on the interval frequency if required additionally more than 8sec) and on loop method i am running a for loop which will power down the arduino for more than 8sec on loop, i am using lowPower.h library for this. now the problem is, when i start the arduino, at the loop runs for first time it sets the servo position to zero angle and on second time the clockPos variable gets increased to 15o but the servo not moves to the 15o angle on the third time the clockPos gets increased to 30 but now the servo moves to 15o angle, i dont know whats happening please help me on this, and have look on my code and please let me know the cause.
int clockPos = 0; //variable for the angle position
int intervalTime = 0; //interval time loop which will equal for minium of 8sec ( 1 = 8sec, 2 = 16sec, and on…)
pinMode(13, OUTPUT); //just switching off the onboard led
intervalTime = 1; //initializing the interval time for 8sec( 1 = 8sec)
//running the loop for the given interval and arduino powerdown till that time
for (int i = 0; i < intervalTime; i += 1)
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
//if the servo reaches specified angle of 180 degree we need to reset the clockPos value to zero, so that servo
//can start from zero position
if (clockPos == 180)
clockPos = 0;
//if the angle not reached to 180 degree, we are attaching the pin 9 to servo and writting the angle for servo to move
//after servo reaches to the angle, need to increment by 15 degree and detaching the servo.
myservo.write(clockPos, 30, true);
clockPos = clockPos + 15;