LED Dimmer
Fade the onboard LED in real time with a brightness slider — your first write-with-payload characteristic.
Where the RGB project sends a simple on/off flag, this project sends a value with meaning: a single byte from 0 to 255. The sketch exposes one brightness characteristic and applies whatever you write to it with analogWrite(), which drives the built-in LED with PWM (pulse-width modulation).
PWM switches the LED on and off thousands of times per second; the byte you send sets the fraction of time it spends on. Your eye averages the flicker into a smooth brightness level, so dragging the slider fades the LED continuously instead of just snapping between on and off.
While you drag, the app writes the slider position to the characteristic. Writes are applied in the sketch loop within milliseconds, so the LED tracks your finger with no perceptible lag. On disconnect the sketch resets brightness to zero and starts advertising again.
Goals
- Write a single-byte brightness value over BLE
- Drive the onboard LED with PWM from the browser slider
- See how payload writes differ from on/off toggles
Materials
- Arduino Nano 33 BLE (or BLE Sense)
- USB cable
- Arduino IDE with ArduinoBLE library