Hello,
This is my first attempt at using an Arduino to control a small DIY widget that I am constructing…
The components in my widget are a motion sensor, and a DC motor driven forward and reverse with two SSR (SP-NC)
Anyhow, here is the pseudo code that I am trying to get my sketch to accomplish:
Constantly read input from motion sensor
Once motion is detected, activate a “timer” for 5 min
After the elapsed 5 min turn the motor on forward for x amount of time(roll function)
Turn the motor off
Pause
Turn the motor on reverse for same x amount of time(unroll function)
Turn motor off
Return to reading input from motion sensor and start over
This is a very simple task, but since I am a noob to the whole coding aspect of this sparky fun game, I am looking for a litle input on what I have so far. Any and all input will be greatly appreciated!
Here is my code so far:
//Begin serial communications at 9600 bits/sec
//This is motor forward
const int forward = 3;
//This is motor reverse
const int reverse = 4;
//This is motion sensor
const int msense = 6;
void setup() {
Serial.begin(9600);
pinMode(msense, INPUT);
pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
}
void loop() {
int detect = digitalRead(msense);
delay(5);
if (detect == HIGH){
delay(300000);
void roll();
void unroll();
}
}
void roll () {
digitalWrite(forward, HIGH);
delay(60000);
digitalWrite(forward, LOW);
delay (1000);
}
void unroll() {
digitalWrite(reverse, HIGH);
delay(60000);
digitalWrite(reverse, LOW);
delay(1000);
}