Last active
March 19, 2020 11:42
-
-
Save suadanwar/44386873b3661b95483d55b002c338e5 to your computer and use it in GitHub Desktop.
This sample code is for Automatic Soap Dispenser Using Maker UNO tutorial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo myservo1; // create servo object to control a servo1 | |
Servo myservo2; // create servo object to control a servo2 | |
const int sensorPin = 3; // the number of the IR sensor pin | |
int sensorState = 0; // variable for reading the IR sensor status | |
void setup() { | |
// initialize the IR sensor pin as an input: | |
pinMode(sensorPin, INPUT); | |
myservo1.attach(5); | |
myservo2.attach(6); | |
} | |
void loop() { | |
// read the state of the IR sensor value: | |
sensorState = digitalRead(sensorPin); | |
// check if the sensor detects any object. If it is, the sensorState is HIGH: | |
if (sensorState == HIGH) { | |
myservo1.write(180); // sets the servo position to 180 degree | |
myservo2.write(0); // sets the servo position to 0 degree | |
delay(15); | |
} else { | |
myservo1.write(0); // sets the servo position to 0 degree | |
myservo2.write(180); // sets the servo position to 180 degree | |
delay(15); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment