017 - MicroPython TechNotes: LASER Module
Introduction
In this article, we will learn on how to use a LASER module with ESP32 using MicroPython programming language.
Pinout
- G – for the ground pin.
- V – for the supply voltage.
- S – for the control signal pin.
Bill Of Materials
- ESP32 development board with MicroPython firmware that will serve as the main microcontroller.
- ESP32 shield from Gorillacell ESP32 development kit to extend the pins of ESP32 and to provide easy circuit connection.
- 3-pin female-female dupont jumper wires.
- And of course the LASER module itself.
Hardware Instruction
- First, attach the ESP32 development board on top of the ESP32 shield and make sure that both USB port are on the same side.
- Next, attach the dupont wires to the LASER module by following the color coding which black for the ground, red for the VCC, and yellow for the control signal pin.
- Next, attach the other side of the dupont jumper wires to the ESP32 shield by matching the colors of the wires to the colors of the pin headers which is black to black, red to red, and yellow to yellow. For this experiment, I choose GPIO 25 because this ESP32 shield provides 5V on GPIO 25.
- Next, power the ESP32 shield with an external power supply with type-C USB connector. Make sure that the power switch is set to ON state.
- Next, connect the ESP32 to the computer through a micro-USB cable. The demo circuit should be ready.
Software Instruction
For this experiment, I prepared 2 example source code. Just copy and paste it in Thonny. Enjoy.
Video Demonstration
Call To Action
For any concern, write your message in the comment section.
You might also like to support my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker.
Thank you and have a good days ahead.
See you,
– George Bantique | tech.to.tinker@gmail.com
Source Code
1. Example # 1, basic and simple control of LASER module:
1# More details can be found in TechToTinker.blogspot.com
2# George Bantique | tech.to.tinker@gmail.com
3
4from machine import Pin
5
6laser = Pin(25, Pin.OUT)
7
8# # The following source should be tested using the REPL:
9# laser.on() # Turns ON the laser.
10# laser.off() # Turns OFF the laser.
How the code works:
from machine import Pin
Loads or imports the necessary library, in this case the Pin class from the machine module. This is in order to access the pins of ESP32.
laser = Pin(25, Pin.OUT)
This line of code creates the object named laser which is connected on GPIO 25 with a pin direction set as an output.
laser.on()
This will set the pin to logic HIGH which will turn ON the laser module.
laser.off()
This will clear the pin to logic LOW which will turn OFF the laser module.
2. Example # 2, SOS using the LASER module:
1
2# More details can be found in TechToTinker.blogspot.com
3# George Bantique | tech.to.tinker@gmail.com
4
5from machine import Pin
6from time import ticks_ms
7
8laser = Pin(25, Pin.OUT)
9switch = Pin(0, Pin.IN, Pin.PULL_UP)
10
11DOTS_INTERVAL = 250
12DASH_INTERVAL = 750
13LOWS_INTERVAL = 500
14BETW_INTERVAL = 700
15
16isSOS = False
17startTime = ticks_ms()
18steps = 0
19
20while True:
21 if isSOS:
22 if steps == 1 or steps == 3 or steps == 5:
23 laser.on()
24 if ticks_ms() - startTime >= DOTS_INTERVAL :
25 steps += 1
26 startTime = ticks_ms()
27 elif steps == 7 or steps == 9 or steps == 11:
28 laser.on()
29 if ticks_ms() - startTime >= DASH_INTERVAL:
30 steps += 1
31 startTime = ticks_ms()
32 elif steps == 0 or steps == 6 or steps == 12:
33 laser.off()
34 if ticks_ms() - startTime >= BETW_INTERVAL:
35 steps += 1
36 startTime = ticks_ms()
37 else:
38 laser.off()
39 if ticks_ms() - startTime >= LOWS_INTERVAL:
40 steps += 1
41 startTime = ticks_ms()
42
43 if steps > 12:
44 steps = 0
45
46 if switch.value() == 0:
47 laser.off()
48 #print('press')
49 isSOS = not isSOS
50 steps = 0
51 sleep_ms(300)
References And Credits
- Purchased your Gorillacell ESP32 development kit at: gorillacell.kr
Posts in this series
- 049 - MicroPython TechNotes: MP3 Player
- 048 - MicroPython TechNotes: Analog Touch Sensor
- 047 - MicroPython TechNotes: E108 GPS
- 046 - MicroPython TechNotes: RF433 Transceivers
- 045 - MicroPython TechNotes: Infrared Transmitter
- 044 - MicroPython TechNotes: Infrared Receiver
- 043 - MicroPython TechNotes: ESP12E WiFi | External WiFi module
- 042 - MicroPython TechNotes: JDY-32 | Bluetooth Low Energy BLE
- 041 - MicroPython TechNotes: Bluetooth HC-06
- 040 - MicroPython TechNotes: Relay
- 039 - MicroPython TechNotes: Electromagnet
- 038 - MicroPython TechNotes: Buzzer
- 037 - MicroPython TechNotes: Servo Motor
- 036 - MicroPython TechNotes: Stepper Motor
- 035 - MicroPython TechNotes: Dual Motor Driver
- 034 - MicroPython TechNotes: DC Motors | Gear Motor and Fan Motor
- 033 - MicroPython TechNotes: TCS34725 RGB Color Sensor
- 032 - MicroPython TechNotes: BMP280 Sensor
- 031 - MicroPython TechNotes: TOF Distance Sensor
- 030 - MicroPython TechNotes: DS3231 RTC
- 029 - MicroPython TechNotes: HC-SR04 Ultrasonic Sensor
- 028 - MicroPython TechNotes: DHT11 Temperature and Humidity Sensor
- 027 - MicroPython TechNotes: Rotary Encoder
- 026 - MicroPython TechNotes: Light Dependent Resistor (LDR)
- 025 - MicroPython TechNotes: Joystick
- 024 - MicroPython TechNotes: Slider Switch
- 023 - MicroPython TechNotes: Continuous Rotation Potentiometer
- 022 - MicroPython TechNotes: Potentiometer | Reading an Analog Input
- 021 - MicroPython TechNotes: Color Touch Sensor
- 020 - MicroPython TechNotes: Touch Sensor
- 019 - MicroPython TechNotes: Switch Module
- 018 - MicroPython TechNotes: Button | Reading an Input
- 016 - MicroPython TechNotes: RGB LED Matrix
- 015 - MicroPython TechNotes: Neopixel 16
- 014 - MicroPython TechNotes: 8x8 Dot Matrix Display (I2C)
- 013 - MicroPython TechNotes: 8x16 Dot Matrix Display (SPI)
- 012 - MicroPython TechNotes: 8x8 Dot Matrix Display (SPI)
- 011 - MicroPython TechNotes: 1.3 OLED Display
- 010 - MicroPython TechNotes: 0.96 OLED Display
- 009 - MicroPython TechNotes: 7 Segment Display
- 008 - MicroPython TechNotes: 16x2 LCD
- 007 - MicroPython TechNotes: RGB LED
- 006 - MicroPython TechNotes: Traffic Light LED Module
- 005 - MicroPython TechNotes: Gorilla Cell LED | MicroPython Hello World
- 004 - MicroPython TechNotes: Gorilla Cell I/O Devices
- 003 - MicroPython TechNotes: Gorillacell ESP32 Shield
- 002 - MicroPython TechNotes: Introduction for Gorillacell ESP32 Dev Kit
- 001 - MicroPython TechNotes: Get Started with MicroPython
- 000 - MicroPython TechNotes: Unboxing Gorillacell ESP32 Development Kit
No comments yet!