Community project

Laser-Guided DC Motor Control

Photo of Laser-Guided DC Motor Control
Generated with AI

raul tierrablanca

Published November 30, 2026

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

Wiring diagram for Laser-Guided DC Motor Control
Loading diagram…

Gather all the parts

QtyComponent
1

Motor DC de escobillas de 12 V, dos cables

Motor reversible pequeño; corriente de bloqueo máxima 1 A para este montaje.

1

KY-008 Laser Module

KY-008 650nm red laser transmitter module. Common modules are specified for 5V operation at less than about 40mA, with some variants documented for 3V-5V. The interface is simple digital ON/OFF control and needs no firmware library. Verify the exact board pinout: many KY-008 boards expose S, VCC, and GND, while some older documentation marks the middle pin as not connected. Avoid sourcing the laser current directly from a GPIO unless the module has a separate logic input.

1

Light Sensor Module V3 (LM393 photoresistor)

Light sensor module with a photoresistor and an LM393 comparator on a small blue board. It outputs an analog light-level voltage on AO and a digital signal on DO that switches low when the light is brighter than the threshold set with the onboard trimmer. It runs from 3.3 to 5 V and connects through a 4-pin 2.54 mm right-angle header (VCC, GND, DO, AO).

1

12V Barrel-Jack Adapter

12 V / 2 A wall adapter with a 5.5 mm / 2.1 mm barrel jack. Used to power motor drivers, LED strips, or boards that need a higher rail.

1

DFRobot DRI0002 L298N (un canal utilizado)

Puente H DRI0002 con VD de 6.5 a 12 V, VS de 4.8 a 46 V; E1 activa y M1 LOW adelante, HIGH atrás. Canal 2 desactivado.

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"

FunctionsupplyArduino
power+12V → DFRobot DRI0002 L298N (un canal utilizado) VSEXT
power+12V → DFRobot DRI0002 L298N (un canal utilizado) VDEXT
groundGNDGND

2. Connections between "driver" and "Arduino"

FunctiondriverArduino
groundGNDGND
pwmE1GPIO 5
digitalM1GPIO 4
groundE2GND
groundM2GND
powerM1+ → Motor DC de escobillas de 12 V, dos cables AEXT
powerM1- → Motor DC de escobillas de 12 V, dos cables BEXT

3. Connections between "laser" and "Arduino"

FunctionlaserArduino
powerS5V
powerVCC5V
groundGNDGND

4. Connections between "sensor" and "Arduino"

FunctionsensorArduino
powerVCC5V
groundGNDGND
digitalDOGPIO 2

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.

Open in Schematik