LED
Lights when current flows. Five colors, and the brightness is what your eye would see.
- 2 pins
- 1 setting
- In 153 projects
- In 177 lessons
The LED in brief
What it is, and every setting the properties panel gives it.
An LED is a diode, not a resistor. Below about 1.5 volts a red one barely conducts; past that its current climbs exponentially with the voltage across it, so it takes whatever the rest of the loop can push through it while its own drop hardly moves. That is why an LED always needs a series resistor to set its current, never a bare wire to the supply: the resistor is what actually does the limiting. Mokxi models the Shockley equation itself rather than a fixed drop, so the anode net sits where the curve puts it (1.72 V for a red LED at 14.9 mA, and lower at lower currents) at whatever value the circuit’s resistor sets. What you see is not the instantaneous state either. The probe is a short-lived average of the LED’s brightness, with a time constant close to 8 milliseconds, the same range the eye’s own response takes, which is why a fast-blinking or PWM-dimmed LED here looks the way it would on a real bench rather than flickering once per switch.
- Family
- Basics
- Pins
- 2
- color
- red (or green, blue, yellow, white)
- red, green, blue, yellow or white. It changes the picture and the die: each color is specified by its drop at 20 mA, which is how a datasheet specifies one. Red 1.8 V, yellow 2.0 V, green 3.0 V, blue 3.0 V, white 3.1 V.
A circuit built around it, running and explained: the LED circuit simulator.
2 pins
Named as the editor names them, so a wire lands where you expect it.
How to wire an LED to an Arduino
An LED only lights one way around. The long leg is the anode (A): it goes toward the pin. The short leg, on the flat side of the rim, is the cathode (C): it goes toward GND. Put a resistor in series, 220 ohms for a 5 V board, so the pin does not push more current through the LED than either can take.
Then pinMode(pin, OUTPUT) and digitalWrite(pin, HIGH) light it. On a PWM pin, analogWrite(pin, 0 to 255) dims it. The circuit here is the first one most people build: an LED and a 220 ohm resistor on pin 13, blinking once a second.
On a 3.3 V board such as an ESP32 or a Pico, a 100 to 150 ohm resistor gives a red LED about the same brightness, and the LED pin in the sketch changes: GPIO 2 on an ESP32 DevKit, GP25 on the Pico.
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // pin 13 on an Uno
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}What is true about the LED, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The LED is a diode and the diode is the Shockley equation,
I = Is (exp(Vj / (N Vt)) - 1), with N = 2 and 12 ohm of bulk resistance, and
the color's drop at 20 mA is what sets Is. So the drop is not a number the
part carries around: it is whatever the curve gives at the current the circuit
is passing. A 5 V rail through 220 ohm lights a red LED at 14.9 mA with
1.72 V across it, and the same LED on 3.3 V through 220 ohm passes 7.7 mA
at 1.60 V. The drop falls with the current, which is what a real LED does and
what a fixed drop could never show.
Blue and white drop 3.0 V and 3.1 V, because that is what a real blue die does, so a blue LED on 5 V through 220 ohm passes 9.8 mA. On a 3.3 V rail it passes only 2.8 mA, which is the real reason a blue LED looks dim on a 3.3 V board.
The LED loads the net it is on, the way a real diode does, and below about a nanoamp of forward current it lets go of both nets entirely: no leakage, no reverse current. The probe is not the instantaneous brightness either: it is an 8 ms rolling average of it, the same time constant your own retina uses, so a PWM-dimmed LED reads as dimmed rather than as a random flicker.
Not modeled
One curve per color, and no spread. Real LEDs of the same color vary by a couple of hundred millivolts from part to part; every red LED here is the same red LED. The bulk resistance is 12 ohm and the emission coefficient 2 for every color, which is the middle of the range indicator LEDs sit in rather than a measurement of any one part.
No junction capacitance and no temperature. The junction is at 27 C and stays there, where a real LED's drop moves about 2 mV a degree, and it switches in nothing flat. There is no reverse breakdown either: reverse biased it passes its saturation current, which is femtoamps, however much you put across it.
Full brightness is 20 mA and the probe stops there. Brightness is the forward current divided by 20 mA and clamped at 1, so 20 mA and 200 mA look identical on the canvas even though the probe reports the current honestly.
The glow is drawn as bright as it looks. The eye does not see light in
proportion: seen brightness goes roughly as the cube root of the light, the CIE
lightness curve, and the canvas draws the probe through that curve. So an LED on
1 k from 5 V (3 mA, 15% of its rated current) looks about 45% lit, as it does on
the bench, rather than nearly off, and a linear analogWrite fade looks nearly
full for most of its travel and falls away at the bottom. The probe itself is
still the light, current over 20 mA averaged the way the eye averages a PWM.
LEDs, seven-segment dies and RGB LEDs (`led`)
| model | what sets it |
|---|---|
the same equation, with N = 2 and 12 ohm of bulk | the color's drop at 20 mA: red 1.8 V, yellow 2.0, green 3.0, blue 3.0, white 3.1 |
From LED, in full.
See the LED in a project
153 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
177 lessons place it in their own circuits.
The twelve week course
11 lessons
- Week 1: Current, voltage and the breadboard
- Week 2: Blink: the first program
- Week 3: Buttons, pull-ups and contact bounce
- Week 4: Timing without a processor: the 555
- Week 5: Logic gates, as real chips
- Week 6: Arithmetic from gates: the full adder
- Week 7: Memory: flip-flops and counters
- Week 8: More outputs than pins: the shift register
- Week 9: Pulse width modulation and the eye
- Week 11: Interrupts: events instead of polling
- Week 12: Project week: two boards, one wire
Learn articles
166 lessons
- Connect a Board to WiFi and Serve a Page
- How to Use a Breadboard: Your First Circuit
- Ohm's Law, in a Circuit You Can Run
- Picking a Resistor for an LED
- Pull-Up Resistors and the Floating Input They Fix
- Debouncing a Button: Why It Fires More Than Once
- PWM: Faking an Analog Voltage on a Digital Pin
- Logic Gates, and the Truth Table You Can Press
- Shifting a Byte In, One Edge at a Time
- Blink an LED with Arduino: Wiring and the Resistor
- Arduino Blink Without Delay: Two LEDs, Two Rates
- Arduino PWM Fade: analogWrite, Pins and the Curve
- Blink an LED on the ESP32-C3, Step by Step
- Blink an LED with a 555 Timer, No Microcontroller
- Arduino Simulators Compared: An Honest Roundup
- How to Simulate an Arduino Project Without Hardware
- Arduino Traffic Light Code with a Pedestrian Button
- Arduino Ultrasonic Sensor (HC-SR04) Tutorial
- Arduino 4x4 Keypad Code Lock with a Relay
- Arduino MPU6050: Accelerometer and Tilt
- Arduino Potentiometer Wiring and Code: Dim an LED
- Arduino LDR Night Light (Photoresistor)
- Arduino IR Remote: Decode NEC, Switch Lamps
- Arduino Joystick Module: Wiring, Code, Live Demo
- Arduino Buzzer and Piezo: Beeps, Notes, Metronome
- PIR Motion Sensor: How It Works, With an Arduino
- Series vs Parallel Circuits, Seen With LEDs
- The 555 Monostable: One Press, One Timed Pulse
- An Op-Amp as a Comparator, With Hysteresis
- Arduino State Machine: A Four-State Reaction Game
- ESP32 analogRead: 12 Bits, Attenuation and ADC2
- Raspberry Pi Pico PWM: Slices, Channels and 1 kHz
- STM32 Blue Pill Blink with Registers, Not pinMode
- Arduino Uno vs ESP32 vs Pico: Which to Learn First?
- Multisim Live Is Gone: A Chromebook Alternative
- Digital Electronics on Chromebooks: Labs by Unit
- Half Adder and Full Adder: Truth Table to Breadboard
- Flip-Flops Explained: SR Latch, D and JK Flip-Flops
- How to Use a Multimeter: Practice on a Virtual One
- Arduino Science Fair Projects With a Real Hypothesis
- Reaction Time Science Fair Project With an Arduino
- Engineering Science Fair Project: How to Write It Up
- 555 Timer Projects for a Science Fair (No Coding)
- Circuit Lab Division B: Middle School Starter Guide
- TSA Electrical Applications: Practice Circuits
- Arduino Simulator for Chromebook, Free in Chrome
- Arduino Simulator for Mac, Free in Safari or Chrome
- Arduino Projects for Beginners, Each One Running
- Arduino LED Not Lighting Up or Dim: What to Check
- Arduino Compile Errors Explained, With the Fixes
- How to Debug Arduino Code: Prints to Breakpoints
- "Was Not Declared in This Scope" in Arduino: 6 Fixes
- Arduino "expected ';' before" and Similar Errors
- Arduino stk500_getsync() Not in Sync: Upload Fixes
- ESP32 DevKit V1 Pinout: Every Pin and Which to Avoid
- ESP32-C3 SuperMini Pinout: LED, ADC, I2C, Boot Pins
- Wemos D1 Mini Pinout: D0-D8 to GPIO, I2C and SPI
- NodeMCU Pinout: ESP8266 D0-D8 to GPIO, Pins to Avoid
- Arduino Nano Pinout: PWM, I2C, SPI, A6 and A7
- Raspberry Pi Pico Pinout: GPIO, PWM, ADC and Power
- Arduino Uno Pinout: ATmega328P Pins, PWM, I2C, SPI
- Raspberry Pi Pico W Pinout: GPIO, LED and WiFi Pins
- XIAO ESP32-C3 Pinout: D Pins to GPIO, ADC, Boot Pins
- Pro Micro Pinout: 32U4 Pins for Arduino and QMK
- ESP-01 Pinout: GPIO0, GPIO2, Boot Modes and I2C
- STM32 Blue Pill Pinout: 5 V Tolerant Pins and BOOT
- ATmega328P Pinout: 28-Pin DIP to Arduino Pins
- Wemos D1 R32 Pinout: Uno Names to ESP32 GPIOs
- Arduino millis() Overflow: Why Subtraction Works
- Arduino map() Function: Scale Any Reading
- Arduino for Loop: Count, Repeat, Chase LEDs
- Arduino Array: Lists of Pins, Patterns and Notes
- Arduino Functions: Write It Once, Call It Anywhere
- Arduino Serial Read: Input from the Serial Monitor
- Arduino if else: One Branch Runs, and Why
- Arduino while Loop: Wait, Repeat, Break Out
- Arduino digitalRead(): Buttons, HIGH and LOW
- Arduino Data Types: int, long, float and byte
- Arduino Serial.print vs println, and Decimals
- Arduino const vs #define: Which One to Use
- Arduino Struct: Group Values, With Examples
- Arduino Pointers Explained: & and * on an Uno
- Arduino enum: Named States, enum class and Switch
- Arduino Timer Interrupt: Timer1 Every Second
- Arduino Watchdog Timer: Reset a Stuck Sketch
- Arduino AI Assistant in Your Browser: Meet Mokxi AI
- Fix Arduino Code With AI, and Know It Compiles
- ChatGPT for Arduino Code, and an AI That Compiles
- ESP32 PWM: ledcAttach, ledcWrite and Frequency
- Arduino Multitasking With millis(), Step by Step
- Arduino Static Variable vs Global, With Examples
- Arduino strtok: Parse Serial Commands and CSV
- Arduino "expected unqualified-id": Causes and Fixes
- Fix "lvalue required as left operand of assignment"
- Arduino Relay Module: Active LOW and Startup Clicks
- Leverless Controller Build: Buttons, Pins and Code
- SOCD Cleaning Explained, With Code
- Arcade Button Wiring for a Pro Micro or Pico
- Design Your Sim Racing Button Box in the Browser
- Home Assistant and ESPHome Devices on an ESP32
- Arduino Model Railroad: Turnouts, Crossings, Signals
- 3D Printer Firmware: Homing, PID, G-code, Runout
- DIY Stream Deck and Camera Slider With Arduino
- Arduino Eurorack CV Quantizer With a PWM DAC
- Arduino RC522 RFID Reader: Wiring and Code
- Arduino Soil Moisture Sensor: Code and Wiring
- Arduino Sound Sensor (KY-038): Clap Switch
- Arduino nRF24L01: Wiring, Code and a Radio Doorbell
- Arduino IR Transmitter: Laser Tag With Two Nanos
- Arduino Rotary Encoder (KY-040): Wiring and Code
- Arduino Tilt Sensor (SW-520D): Wiring and Code
- Arduino Tone Melody: Play a Song on a Piezo
- Arduino TM1637 Display: Library and Countdown
- Arduino BH1750 Light Sensor: Lux, Wiring, Code
- Arduino Flame Sensor: Wiring, Code and Range
- Arduino Vibration Sensor (SW-420): Wiring, Code
- Arduino Reed Switch: Wiring, Code and a Door Alarm
- Arduino pinMode(): OUTPUT, INPUT and INPUT_PULLUP
- Arduino Interrupts: attachInterrupt on Pin 2 and 3
- Arduino millis(): Timers and Multiple Tasks
- Arduino PWM Frequency: 490 Hz, 980 Hz, How to Change
- Raspberry Pi Pico MicroPython in Your Browser
- ESP32 MicroPython Simulator, Free in Your Browser
- CircuitPython Simulator for the Raspberry Pi Pico
- Raspberry Pi GPIO with Python, in Your Browser
- Arduino "Redefinition of void setup()": Fixes
- Arduino "Undefined Reference To": Every Cause
- Arduino "expected '}' at end of input": How to Fix
- Arduino "control reaches end of non-void function"
- Arduino "variable or field declared void": Fixes
- Arduino "call of overloaded is ambiguous": Fixes
- Arduino INA219: Current Sensor Library and Code
- Arduino SHT31: Library, Example and Wiring
- ATtiny85 Pinout: PB0 to PB5, ADC, PWM, I2C and ISP
- Arduino Leonardo Pinout: I2C, SPI on ICSP, A6-A11
- STM32F411 Black Pill Pinout: PC13, KEY and BOOT0
- Arduino Pro Mini Pinout: A4 to A7, FTDI, RAW, VCC
- ESP32 DevKitC Pinout: All 38 Pins and the Flash Six
- Arduino Assembly Language: AVR Assembly Online
- STM32 HAL and Register Code in the Browser
- Export a Circuit to a KiCad Schematic
- Arduino Build Guide and Parts Shopping List
- Follow Your Arduino Starter Kit in the Browser
- Digital Logic Lab Experiments, Graded in the Browser
- Microcontroller Lab Experiments With No Kits
- Virtual Electronics Lab for College Classes
- Free Arduino Simulator for Students, in the Browser
- Microcontroller Lab Viva Questions, With Answers
- Arduino Practical Exam Practice: Ten Timed Tasks
- ESP32 IoT Projects for Final Year Students
- Run an Electronics Lab for Online Classes
- Raspberry Pi Pico Button: Wiring and Code
- Arduino Halloween Props to Build in Your Browser
- Simulate an ESP32 and an Arduino Uno Together
- NPN Transistor Switch Simulator
- LED I-V Curve, Simulated and Swept
- 555 Timer Simulator: an LED Blinker
- Arduino Simon Says Game: Four LEDs, Four Buttons
- Arduino Whack-a-Mole Game: LEDs, Buttons, Score
- Arduino Game Projects You Can Play in Your Browser
- Tinkercad ESP32 Simulator: A Free Alternative
- ESP32 Projects for Beginners You Can Run Right Now
- STEM Club Ideas: Electronics and Coding Sessions
- Best ESP32 Simulator? The Free Options, Compared
- Tinkercad Alternatives: 6 Simulators, Compared
- Best Logic Gate Simulator: Free Tools Compared
The boards it is shown on
Each of these 29 boards has a built-in project with the LED in it.
- ESP32-C3-DevKitM-1
- Arduino Uno R3
- Raspberry Pi Pico
- STM32F411 Black Pill
- ATtiny85
- Arduino Nano
- Arduino Leonardo
- ESP32 DevKit V1
- ESP8266 NodeMCU V1.0
- Raspberry Pi Pico W
- SparkFun Pro Micro
- STM32 Blue Pill (F103)
- Arduino Uno R4 Minima
- BBC micro:bit V2
- Arduino Pro Mini
- Arduino Micro
- Wemos D1 mini
- ESP-01S
- Seeed XIAO ESP32-C3
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- ATmega328P on a breadboard
- Wemos D1 R32
- Waveshare RP2040-Zero
- WCH CH32V003
- STM32 Nucleo-F411RE
- Seeed XIAO ESP32-S3
- Raspberry Pi 4 Model B
- ESP32-C3 SuperMini
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the LED
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.