Optical Laser Guitar System for ESP32
An ESP32 sensor project involving Speaker.
Parts and sourceBefore you start
Check the exact Speaker configuration against the upstream wiring or parts list.
Upstream README
Optical Laser Guitar System
Academic Final Year Project completed as part of the B.S. Telecommunication Engineering program at Hazara University.
A touchless musical instrument that turns five laser beams into virtual guitar strings. Break a beam with your hand and an ESP32 plays the corresponding note in real time — no strings, no contact, just light.
Overview
The Optical Laser Guitar System is a touchless musical instrument built around an ESP32 microcontroller, five laser modules, five LDR (Light Dependent Resistor) sensor modules, and a speaker.
Each laser beam behaves like a virtual guitar string. When a user interrupts a beam with their hand, the corresponding LDR detects the drop in light intensity. The ESP32 reads this analog change, recognises the "string" as plucked, and plays the assigned guitar note in real time through its built-in DAC connected to a speaker.
The project demonstrates the practical application of embedded systems, optical sensing, analog-to-digital conversion (ADC), digital-to-analog conversion (DAC), and real-time signal processing.
Features
- Five independent virtual strings — one laser/LDR pair per note.
- Completely touchless — play by interrupting laser beams with your hand.
- Real-time response — notes trigger the instant a beam is broken.
- On-board audio — guitar samples played via the ESP32 built-in DAC (GPIO25).
- Self-contained — no PC, phone, or network required while playing.
- Ambient-light resistant — optical shielding around each LDR rejects stray light.
- USB powered — a single cable powers the ESP32 and all connected modules.
Project Specifications
| Specification | Detail |
|---|---|
| Microcontroller | ESP32 DevKit |
| Programming Language | Embedded C++ |
| Development Environment | Arduino IDE |
| Power Supply | USB 5V |
| Sensors | 5 × LDR Sensor Modules |
| Input Method | Laser Beam Interruption |
| Output Device | Speaker Module using ESP32 DAC (GPIO25) |
| Number of Virtual Strings | 5 |
Hardware Components
| Component | Qty | Purpose |
|---|---|---|
| ESP32 Development Board | 1 | Central controller — reads sensors and generates audio |
| Laser Module | 5 | Emit the virtual "strings" |
| LDR Sensor Module | 5 | Detect when a beam is broken |
| Speaker Module | 1 | Output the audio |
| Breadboard | 1 | Prototyping and connections |
| Jumper Wires | — | Wiring between modules |
| USB Cable | 1 | Power and programming |
Working Principle
- USB powers the ESP32, which in turn powers the lasers, LDRs, and speaker.
- Each laser shines continuously onto its paired LDR, keeping every "string" in a brightly lit state.
- The ESP32 samples all five LDRs in a tight loop using its ADC channels.
- Each reading is compared against a calibrated threshold to decide whether the beam is lit or blocked.
- Breaking a beam drops the light level past the threshold, which the firmware interprets as a pluck on that string.
- The note sample is streamed to the DAC on GPIO25, producing the analog waveform sent to the speaker.
- The loop repeats thousands of times per second, so the instrument feels instant and responsive.
USB 5V ─► ESP32 ─► Lasers ──► (beams) ──► LDRs ─► ADC read ─► threshold check
│
beam broken? ──────────┘
│ yes
▼
play note sample ─► DAC (GPIO25) ─► Speaker
Pin Configuration
| Component | ESP32 Pin |
|---|---|
| LDR 1 | GPIO34 |
| LDR 2 | GPIO35 |
| LDR 3 | GPIO32 |
| LDR 4 | GPIO33 |
| LDR 5 | GPIO26 |
| Speaker | GPIO25 (DAC Output) |
GPIO34/35 are input-only ADC pins, ideal for reading the LDRs. GPIO25 is one of the ESP32's two true DAC outputs, which is why it drives the speaker.
Source Code
The firmware for this project was developed in Embedded C++ using the Arduino IDE for the ESP32 microcontroller.
The source code is not included in this public repository because it was developed as part of an academic Final Year Project. This repository is intended to showcase the project's design, implementation, hardware architecture, engineering challenges, and final results.
If requested for academic review or professional discussion, the implementation details can be explained during interviews or technical presentations.
Skills Demonstrated
Embedded Systems · ESP32 Programming · Embedded C++ · Arduino IDE ·
Sensor Interfacing · Circuit Design · Analog-to-Digital Conversion (ADC) ·
Digital-to-Analog Conversion (DAC) · Hardware Troubleshooting ·
System Integration · Prototyping · Problem Solving
Technologies
- ESP32 DevKit
- Arduino IDE
- Embedded C++
- LDR Sensor Modules
- Laser Modules
- GPIO
- ADC
- DAC
- Breadboard Prototyping
Challenges and Solutions
| Challenge | Solution |
|---|---|
| Ambient light interference affected the LDR sensors and caused false triggers. | Installed optical shielding tubes (straws) around each LDR so it only sees its own laser. |
| Laser alignment was difficult and easily disturbed. | Optimized the laser alignment and mounting for a stable beam locked onto each LDR. |
| Limited ESP32 memory restricted how much audio could be stored. | Optimized the audio files (8-bit mono PCM, reduced sample rate) to fit in available memory. |
Results
- Successfully implemented a touchless, laser-based musical instrument.
- Achieved real-time laser interruption detection with no perceptible lag.
- Reliable operation under bright indoor lighting and daylight after optical shielding was added.
- Five independent laser strings, each triggering a different guitar note.
- Improved sensor reliability under varying ambient lighting through custom optical shielding.
Applications
- Interactive musical instruments
- Embedded systems education
- Human-Computer Interaction (HCI)
- STEM demonstrations and science exhibitions
- Educational laboratories
Future Improvements
- Polyphonic playback (multiple notes at once)
- Dedicated audio amplifier for louder, cleaner sound
- OLED display for live status
- Bluetooth connectivity for wireless control and MIDI support for compatibility with digital music production software
- More laser strings for a wider note range
Key Achievements
- Designed and developed a fully functional touchless laser-based musical instrument.
- Successfully interfaced five LDR sensor modules with an ESP32 microcontroller.
- Implemented real-time laser interruption detection for note triggering.
- Generated guitar audio through the ESP32 built-in DAC.
- Improved reliability under bright ambient lighting using custom optical shielding.
- Integrated hardware and software into a complete working embedded system prototype.
Repository Structure
Optical-Laser-Guitar-System
├── README.md # Project documentation
├── LICENSE # MIT License
├── .gitignore
└── images/
└── project.jpg # Project photo
Author
Muhammad Hassan B.S. Telecommunication Engineering Graduate Hazara University, Mansehra hassan.abdali48@gmail.com
Interested in embedded systems, electronics, AI, and Flutter app development.
License
This project is licensed under the MIT License — see the LICENSE file for details.