Laser Sensor
| ||
Overview
Specification
- Boost chip: PT1301
- Effective distance: 0.01-0.8m(typ), 1.5m(max)
- Power: 2.5V ~ 5.0V
- Dimension: 53.0mm*18.0mm
- Mounting holes size: 2.0mm
Principle: The emitting part of the laser sensor is a 180KHz oscillator emitted by an oscillator tube, amplified by a triode, the laser tube emits light, and the receiving part receives the returned light intensity from a matching 180KHz receiver tube. Since the laser sensor uses modulation processing, the receiving tube can only accept the reflected light of the same frequency, so the influence of visible light on the reflected laser can be effectively prevented.
Applications
- Obstacle detection
- Pipeline counter
- Smart robot
- Obstacle-avoiding car
Pinouts
In the case of working with a MCU:
- VCC ↔ 2.5V ~ 5.0V
- GND ↔ power supply ground
- DOUT ↔ MCU.IO (digital output)
Get Started at Pico
If you are the first time o use the Pico, you need to first learn how to get started at the Pico before you run other examples.
The Pico supports C and the Micropython which requires different firmware.
In most of the examples archives (Demo codes), we provide a Micropython firmware (uf2 file), we recommend you to use the provided firmware to test the board. Because the codes may run abnormally with different firmware.
If the board is tested to be workable, you can also download the newest firmware from Raspberry Pi and do further programming.
- If you want to use C codes, please refer to the C/C++ Guides
- If you want to use Micropython codes, please refer to the Micropython Guides.
- The link of the newest Micropython firmware of Pico
- Official Guides of Raspberry Pi Pico
Hardware Connection
Sensor | Pico | Description |
---|---|---|
VCC | 3.3V | Power input |
GMD | GND | Power ground |
DOUT | GP22 | Digital output |
Download examples
Use Raspberry Pi as the host device. Open a terminal and run the following commands to download the example.
sudo apt-get install p7zip-full cd ~ sudo wget https://files.waveshare.com/upload/f/fd/Laser-Sensor-code.7z 7z x Laser-Sensor-code.7z -o./Laser-Sensor-code cd ~/Laser-Sensor-code cd Pico/c/build/
Examples
C codes
- Go into the c directory:
cd ~/Laser-Sensor-code/Pico/c/build
- Add the path of the SDK:
export PICO_SDK_PATH=../../pico-sdk
- Note that if the path of your SDK is different, you need to modify the command and use the correct path to export.
- Generate Makefile and build:
cmake .. make -j9
- After building, a uf2 file is generated.
- Press and hold the button of Pico, connect it to Raspberry Pi then release the button.
- Copy/Drag the uf2 file to the portable disk (RPI-RP2) recognized.
cp main.uf2 /media/pi/RPI-RP2/
Micropython codes
Working with Windows
- 1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer through the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
- 2. Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the identified removable disk (RPI-RP2).
- 3. Open Thonny IDE (note: use the latest version of Thonny, otherwise there is no Pico support package, the latest version under Windows is v3.3.3).
- 4. Click Tools -> Settings -> Interpreter, and select Pico and the corresponding port as shown in the figure.
- 5. File->Open->Laser Sensor.py, click to run, as shown below:
Working with Raspberry Pi
- Flash the Micropython firmware first.
- Open the Thonny IDE (Menu -> Programming -> Thonny Python IDE).
- 【Optiional】If the Thonny IDE in the Raspberry Pi is not the new version that supports Pico, please upgrade it first.
sudo apt upgrade thonny
- Configure Interpreter, choose Tools -> Options... -> Interpreter, choose MicroPython(Raspberry Pi Pico) and the ttyACM0 port.
- Click File -> Open.. and browser the micro python codes (Laser Sensor.py) to run the codes
Expected result
- Put an object(obstacle) in front/above the Laser sensor, the indicator of the sensor board lights, and it turns off if the object is removed.
Note: Try to avoid touching the resistors and capacitors on the board when the power is on, so as to avoid burning out the infrared emitting tube. As the laser is harmful to the eyes, DO NOT irradiate the eyes directly while using.
The STM32 examples are based on the STM32F103RBT6 and the STM32H743. The connection provided below is based on the STM32F103RB. If you need to use other STM32 boards, you may need to change the hardware connection and port the code yourself.
STM32
Hardware connection
Sensor | STM32 | Description |
---|---|---|
VCC | 3.3V | Power input |
GND | GND | Power ground |
DOUT | PA4 | Digital output |
Examples
The examples are developed based on the HAL libraries. Download the demo codes to your PC. Unzip and find the STM32 project from Laser-Sensor-code\STM32\STM32F103RB\MDK-ARM.
- Open the Laser Sensor.uvprojx file by Keil.
- Build and the project.
- Program the project to your STM32 board.
- Connect the UART1 of your STM32 board to the PC and check the serial data with SSCOM software.
Note: Try to avoid touching the resistors and capacitors on the board when the power is on, so as to avoid burning out the infrared emitting tube. As the laser is harmful to the eyes, DO NOT irradiate the eyes directly while using.
The Arduino example is written for the Arduino UNO. If you want to connect it to other Arduino boards, you may need to change the connection.
Arduino
Hardware connection
Sensor | Arduino | Description |
---|---|---|
VCC | 5V | Power input |
GND | GND | Power ground |
DOUT | D2 | Digital output |
Install the Software
Run the Program
Download the program in the information we provided, unzip it, and then enter the Laser-Sensor-code/Arduino/Laser_Sensor directory.
Double-click to open the Laser_Sensor.ino file.
Select your development board and the corresponding port.
Compile and download, as shown below:
After the download is successful, run SSCOM to connect the Laser module, and you can view the status of the sensor in real-time.
Note
Place the obstacle above the laser sensor, and the signal indicator on the module will be on. When the obstacle is far away from the laser sensor, the signal indicator on the module will be off.
Note: Try to avoid touching the resistors and capacitors on the board when the power is on, to avoid burning out the infrared emitting tube, the laser is harmful to the human eyes, please do not use it to irradiate the human eyes!
Resources
FAQ
{{{5}}}
{{{5}}}
{{{5}}}
{{{5}}}
{{{5}}}
{{{5}}}
The range is 0.8M.
{{{5}}}
Support
Technical Support
If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)