77Views2Replies

Author Options:

help programming arduino Answered

this is my code so far what i would like to do is connect a pir sensor,once activated there should be a delay of 2min then the two sevo's should be activated and run for 20 min then reset and only be able to reactivate pir after an hour


#include <Servo.h>

Servo vert;
Servo hor;

void setup() {
  vert.attach(10);
  hor.attach(11);
}

void migrate(Servo &myServo, int newPos) {
  int wait=random(1,20); //randomize the wait to make it more interesting
  int pos = myServo.read(); //Read the current servo position
  if (pos < newPos) {
    for (int i=pos; i < newPos; i++) {
      myServo.write(i);
      delay(wait);
    }
  } else {
    for (int i=pos; i > newPos; i--) {
      myServo.write(i);
      delay(wait);
    }
  }
}

Tags:arduino

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
airworx
airworx

5 years ago

thnx mate will.give it a go

0
dudes
dudes

5 years ago

Something like this may help.

int timeCheck = 0;

int timeServo = 0;

Void Setup()

{//setup stuff// }

void loop() {

if(//pir sensor is activated//) {

timeCheck = millis();

}

while(millis() > timeCheck + 120000//two minutes//) {

timeServo = millis();

while(millis() < timeServo + 1200000) {

//do servo stuff//

}

if(millis() > timeServo + 1200000) {

//stop servo stuff//

//deactivated pir sensor//

timeCheck = 0;

timeServo = 0;

delay(3600000);

}

}

Obviously you have to write the actual code, but hopefully this format will help in some way.