A professional single‐file Arduino sketch to safely drive and dim a 12 V laser module using PWM, a MOSFET driver, a potentiometer and a toggle button.
📁 File: LaserControl.ino
👤 Author: bocaletto-luca
🔧 License: MIT
| Component | Qty | Notes |
|---|---|---|
| 12 V Laser Module | 1 | TTL/analog PWM input compatible |
| N-Channel MOSFET (e.g. IRLZ44N) | 1 | Logic‐level gate, 30 V, 47 A |
| Arduino Uno / Nano / … | 1 | |
| 10 kΩ Potentiometer | 1 | For power adjustment |
| Push Button (toggle switch) | 1 | With internal pull-up |
| 220 Ω Gate resistor | 1 | Protect MOSFET gate |
| 10 kΩ Pulldown resistor | 1 | On MOSFET gate (optional if using gate resistor) |
| External 12 V power supply | 1 | ≥ Laser module current rating |
| Hook-up wire, breadboard | — |
| Arduino Pin | Connected To |
|---|---|
| D9 (PWM) | MOSFET gate (via 220 Ω resistor) |
| GND | MOSFET source, Arduino GND, Laser GND |
| 12 V VIN | Laser VCC |
| D2 | Toggle button → GND (INPUT_PULLUP) |
| A0 | Potentiometer wiper |
| 5 V | Potentiometer VCC |
| GND | Potentiometer GND |
12 V Supply ──+── Laser VCC | +── Arduino Vin (if powering Arduino that way)
Laser GND ── MOSFET Drain MOSFET Source ── GND (common)
Arduino D9 ──┬─ 220 Ω ── Gate of MOSFET └─ 10 kΩ ── GND (optional gate pulldown)
Potentiometer: 5 V ── Wiper (A0) ── GND
Button: Arduino D2 ── Button ── GND (pull-up enabled in code)
⚙️ Usage
Wire the components as shown.
Open LaserControl.ino in Arduino IDE.
Select board & COM port.
Upload the sketch.
Adjust power with the potentiometer, toggle laser with the button.
Monitor status on Serial Monitor @ 9600 baud.
🚨 Safety Tips
Always use laser safety goggles rated for your wavelength.
Never point the beam at eyes or reflective surfaces.
Implement an emergency-stop or key-switch for high-power modules.