Community project

LED On Control

Photo of LED On Control
Generated with AI

For Work

Published November 5, 2026

This project builds a simple fan control system using an Arduino Uno, where a push button toggles a small N20 motor on and off. The RGB LED provides visual feedback—red when the fan is off, green when running—while a 16x2 LCD display shows the current fan state. The guide includes a complete wiring diagram, parts list, and step-by-step assembly instructions.

The firmware implements debounced button reading to ensure reliable switching, along with serial communication for remote control via USB. Builders will learn how to wire digital outputs, use I2C communication with the LCD, and write clean Arduino code that handles both physical and serial inputs. This project is ideal for beginners learning to combine multiple components into a functional embedded system.

Wiring diagram

Loading diagram…

Gather all the parts

QtyComponent
1

Rgb Led

Discrete four-pin common-cathode RGB LED with separate red, green, and blue anodes. Each colour channel needs its own current-limit resistor and can be PWM-dimmed from separate MCU GPIO pins.

1

Resistor

330 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Push Button

Momentary push button switch

1

LCD 16x2 I2C

16x2 character LCD display with I2C backpack

1

Resistor

330 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

330 Ω

Through-hole resistor (current-limiting in series with an LED)

1

M5Stack Mini Fan Unit - N20 Magnetic Motor with Propellers

DC MOTOR SKU:U063 Description FAN unit is designed with an N20 Motor and a small fan piece is included in the package. This N20 motor is has a 5V supply voltage. The output shaft has a rotational speed of 8800 RPM. Product Features single-direction rotation 5V-DC Simple DC motor with no gear 60 mm mini fan paddle Include 1x FAN unit 1x GROVE Cable 2x Plastic fan paddle Applications Electric Fan Specification Resources Parameter Net weight 9g Gross weight 24g Product Size 35*24*12mm Package Size 60*57*17mm Schematic EasyLoader download EasyLoader 1.EasyLoader is a simple and fast program burner. Every product page in EasyLoader provides a product-related case program. It can be burned to the master through simple steps, and a series of function verification can be performed. . After downloading the software, double-click to run the application, connect the M5 device to the computer through the data cable, select the port parameters, click "Burn" to start burning. (For M5StickC burning,

1

Regulated 5 V DC supply, 2 A

Enclosed regulated 5 V supply with labelled positive and negative low-voltage output terminals. Do not open or wire mains terminals.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

Assemble it in 4 steps

1. Remove the distance sensor

Unplug USB and the fan supply. Remove the HC-SR04 and all four of its wires. D5 will control the fan; move the blue LED resistor wire from D5 to D4.

2. Connect the fan module

Use the M5Stack Unit Fan U063, which contains its motor driver and protection. Connect its yellow DIN wire to D5, red VCC wire to the separate regulated 5 V supply positive terminal, and black GND wire to supply negative. Leave the white wire unconnected. Connect supply negative to Uno GND. Fit r4 (10 kΩ) between DIN and GND so the fan stays off during reset.

  • Do not connect fan power to a GPIO or the Uno 5V pin. Never join the separate supply positive to Uno 5V.
  • Use an enclosed regulated 5 V 2 A supply with labelled low-voltage output terminals. Never open or wire mains equipment.
  • Secure the motor and use a guard over its propeller. Keep fingers, hair and loose wires away. Disconnect fan power before handling it.

3. Keep the button and RGB LED

Keep the button between D2 and GND. Keep the common-cathode RGB LED common leg at GND, with D7 through r1 (330 Ω) to red, D6 through r2 (330 Ω) to green, and D4 through r3 (330 Ω) to blue. Red means commanded OFF; green means commanded ON. Blue stays off. Each press toggles the fan, with switch bounce filtered in software.

  • Keep a separate series resistor for each LED colour. Check the LED supplier pin diagram.

4. Keep the LCD and test

Keep LCD VCC at Uno 5V, GND at GND, SDA at A4 and SCL at A5. The backpack address is 0x27. Plug in USB and press Deploy, then power the fan supply. The fan starts OFF after reset. Press the button to toggle it. The existing browser GUI also controls it. The LCD shows commanded state, not proof of actual rotation. Press OFF and disconnect fan power when finished; disconnecting the browser alone does not stop it.

Review all connections

1. Connections between "r1" and "Arduino"

Functionr1Arduino
digitalP1GPIO 7
digitalP2 → Rgb Led REXT

2. Connections between "r2" and "Arduino"

Functionr2Arduino
digitalP1GPIO 6
digitalP2 → Rgb Led GEXT

3. Connections between "r3" and "Arduino"

Functionr3Arduino
digitalP1GPIO 4
digitalP2 → Rgb Led BEXT

4. Connections between "led1" and "Arduino"

Functionled1Arduino
groundGNDGND

5. Connections between "button1" and "Arduino"

Functionbutton1Arduino
digitalSIGNALGPIO 2
groundGNDGND

6. Connections between "lcd1" and "Arduino"

Functionlcd1Arduino
powerVCC5V
groundGNDGND
i2cSDAGPIO 18
i2cSCLGPIO 19

7. Connections between "fan1" and "Arduino"

Functionfan1Arduino
powerVCC → Regulated 5 V DC supply, 2 A POSEXT
groundGND → Regulated 5 V DC supply, 2 A NEGEXT
pwmDINGPIO 5

8. Connections between "supply1" and "Arduino"

Functionsupply1Arduino
groundNEGGND

9. Connections between "r4" and "Arduino"

Functionr4Arduino
digitalP1 → M5Stack Mini Fan Unit - N20 Magnetic Motor with Propellers DINEXT
groundP2GND

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
constexpr byte RED=7, GREEN=6, BLUE=4, FAN=5, BUTTON=2;
bool enabled=false, lastReading=HIGH, stableReading=HIGH;
unsigned long changed=0;
void updateOutputs() {
  digitalWrite(FAN,enabled?HIGH:LOW);
  digitalWrite(RED,!enabled); digitalWrite(GREEN,enabled); digitalWrite(BLUE,LOW);
  lcd.setCursor(0,1); lcd.print(enabled?F("Fan: ON         "):F("Fan: OFF        "));
}
void report() {Serial.println(enabled?F("ON"):F("OFF"));}
void setFan(bool on) {if(on!=enabled) {enabled=on; updateOutputs();} report();}
void setup() {
  digitalWrite(FAN,LOW); pinMode(FAN,OUTPUT);
  pinMode(RED,OUTPUT); pinMode(GREEN,OUTPUT); pinMode(BLUE,OUTPUT);
  pinMode(BUTTON,INPUT_PULLUP); Serial.begin(9600);
  lcd.init(); lcd.backlight(); lcd.setCursor(0,0); lcd.print(F("Button fan      ")); updateOutputs();
}
void loop() {
  bool reading=digitalRead(BUTTON);
  if(reading!=lastReading) {changed=millis(); lastReading=reading;}
  if(millis()-changed>=30 && reading!=stableReading) {
    stableReading=reading; if(reading==LOW) setFan(!enabled);
  }
  while(Serial.available()) {
    char c=Serial.read();
    if(c=='1'||c=='0') setFan(c=='1');
    else if(c=='?') report();
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik