Laser Sensor Module

The Laser Sensor Module project demonstrates how to interface a laser sensor module with an Arduino Nano. The project reads the analog value from the laser sensor, converts it to voltage, and prints the results to the serial monitor.

How It Works

A laser module such as the KY-008 is a 650 nm red laser diode on a small carrier board with its current-limiting resistor already fitted. It is not a sensor on its own — it is an emitter. Paired with a detector on the far side of a gap it forms a break-beam sensor, the most reliable way to detect that something has passed a point.

The diode is driven like an LED: a logic HIGH on the signal pin turns it on. Because the beam is collimated it stays narrow over several metres, which is exactly what makes it useful. A photoresistor, photodiode or phototransistor on the opposite side sees a sharp drop in light the instant the beam is interrupted.

Output power is typically around 5 mW — a Class 3R device. That is strong enough to damage the retina on direct viewing, so the beam should always be aimed away from eye level and never pointed at anyone.

Components Needed

  • Arduino Nano
  • Laser Sensor Module module
  • Arduino Nano
  • USB cable for programming and power
  • Arduino Nano

Wiring to the Arduino Nano

Connect S to D2, the middle pin to the 5 V rail and the − pin to GND. The KY-008 already carries its series resistor, so no external component is needed. Driving it from a GPIO is acceptable because the module draws roughly 20–30 mA.

For a break-beam arrangement, mount an LDR or phototransistor directly opposite the laser and read it on A0. Shield the detector from room lighting with a short tube of black heatshrink — ambient light, not the laser, is what limits reliability.

The Arduino Nano runs on 5 V logic, which matches the output swing of most hobby modules, so the signal pin connects directly with no level shifting.

Module pinArduino Nano pinFunction
S (signal)D2Drives the laser on and off
Middle5VSupply
− (GND)GNDCommon ground

Build and Upload

Connect the Arduino Nano to your computer via USB.

Open the Arduino IDE and paste the provided code.

Upload the code to the Arduino Nano.

Once the code is uploaded, open the serial module.

Observe the sensor value and voltage readings printed on the serial monitor.

Example Code

Break-beam detector: pulse the laser, read the detector, report interruptions. Upload it with the board set to Arduino Nano and open the Serial Monitor at 9600 baud.

Break-beam detector: pulse the laser, read the detector, report interruptions
const int LASER_PIN   = 2;
const int DETECT_PIN  = A0;
const int THRESHOLD   = 409;   // tune for your optics

bool beamBroken = false;

void setup() {
  Serial.begin(9600);
  pinMode(LASER_PIN, OUTPUT);
  digitalWrite(LASER_PIN, HIGH);   // beam on continuously
  delay(50);                       // let the detector settle
}

void loop() {
  int light = analogRead(DETECT_PIN);
  bool broken = (light < THRESHOLD);

  if (broken != beamBroken) {      // report edges only
    beamBroken = broken;
    Serial.println(broken ? "BEAM BROKEN" : "beam restored");
  }
  delay(10);
}

Applications

A laser sensor module turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Entry counters for doorways and corridors
  • Perimeter and tripwire alarms
  • Object counting on a conveyor or chute
  • Speed traps, by timing an object across two beams a known distance apart
  • Non-contact end stops where a mechanical switch would wear out

Working with the Arduino Nano

The Arduino Nano is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Nano shares the Uno’s ATmega328P but adds A6 and A7, which are analog-input only and cannot be used as digital pins.

Its DIP footprint drops straight into a breadboard, which suits permanent sensor builds.

Older clones use the CH340 USB bridge and may need that driver plus the "ATmega328P (Old Bootloader)" processor option.

Arduino Nano characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A7 (eight channels, two more than the Uno)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • The detector never crosses the threshold — room lighting is swamping the laser. Shield the detector and re-measure both lit and blocked values.
  • Detection is intermittent at range — the beam is drifting off the detector. Mount both ends rigidly; a few millimetres of flex is enough to miss.
  • The laser is dim or flickering — the GPIO cannot supply enough current. Drive it through a transistor instead.
  • Readings invert — an LDR divider can be wired either way round; swap the fixed resistor and sensor positions.
  • Code written for an ESP board gives odd analog values — the Arduino Nano uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Nano I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Nano

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Nano specifically:

The Nano’s DIP footprint makes it the natural choice once a breadboard prototype becomes a soldered build. Mount it on female headers rather than soldering it down, so the board can be recovered if the project is retired.

With A6 and A7 available in addition to A0–A5, the Nano can read two more analog sensors than an Uno. Remember that those two pins are analog-input only — they cannot be used with digitalWrite or as digital inputs.

For battery-powered builds, the Nano’s regulator and USB bridge dominate idle current. Powering the 5V pin directly from a regulated supply and removing the power LED substantially extends runtime.

Notes and Practical Limits

Never look into the beam or aim it at reflective surfaces at eye height. Treat the module as you would any laser pointer, and switch it off in software when the project is idle rather than leaving it permanently lit.

Pulsing the laser and sampling in step with the pulses rejects ambient light far better than a continuous beam. Drive the laser from a timer, read the detector both lit and unlit, and use the difference — this is how commercial break-beam sensors ignore sunlight.