#include <Servo.h> // Add Servo library to control servo motors
#define FlameSensor 8 // variable for the digital pin in the arduino used for sensor
Servo Hand; // Name your servo motor
int pos = 0; // Variable where the hand's position will be stored (in degrees)
// put your setup code here, to run once:
void setup() {
pinMode(FlameSensor, INPUT); //activate the pin used for the sensor in the arduino as Input
Hand.attach(3); // Attache the hand to the pin 3
Hand.write(pos); // Initialize the hand's position to 0 (leftmost)
}
// put your main code here, to run repeatedly:
void loop() {
if (digitalRead(FlameSensor) == LOW) {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees in steps of 1 degree
Hand.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
Hand.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
delay(100);
}