keyestudio
Share your creative ideas with us here
By ran | 24 June 2024 | 0 Comments

HOW to Use Laser Sensor with ESP32

Description

Lasers are widely used to cut, weld, surface treat, and more on specific materials. The energy of the laser is very high. The toy laser pointer may cause glare to the human eye, and it may cause retinal damage for a long time. my country also prohibits the use of laser to illuminate the aircraft.

Working Principle

The laser head sensor module is mainly composed of a laser head with a light-emitting die, a condenser lens, and a copper adjustable sleeve.

We can see the circuit schematic diagram of this module which is very similar to the LED we have learned. They are all driven by triodes. A high-level digital signal is directly input at the signal end, then the sensor will start to work; if inputting low levels, the sensor won’t work.

Note: don’t point an laser emitter at eyes of people.

Components

img

img

img

img

img

ESP32 Board*1

ESP32 Expansion Board*1

Keyestudio DIY Laser Module*1

3P Dupont Wire*1

Micro USB Cable*1

Connection Diagram

Test Code

from machine import Pin
import time

laser = Pin(0, Pin.OUT)# Build a laser object, connect the laser to pin 0, and set pin 0 to output mode
while True:
    laser.value(1) # Turn on the laser
    time.sleep(2) # dalay 2s
    laser.value(0) # Turn off the laser
    time.sleep(2) # delay 2s

Test Result

Connect the wires according to the experimental wiring diagram and power on. Click “Run current script”, the code starts executing, we will see that the laser tube on the module emits a red laser signal for 2 seconds, and stops emitting a red laser signal for 2 seconds. Press “Ctrl+C”or click “Stop/Restart backend”to exit the program.

Leave a Reply

Your email address will not be published.Required fields are marked. *
Name
E-mail
Content
Verification code