12 / 20
Laser barrier gate
An interrupted beam opens a striped servo barrier.
Run this experiment →Why it’s here
Break the beam, observe the arm, then restore the beam.
How it works
An interrupted beam opens a striped servo barrier. A target position encoded by pulse width, rather than a continuous motor speed. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Break the beam, observe the arm, then restore the beam.
Connections
- GPIO 27 — Beam receiver; LOW when lit
- GPIO 18 — Servo signal; suitable separate supply
Example sketch
#include <ESP32Servo.h>
Servo arm;
// Receiver LOW with beam present, HIGH when blocked. Verify your receiver.
void setup() {
pinMode(27, INPUT_PULLUP);
arm.setPeriodHertz(50); arm.attach(18, 500, 2400);
}
void loop() {
bool blocked = digitalRead(27) == HIGH;
arm.write(blocked ? 90 : 0);
delay(20);
}Check your understanding
What is the servo command?
Show the answer
A target position encoded by pulse width, rather than a continuous motor speed.