This project builds a laser-triggered motor controller that responds to beam interruption. When an object blocks the KY-008 laser beam detected by the LM393 light sensor, the Arduino triggers the L298N motor driver to spin a 12V brushed DC motor in a programmed sequence: 3 seconds forward, 5 seconds pause, then reverse.
The guide provides a complete wiring diagram showing how to connect the laser module, light sensor, motor driver, and power supply to the Arduino Uno, a full parts list with specifications, the complete Arduino firmware with debouncing logic, and step-by-step assembly instructions including proper H-bridge configuration and safe testing procedures without load.
Wiring diagram

Gather all the parts
Assemble it in 4 steps
1. Preparar el puente H correcto
Usa DFRobot DRI0002 con pines E1 y M1; este cableado no corresponde al módulo rojo con IN1 e IN2. Desconecta USB y fuente. Retira el puente VD=VS y conecta el positivo de 12 V tanto a VD como a VS.
- No conectar 12 V al pin 5V del Nano. Usar fuente cerrada y aislada; no manipular tensión de red.
2. Conectar el motor
Conecta los dos cables del motor a M1+ y M1-. E1 va a D5 para activar el motor y M1 a D4 para elegir el sentido. E2 y M2 van a GND para dejar el otro canal apagado. Une GND del puente y de la fuente con GND del Nano.
- Usa un motor de 12 V cuya corriente de bloqueo no supere 1 A. El L298N pierde tensión y se calienta; no alimentes el motor por una protoboard.
3. Montar la barrera láser
Conecta S y VCC del KY-008 a 5V, nunca a una salida digital; GND a GND. En modelos con pin central sin conexión déjalo libre. Conecta VCC del receptor a 5V, GND a GND y DO a D2 para detectar el corte del haz. AO queda libre. Coloca el láser frente a la fotoresistencia y protege el receptor de la luz ambiental con un tubo opaco.
- Nunca apuntes el láser a ojos ni a superficies reflectantes. Termina el haz en el receptor y un fondo opaco.
4. Ajustar y probar sin carga
Alimenta el Nano por USB. Con el motor sin carga mecánica, ajusta el tornillo del receptor hasta que DO sea LOW con el haz recibido y HIGH al taparlo. Conecta la fuente de 12 V y corta el haz. Debe girar 3 segundos, parar 5 y regresar 3. Si el primer giro es a la izquierda, desconecta ambas alimentaciones e intercambia los dos cables del motor.
- La parada es por desconexión eléctrica; el motor puede seguir por inercia. Tres segundos de vuelta no garantizan regresar exactamente a la posición inicial. No usar como protección de personas ni con mecanismos que puedan atrapar; no hay finales de carrera.
Review all connections
1. Connections between "supply" and "Arduino"
2. Connections between "driver" and "Arduino"
3. Connections between "laser" and "Arduino"
4. Connections between "sensor" and "Arduino"
Deploy the firmware
#include <Arduino.h>
constexpr uint8_t ENABLE = 5, DIR = 4, SENSOR = 2;
enum State { WAIT_CLEAR, READY, RIGHT, PAUSE, LEFT };
State state = WAIT_CLEAR;
unsigned long started = 0, changed = 0;
bool rawBlocked = true, blocked = true;
void stopMotor() { digitalWrite(ENABLE, LOW); }
void runMotor(bool reverse) {
stopMotor();
digitalWrite(DIR, reverse ? HIGH : LOW);
digitalWrite(ENABLE, HIGH);
}
void setup() {
digitalWrite(ENABLE, LOW);
pinMode(ENABLE, OUTPUT);
digitalWrite(DIR, LOW);
pinMode(DIR, OUTPUT);
pinMode(SENSOR, INPUT);
rawBlocked = blocked = digitalRead(SENSOR) == HIGH;
changed = millis();
Serial.begin(9600);
Serial.println(F("Alinea laser: esperando haz libre."));
}
void loop() {
const unsigned long now = millis();
const bool reading = digitalRead(SENSOR) == HIGH;
if (reading != rawBlocked) { rawBlocked = reading; changed = now; }
if (now - changed >= 50) blocked = rawBlocked;
switch (state) {
case WAIT_CLEAR:
if (!blocked && now - changed >= 300) {
state = READY; Serial.println(F("Listo."));
}
break;
case READY:
if (blocked) {
runMotor(false); started = now; state = RIGHT;
Serial.println(F("Derecha: 3 s"));
}
break;
case RIGHT:
if (now - started >= 3000) {
stopMotor(); started = now; state = PAUSE;
Serial.println(F("Parado: 5 s"));
}
break;
case PAUSE:
if (now - started >= 5000) {
runMotor(true); started = now; state = LEFT;
Serial.println(F("Izquierda: 3 s"));
}
break;
case LEFT:
if (now - started >= 3000) {
stopMotor(); state = WAIT_CLEAR; changed = now;
Serial.println(F("Fin. Retira el objeto."));
}
break;
}
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




