This project will be about driving 2 servos and 1 laser using a esp32 and a power supply to to point to parts or tools, I own around my garage. This project will be connected to another project called GParts which is also located on this github space.
How to connect a 6V laser to esp32 and and be able to control it's brightness
- BC337 Base (middle pin) to ESP32 D4
- BC337 Collector to GND
- BC337 Emitter to Laser GND
- Laser VCC wire to 6V
Parts used in the project
- Laser 650nm 5mW Red Cross
- Two pieces Servo motor RDS3225
- ESP32 Development Board
- Power supply 6V - 6A
- HLK-PM01 5V
- BC337 -25 Transistor
GND +6V
├──────────────────────┐ │
| ╔═══════════╗ | │
| ║ -BC337- ║ | ╔═════════╗ |
| ║ ║ | ║ -Laser- ║ │
| ║ Collector ╟─┘ ║ ║ │
| ┌─────╢ Base ║ ║ VCC ╟──┤
| │ ║ Emitter ╟──────╢ GND ║ │
| │ ╚═══════════╝ ╚═════════╝ │
| │ ╔═══════════╗ ╔══════════╗ │
│ │ ║ -ESP32- ║ ║-HLK-PM01-║ │
| │ ║ ║ ║ ║ │
│ │ GND ║ 3V3 VIN ╟─────╢ +Vo (+5V)║ │
│ │ ╧ ─╢ GND GND ╟─────╢ -Vo ║ │
│ └─────╢ D4 ║ ╚══════════╝ │
| ┌─╢ D13 D12 ╟─┐ ┌───── GND │
| │ ║ ║ | | ╧ │
| │ ╚═══════════╝ | | ╔══════════╗ │
| │ ╔══════════╗ | | ║ -Servo2- ║ │
| │ ║ -Servo1- ║ | | ║ ║ │
| │ ║ ║ | └─╢ GND ║ │
| └─╢ Signal ║ └───╢ Signal ║ │
| ║ VCC ╟──┐ ║ VCC ╟──┤
└────────╢ GND ║ | ╚══════════╝ │
╚══════════╝ └─────────────────┘
The image is based on this document which was drawn in fritzing.
In examples let's assume the esp32 has been issued the ip address 192.168.1.231 on your local network.
Method: HTTP GET.
Move accepts four query parameters
- tilt is a Required parameter for how much in degrees the tower should
be tilted (up/down position).
- Valid values: 0 - 264.
- pan is a Required parameter for how much in degrees the tower should
be paned (left/right position).
- Valid values: 0 - 255
- laser is a Optional parameter for how bright the laser should be where
255 is full on and 0 if off.
- Valid values: 0 - 255
- blink is a Optional parameter how many milliseconds should pass before
blinking. Pass 0 to turn blinking off. Pass 3500 to make the laser blink
every 3.5 seconds.
- Valid values: 0 - 2147483647
Example query
http://192.168.1.231:5100/move?tilt=101&pan=148&laser=255&blink=1000
Method: HTTP GET.
Set accepts two query parameters
- laser is a Optional parameter for how bright the laser should be where
255 is full on and 0 if off.
- Valid values: 0 - 255
- blink is a Optional parameter how many milliseconds should pass before
blinking. Pass 0 to turn blinking off. Pass 3500 to make the laser blink
every 3.5 seconds.
- Valid values: 0 - 2147483647
Example query
http://192.168.1.231:5100/set?laser=255&blink=3000
Method: HTTP GET.
Grid accepts two query parameters
- tilt is a Required parameter for how much in degrees the tower should
be tilted (up/down position).
- Valid values: 0 - 264.
- pan is a Required parameter for how much in degrees the tower should
be paned (left/right position).
- Valid values: 0 - 255
Example query
http://192.168.1.231:5100/grid?tilt=70&pan=90
To upload this program firmware over the air (OTA) change the upload-port
to 3232. To upload this program firmware using usb change the upload-port
to something like COM6, that is if you computer gave the esp32 usb connection the name COM6.