Workbench light on an Arduino Uno
A 3 W power LED spot flashes on pin 8 through a D4184 module, its 700 mA set by a 12 ohm 10 W resistor on a 12 V adapter. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $37. On Mokxi they're free.
What you'll learn
- Switching a high-current load with a MOSFET module
- Setting LED current with a series resistor
- Resistor power rating and heat
- Timing with
millis()instead of waiting - Sharing ground between two supplies
- Difficulty: Intermediate
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 6
How it works
A 12 V adapter powers a 3 W LED spot through a D4184 MOSFET module. The Uno's pin 8 goes to the module's TRIG input and acts as a switch, so the Uno never carries the LED's current. The Uno and module share ground.
A 3 W LED has no built-in resistor. A 12 ohm, 10 W resistor sets the current to about 0.72 A and burns about 6.2 W as heat, which is why it must be a 10 W part.
The sketch toggles pin 8 every 2000 ms, so the spot is on for two seconds, then off for two seconds, and prints the state to serial.
Parts list
6 parts, plus the jumper wires. They retail for about $37; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × D4184 dual MOSFET switch module
- 1 × Resistor, 12 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × Power LED, 1 W or 3 W star
- 1 × DC jack and adapter
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| D4184 dual MOSFET switch module pin GND | Arduino Uno R3 pin GND |
| D4184 dual MOSFET switch module pin TRIG | Arduino Uno R3 pin 8 |
| DC jack and adapter pin V+ | D4184 dual MOSFET switch module pin VIN+ |
| DC jack and adapter pin V- | D4184 dual MOSFET switch module pin VIN- |
| Resistor, 12 Ω pin 1 | D4184 dual MOSFET switch module pin OUT+ |
| Power LED, 1 W or 3 W star pin - | D4184 dual MOSFET switch module pin OUT- |
| Power LED, 1 W or 3 W star pin + | Resistor, 12 Ω pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Workbench light: a 3 W power LED spot that pin 8 switches through a D4184
// MOSFET module.
//
// 8 the module's TRIG (on and off)
// GND the module's GND, shared with the Uno (its GND is its VIN-)
// 12 V a 12 V 2 A adapter into the module's VIN+ and VIN-
// spot the module's OUT+ through a 12 ohm 10 W resistor to the star's +,
// its - on the module's OUT-
//
// A 3 W LED has no resistor of its own. It is rated 700 mA at about 3.4 V,
// so the 12 ohm one sets the current: (12 - 3.4) / 12 = 0.72 A, and it burns
// (12 - 3.4) x 0.72 = 6.2 W, which is why it is a 10 W part. Leave it out and
// the LED takes amps and is gone in a second; a constant-current driver would
// waste less, but the resistor is the honest start.
//
// Press Run: the spot flashes on for two seconds in four.
const int SPOT_PIN = 8;
void setup() {
Serial.begin(115200);
Serial.println("Mokxi Arduino Uno: workbench light");
pinMode(SPOT_PIN, OUTPUT);
}
unsigned long lastSpot = 0;
bool spot = false;
void loop() {
unsigned long now = millis();
if (now - lastSpot >= 2000) {
lastSpot = now;
spot = !spot;
digitalWrite(SPOT_PIN, spot ? HIGH : LOW);
Serial.println(spot ? "spot on" : "spot off");
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
It opens serial at 115200 and prints a start message. Then pinMode makes SPOT_PIN (pin 8) an output, so the Uno can drive the module's TRIG input.
void setup() {
Serial.begin(115200);
Serial.println("Mokxi Arduino Uno: workbench light");
pinMode(SPOT_PIN, OUTPUT);
}loop sketch.ino
It reads millis() and compares it with lastSpot. Once 2000 ms have passed, it flips the spot flag and writes HIGH or LOW to the pin. It prints "spot on" or "spot off". Because nothing blocks the loop, the loop stays free for other work.
void loop() {
unsigned long now = millis();
if (now - lastSpot >= 2000) {
lastSpot = now;
spot = !spot;
digitalWrite(SPOT_PIN, spot ? HIGH : LOW);
Serial.println(spot ? "spot on" : "spot off");
}
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The spot never lights This project
Check that the module's GND is joined to the Uno's GND, and that VIN+ and VIN- are on the 12 V adapter. - The resistor gets very hot This project
That is expected. It dissipates about 6.2 W, so use the 12 ohm 10 W part and never swap in a small one. - The load never turns on, or it is only dim. D4184 dual MOSFET switch module
Check the load's own supply is wired to the screw terminals and the control pin gets 3.3 V or 5 V. Join the grounds of the controller and the load supply together. - Parts get hot or wires melt at high current. D4184 dual MOSFET switch module
The board can carry high current only with thick wire and good connections. Keep the load supply within the module's rated voltage, and use a flyback diode across motors and other coils. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - A power LED is wired straight to a microcontroller pin or with no resistor. It draws 350 or 700 mA and burns up or kills the pin. Power LED
Drive it with a logic level MOSFET and a current limiting resistor sized for the rated current, from a proper supply. Join the grounds. - The LED or the resistor overheats and it fades or fails. A 1 W or 3 W LED makes a lot of heat on a small area. Power LED
Mount the star on a heatsink with thermal paste. Rate the resistor for the power: I squared times R. Never run it without cooling for more than a moment.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.