The W55MH32L-EVB is a high-performance evaluation board featuring the W55MH32L microcontroller, designed for industrial and IoT applications. At its heart is a 32-bit Arm® Cortex®-M3 core running at up to 216MHz, with 1024KB of flash memory, 96KB of SRAM, and a fully integrated hardware TCP/IP offload engine.
In this project, we'll build a smart lamp that:
- Reads ambient light levels using an LDR (light-dependent resistor) via ADC
- Drives an RGB LED with PWM to produce white light
- Automatically brightens in the dark and dims in bright conditions
- Uses white balance calibration for pure white output
- Runs on MicroPython – no complex C code required
This is a perfect beginner-to-intermediate project for learning ADC, PWM, and analog-to-digital mapping on the W55MH32L-EVB.
Pin ConnectionsComponent Pin W55MH32L-EVB Pin
LDR Signal PB0
LDR VCC 3.3V 3.3V
LDR GND GND GND
RGB LED Red PWM PA6
RGB LED Green PWM PB9
RGB LED Blue PWM PA0
RGB LED + 3.3V 3.3V
RGB LED - GND GNDCode Explanation1. Imports and Pin Definitions
from machine import Pin, ADC, PWMWe import:
Pin– GPIO controlADC– analog-to-digital conversion for the LDRPWM– pulse width modulation for the RGB LED
The W55MH32L-EVB has 3x 12-bit ADCs with up to 12 input channels, offering 1μs conversion time and a 0~3.6V input range.
2. Reading Light Levels (ADC)
ldr = ADC(Pin(LDR_PIN))
light_level = ldr.read_u16() >> 4 # convert to 12-bit (0-4095)The ADC returns a 16-bit value (0-65535). We right‑shift by 4 to convert to the native 12-bit range (0-4095).
3. Brightness Mapping
brightness = map_value(light_level, 0, DARK_THRESHOLD, MAX_BRIGHTNESS, 0)This maps the light reading to a brightness value:
- Dark → low light_level → high brightness
- Bright → high light_level → low brightness
4. White Light with PWM
The RGB LED produces white light by mixing red, green, and blue at equal intensities:
def set_white(brightness):
r = int(WHITE_BALANCE[0] * brightness / MAX_BRIGHTNESS)
g = int(WHITE_BALANCE[1] * brightness / MAX_BRIGHTNESS)
b = int(WHITE_BALANCE[2] * brightness / MAX_BRIGHTNESS)
RED_PIN.duty(r)
GREEN_PIN.duty(g)
BLUE_PIN.duty(b)The duty() method takes a value from 0-255. WHITE_BALANCE lets you adjust the tint – for example, if white looks pink, reduce the red value.
DemoConclusionThis project demonstrates how easily you can build a smart, adaptive lamp on the W55MH32L-EVB using MicroPython. With just an LDR, an RGB LED, and a few lines of code, you've created an energy‑efficient lighting system that responds to its environment.
Next steps:
- Add Ethernet connectivity for remote monitoring and control
- Connect to Adafruit IO via MQTT to log light levels
- Add a temperature sensor to adjust colour temperature (warm light at night)
- Build a full smart home hub with multiple sensors
Build your own smart lamp today! 🚀







Comments