Skip to main content
ESPBoards

ESP32 KY-008 Laser Transmitter Module

The KY-008 is a laser transmitter module that emits a red laser beam at 650 nm with an output power of 5 mW. It is suitable for applications requiring a visible laser source and is compatible with various microcontrollers.

⬇️ Jump to Code Examples

Arduino Core Image
ESP-IDF Image
ESPHome Image
PlatformIO Image
MicroPython Image

🔗 Quick Links

KY-008 Laser Transmitter Module Datasheet ButtonKY-008 Laser Transmitter Module Specs ButtonKY-008 Laser Transmitter Module Specs ButtonKY-008 Laser Transmitter Module Specs Button

🛒 KY-008 Price

KY-008 Laser Transmitter Module
Normally, the KY-008 Laser Transmitter Module costs around 1$ per Psc.
The prices are subject to change. Check current price:

Amazon com

Amazon de logo

Aliexpress logo

ℹ️ About KY-008 Laser Transmitter Module

The KY-008 Laser Transmitter Module emits a red laser beam with a wavelength of 650 nm and an output power of 5 mW. It operates at a voltage of 5V and consumes less than 40 mA of current. The module features a 650 nm red laser diode, a resistor, and three male header pins. It is commonly used in laser pointer applications and is compatible with microcontrollers like Arduino, Raspberry Pi, and ESP32.

⚙️ KY-008 Sensor Technical Specifications

Below you can see the KY-008 Laser Transmitter Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.

  • Protocol: Digital
  • Operating Voltage: 5V
  • Output Power: 5 mW
  • Wavelength: 650 nm
  • Operating Current: < 40 mA
  • Working Temperature: -10°C to 40°C
  • Dimensions: 18.5 mm x 15 mm

🔌 KY-008 Sensor Pinout

Below you can see the pinout for the KY-008 Laser Transmitter Module. The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32!

  • Pin (S): Signal pin, connects to the microcontroller's digital output pin.
  • Pin (middle): Not connected.
  • Pin (-): Ground pin, connects to the ground of the circuit.

🧵 KY-008 Wiring with ESP32

Below you can see the wiring for the KY-008 Laser Transmitter Module with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.

  • KY-008 Pin (S): Connect to an ESP32 GPIO pin (e.g., GPIO5).
  • KY-008 Pin (middle): Not connected.
  • KY-008 Pin (-): Connect to ESP32 GND.

🛠️ KY-008 Laser Transmitter Module Troubleshooting

This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.

❌ Laser Not Emitting

Issue: The laser module does not emit a beam when expected.

Solutions:

  • Ensure that the signal pin is connected to the correct GPIO pin on the microcontroller and is configured as an output.
  • Verify that the microcontroller is supplying a HIGH signal to the laser module to activate it.
  • Check all wiring connections for continuity and correctness.
  • Confirm that the supply voltage is 5V as required by the module.

⚡ Weak or Flickering Laser Beam

Issue: The laser beam is dim or flickers during operation.

Solutions:

  • Ensure a stable 5V power supply to the module.
  • Check for loose connections or intermittent contacts in the wiring.
  • Verify that the current supplied to the module does not exceed 40 mA to prevent overheating.

💻 Code Examples

Below you can find code examples of KY-008 Laser Transmitter Module with ESP32 in several frameworks:

If you encounter issues while using the KY-008 Laser Transmitter Module, check the Common Issues Troubleshooting Guide.

Arduino Core Image

ESP32 KY-008 Arduino IDE Code Example

Example in Arduino IDE

Fill in your main Arduino IDE sketch file with the following code to use the KY-008 Laser Transmitter Module:

int laserPin = 13;

void setup() {
pinMode(laserPin, OUTPUT);
}

void loop() {
digitalWrite(laserPin, HIGH); // Turn on the laser
delay(1000); // Wait for one second
digitalWrite(laserPin, LOW); // Turn off the laser
delay(1000); // Wait for one second
}

This Arduino code controls the KY-008 laser module connected to digital pin 13. It turns the laser on for one second and then off for one second, creating a blinking effect.

Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP-IDF Image

ESP32 KY-008 ESP-IDF Code Example
Example in Espressif IoT Framework (ESP-IDF)

If you're using ESP-IDF to work with the KY-008 Laser Transmitter Module, here's how you can set it up and read data from the sensor. Fill in this code in the main ESP-IDF file:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define LASER_PIN GPIO_NUM_5

void app_main(void) {
gpio_pad_select_gpio(LASER_PIN);
gpio_set_direction(LASER_PIN, GPIO_MODE_OUTPUT);

while (1) {
gpio_set_level(LASER_PIN, 1); // Turn on the laser
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait for one second
gpio_set_level(LASER_PIN, 0); // Turn off the laser
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait for one second
}
}

This ESP-IDF code configures GPIO5 as an output to control the KY-008 laser module. It turns the laser on for one second and off for one second in a loop, creating a blinking effect.

Update the I2C pins (I2C_MASTER_SDA_IO and I2C_MASTER_SCL_IO) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESPHome Image

ESP32 KY-008 ESPHome Code Example

Example in ESPHome (Home Assistant)

Fill in this configuration in your ESPHome YAML configuration file (example.yml) to integrate the KY-008 Laser Transmitter Module

switch:
- platform: gpio
pin: GPIO5
name: "KY-008 Laser"
id: laser_switch

This ESPHome configuration sets up a switch to control the KY-008 laser module connected to GPIO5. The laser can be turned on and off via the defined switch entity.

Upload this code to your ESP32 using the ESPHome dashboard or the esphome run command.

PlatformIO Image

ESP32 KY-008 PlatformIO Code Example

Example in PlatformIO Framework

For PlatformIO, make sure to configure the platformio.ini file with the appropriate environment and libraries, and then proceed with the code.

Configure platformio.ini

First, your platformio.ini should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino

ESP32 KY-008 PlatformIO Example Code

Write this code in your PlatformIO project under the src/main.cpp file to use the KY-008 Laser Transmitter Module:

#include <Arduino.h>

#define LASER_PIN 5

void setup() {
pinMode(LASER_PIN, OUTPUT);
}

void loop() {
digitalWrite(LASER_PIN, HIGH); // Turn on the laser
delay(1000); // Wait for one second
digitalWrite(LASER_PIN, LOW); // Turn off the laser
delay(1000); // Wait for one second
}

This PlatformIO code initializes GPIO5 as an output to control the KY-008 laser module. It toggles the laser on and off every second, creating a blinking effect.

Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload command.

MicroPython Image

ESP32 KY-008 MicroPython Code Example

Example in Micro Python Framework

Fill in this script in your MicroPython main.py file (main.py) to integrate the KY-008 Laser Transmitter Module with your ESP32.

import machine
import time

LASER_PIN = machine.Pin(5, machine.Pin.OUT)

while True:
LASER_PIN.value(1) # Turn on the laser
time.sleep(1) # Wait for one second
LASER_PIN.value(0) # Turn off the laser
time.sleep(1) # Wait for one second

This MicroPython script sets up the KY-008 laser module on GPIO5 and toggles it on and off every second, producing a blinking effect.

Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy.

Conclusion

We went through technical specifications of KY-008 Laser Transmitter Module, its pinout, connection with ESP32 and KY-008 Laser Transmitter Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.