Automatic door with IR and a servoTinkerPieCircuit tutorial 21 of 24 · Advanced · 25 minutes
Open a door with a servo when the IR sensor sees someone, then close it again.
Open this circuit in TinkerPieCircuit (free, runs in your browser)
What you will learn
- Combining an input (IR sensor) with an output (servo)
- Servo angles
- Waiting with delay()
Parts
Steps
Wire the servo
G →
GND, V →5V, SIG →S1.Wire the IR sensor
VCC →
3V3, GND →GND, OUT →P10.Write the rule
If the sensor reads LOW, turn the servo to 90° (open) and wait 2 seconds. Otherwise turn it to 0° (closed).
Test
Press ▶ Start and click the OBSTACLE switch on the sensor. The door opens, then closes when you click it again.
The code
function setup() {
pinMode(P10, INPUT);
servoWrite(S1, 0);
}
function loop() {
if (digitalRead(P10) == LOW) {
servoWrite(S1, 90);
tone(BUZZER, 660);
delay(100);
noTone(BUZZER);
delay(2000);
} else {
servoWrite(S1, 0);
}
delay(50);
}
Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.
How it works
The sensor tells the program that someone is near. The program then commands the servo. Shop doors and lifts use the same input-decision-output pattern.
← IR sensor people counter · All 24 circuit tutorials · Motion alarm with a PIR sensor →