Hi all,
I've been trying to experiment with motion sensors and Servo motors. Now I'm trying to combine the two.
What I basically want to do is when motion is detected, to bring the Servo motor to 90°.
But I'm not sure how to do it. Do I make two different functions, and call them together in the loop function?
I've been looking, and I'm not sure what to do.
I don't need code, just a link to a tutorial to call functions, or whatnot.
Thanks.
system
2
Do I make two different functions, and call them together in the loop function?
Functions to do what?
const byte pirPin = 3;
void loop()
{
byte pirState = digitalRead(pirPin);
if(pirState == HIGH) // Or LOW, if low means motion detected
{
myServo.write(90);
}
}
Sorry, call functions to set angle of the Servo motor.
Sorry, I have a disability where I lose my elegance between my brain and my keyboard/paper.
Robin2
4
I would create a function to detect the motion and when it is detected set a variable (perhaps motionDetected = true);
Then I would have another function to move the servo depending on the value of that variable.
The code in loop() would be
void loop() {
checkForMotion();
moveServo();
}
See Planning and Implementing a Program
...R