LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsA 2D lidar spins a laser range finder and measures distance at hundreds of angles per turn. The YDLIDAR X2 covers 360 degrees out to about 8 m, ten times a second, over USB. It is the sensor robot vacuums use to map rooms. YDLIDAR's official SDK has Python bindings; the script grabs each scan and draws it with matplotlib as a polar plot.
Do not touch the spinning head; it is easily knocked off balance.
Tick anything you already have and the total updates.
YDLIDAR X2 360-degree lidar
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB from the computer.
room_scan.pyimport math, ydlidar
import matplotlib.pyplot as plt
PORT = "/dev/ttyUSB0"
laser = ydlidar.CYdLidar()
laser.setlidaropt(ydlidar.LidarPropSerialPort, PORT)
laser.setlidaropt(ydlidar.LidarPropSerialBaudrate, 115200)
laser.setlidaropt(ydlidar.LidarPropLidarType, ydlidar.TYPE_TRIANGLE)
laser.setlidaropt(ydlidar.LidarPropDeviceType, ydlidar.YDLIDAR_TYPE_SERIAL)
laser.setlidaropt(ydlidar.LidarPropScanFrequency, 10.0)
laser.setlidaropt(ydlidar.LidarPropSampleRate, 3)
laser.setlidaropt(ydlidar.LidarPropSingleChannel, True)
laser.setlidaropt(ydlidar.LidarPropMaxRange, 8.0)
if not (laser.initialize() and laser.turnOn()):
raise SystemExit("lidar not found on " + PORT)
scan = ydlidar.LaserScan()
plt.ion(); ax = plt.subplot(111, projection="polar")
try:
while plt.fignum_exists(1):
if laser.doProcessSimple(scan):
ang = [p.angle for p in scan.points if p.range > 0]
rng = [p.range for p in scan.points if p.range > 0]
ax.clear(); ax.set_rmax(8); ax.scatter(ang, rng, s=2)
plt.pause(0.01)
finally:
laser.turnOff(); laser.disconnecting()
Wrong port, or another program has it open; on Linux add your user to the dialout group.
The X2 is single channel at 115200 baud; check those two settings.
Not enough USB current; use the adapter's second power port or a powered hub.
Yes, it is a Class 1 laser, safe in normal use.
Poorly in direct sunlight; it is made for indoor use.
Yes, the SDK builds on Raspberry Pi OS; plotting is slower than on a laptop.
1 part: YDLIDAR X2 2D LiDAR Sensor 360° Scan 8m Range – USB-C Interface. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 5 steps.
No. This page has the complete, tested code (room_scan.py).
About ₹6,299 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How triangulation lidar works; Using the YDLIDAR SDK from Python; Plotting scans in polar coordinates.
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
See the smoke level live on a crisp screen and get a loud warning when it spikes.
An infrared eye that spots an open flame and raises the alarm.
Walk into the room and it sounds the alarm: the classic first security build.
Learning project. Check every circuit and the datasheet of each part before you power it up.