Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This sample code is for Automatic Soap Dispenser Using Maker UNO tutorial.
#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