Simple sweep beginner

hi im really beginner about arduino project. and i wanna ask . how to make code of sweep servo with scheduled time without use timer module . example servo that sweep 90 degree and back to 0 position every 1 hour.

can you help me?

You need to review the following thread which will show you how to make a none blocking Timer.

After you master how to make a Timer, then come up with a schematic showing how the project hardware is connected.

You should be aware servos should not be powered from the Arduino, they need their own power supply, probably 6VDC, this can be four AA batteries or a 5V @ 1 to 2Amp cell phone charger.

The servo power supply must share a common ground connection with the Arduino.


You can add a relay circuit to control the power to the servo.

Use this relay to disconnect the servo battery power when it is not needed to move will help extend the life of the batteries.

@alcaponed, your topic has been moved to a more suitable location on the forum.

// 10 sec on, 1 hour off
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  //delay(1000);                       // wait for a second
   delay(1000 *10);
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  //delay(1000);   
  delay(1000*360);  // wait for a second
}

"DELAY()"

blocks all code in loop()

Best to be avoided.

But at the very beginners level it appears work.

A cheat is

delaymicro(1);
Counter++;

If (Counter >= 60000 ){
Counter=0;
Minutespaused++;
}

If(Minutespaused >=86000)
Minutes paused=0;
.....Now do your code.
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.