Wave
Your Hand,
Turn On
Anything!
Build a magic touchless switch using an IR sensor, relay, and LED with Arduino. No buttons, no touching — just wave your hand to control a fan like a wizard! ✨
Have you ever wished you could control devices like a wizard — just waving your hand and things magically turn on? Well, with a little bit of electronics and an IR (Infrared) sensor, you can do exactly that! This project builds a touchless switch that detects when your hand passes in front of it and automatically turns on a fan and a glowing LED indicator.
The best part? You don't need to press anything. Your hand is the switch! This is the exact same technology used in automatic hand sanitiser dispensers, touchless water taps, and smart elevators — and now you can build your own version for under ₹350!
How Does It Work?
Three little heroes make this project work together like a team. Each one has a very important job:
The FC-51 sensor fires invisible infrared light from its emitter LED. When your hand blocks and reflects that light back into the receiver LED, it outputs a LOW signal — the Arduino's cue that something is there!
A relay is a tiny electrically-controlled switch. The Arduino's 5V signal triggers a coil inside the relay that physically snaps a metal contact and connects the fan's power circuit. One tiny signal — one big result!
The indicator LED gives you visual feedback. It glows bright when the fan is ON and turns off when the fan is OFF. It's like the robot's way of saying "Hey, I heard you!"
Parts You'll Need
Circuit Diagram
Here is the complete circuit showing all four components and how they connect to the Arduino Uno. Trace each colour-coded wire before you start building!
Complete Wiring Table
Use this table alongside the circuit diagram. Match wire colours when building to make debugging easy!
📡 FC-51 IR Sensor → Arduino Uno
| IR Sensor Pin | Arduino Pin | Wire Colour | What It Does |
|---|---|---|---|
| VCC | 5V | RED | Powers the IR sensor module |
| GND | GND | BLACK | Completes the power circuit |
| OUT | Digital Pin D2 | PURPLE | Sends LOW when hand detected; HIGH when clear |
⚡ Relay Module → Arduino Uno
| Relay Pin | Arduino / Connection | Wire Colour | What It Does |
|---|---|---|---|
| IN | Digital Pin D8 | ORANGE | Arduino controls the relay here (LOW = ON for most modules) |
| VCC | 5V | RED | Powers the relay coil |
| GND | GND | BLACK | Relay ground |
| COM | Fan positive wire (+) | YELLOW | Common terminal — always connected internally |
| NO | Fan power supply + | YELLOW | Normally Open — connects to COM when relay triggers |
💡 LED Indicator → Arduino Uno
| LED Leg | Connection | Wire Colour | What It Does |
|---|---|---|---|
| Anode (+) long leg | 220Ω resistor → Digital Pin D13 | CYAN | Receives signal from Arduino; resistor limits current |
| Cathode (−) short leg | GND | BLACK | Completes the LED circuit |
LOW to the IN pin turns the relay ON, and HIGH turns it OFF. This feels backwards! The code below handles this correctly, but if your relay seems inverted, flip LOW and HIGH in the relay lines.Step-by-Step Build Guide
Gather and Inspect All Parts
Lay out all your parts before starting. Check that the IR sensor module has three pins (VCC, GND, OUT) — NOT four pins (some temperature sensors also have three pins and look similar!). The IR module has two small LEDs on the front: one clear (IR emitter) and one dark (IR receiver).
Wire the IR Sensor to Arduino
Place the IR sensor on one end of the breadboard. Use three jumper wires:
RED wire → IR VCC → Arduino 5V pin
BLACK wire → IR GND → Arduino GND pin
PURPLE wire → IR OUT → Arduino Digital Pin D2
When you power the Arduino, a small red or green LED on the IR module should light up — that means it's working!
Wire the Relay Module to Arduino
Place the relay module next to the Arduino. Connect:
ORANGE wire → Relay IN → Arduino Digital Pin D8
RED wire → Relay VCC → Arduino 5V
BLACK wire → Relay GND → Arduino GND
Wire the LED Indicator to Arduino
Look at your LED carefully — the longer leg is the positive (anode) and the shorter leg is the negative (cathode). Push it into the breadboard:
Longer leg (+) → 220Ω resistor → CYAN wire → Arduino Pin D13
Shorter leg (−) → BLACK wire → Arduino GND
The 220Ω resistor is essential — without it, too much current flows and the LED will burn out within seconds!
Double-Check Before Powering On
Before connecting USB, go through this checklist:
✅ IR sensor VCC to Arduino 5V (NOT 12V!)
✅ All GND wires connected to a common GND
✅ 220Ω resistor in series with the LED
✅ Relay IN to D8, IR OUT to D2, LED to D13
✅ No bare wires touching each other
Once you're happy with the wiring, connect the Arduino to your computer via USB and upload the code!
Arduino Code
Open the Arduino IDE, paste this code, select your board (Arduino Uno) and port, then click Upload. The code is fully commented so you understand every single line!
// ============================================================ // ✨ DIY Touchless Switch // IR Sensor + Relay + LED → Contactless Fan Controller // Robo Circuit Labs — Beginner-Friendly Version // ============================================================ // ----- Pin Definitions ----- #define IR_SENSOR_PIN 2 // FC-51 OUT → Arduino D2 #define RELAY_PIN 8 // Relay IN → Arduino D8 #define LED_PIN 13 // LED anode (via 220Ω) → D13 // ----- State Variables ----- bool fanOn = false; // Is the fan currently ON? bool lastState = HIGH; // Previous IR sensor reading // Debounce timing: prevents double-triggering from one wave unsigned long lastTriggerTime = 0; const unsigned long DEBOUNCE_MS = 800; // Minimum 0.8s between triggers // =================== SETUP =================== void setup() { Serial.begin(9600); // IR sensor pin reads HIGH (clear) or LOW (hand detected) pinMode(IR_SENSOR_PIN, INPUT); // Relay: OUTPUT, start HIGH = relay OFF // Most modules are ACTIVE LOW: HIGH = off, LOW = on pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, HIGH); // Fan OFF at startup // LED indicator pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // LED off at startup Serial.println("✨ Touchless Switch Ready!"); Serial.println("Wave your hand in front of the IR sensor."); } // =================== LOOP =================== void loop() { // Read the IR sensor // FC-51 sends LOW when it detects an object (hand) int sensorValue = digitalRead(IR_SENSOR_PIN); // Detect FALLING EDGE: HIGH → LOW means hand just appeared if (sensorValue == LOW && lastState == HIGH) { // Debounce check: only react if enough time has passed unsigned long now = millis(); if (now - lastTriggerTime > DEBOUNCE_MS) { lastTriggerTime = now; // TOGGLE: flip the fan state fanOn = !fanOn; applyFanState(); Serial.print("Hand detected! Fan is now: "); Serial.println(fanOn ? "ON 🌀" : "OFF"); } } // Save current reading for next loop comparison lastState = sensorValue; delay(10); // Small delay for stable readings } // =================== HELPER =================== void applyFanState() { if (fanOn) { // Fan ON: relay fires (LOW for active-low modules) // and LED glows digitalWrite(RELAY_PIN, LOW); digitalWrite(LED_PIN, HIGH); } else { // Fan OFF: relay opens (HIGH), LED turns off digitalWrite(RELAY_PIN, HIGH); digitalWrite(LED_PIN, LOW); } } // ============================================================ // HOW IT WORKS (for curious kids!): // // 1. IR sensor continuously emits invisible infrared light // 2. When your hand reflects that light back → OUT goes LOW // 3. Arduino detects the LOW signal on pin D2 // 4. It TOGGLES the fan state (ON→OFF or OFF→ON) // 5. Writing LOW to D8 fires the relay → fan gets power // 6. LED on D13 lights up as a visual confirmation // 7. Debounce timer prevents one wave from triggering twice // ============================================================
DEBOUNCE_MS = 800 line means: "ignore any new detections for 800 milliseconds after the last one." Wave = one clean toggle!🖥️ Watching It Work — Serial Monitor
After uploading, open Tools → Serial Monitor in the Arduino IDE and set baud rate to 9600. Every time you wave your hand, you'll see a message like:
✨ Touchless Switch Ready! Wave your hand in front of the IR sensor. Hand detected! Fan is now: ON 🌀 Hand detected! Fan is now: OFF Hand detected! Fan is now: ON 🌀
Testing Your Touchless Switch
Adjust the Sensor Range First
The FC-51 sensor has a small blue potentiometer (the adjustable knob) on the module. Turning it clockwise increases the detection range (up to ~30 cm); anticlockwise decreases it (down to ~2 cm). For a hand-wave switch, a range of 8–12 cm works best — close enough to wave, far enough to avoid accidental triggers from nearby objects.
Test Without the Fan First
Before connecting the fan, upload the code and just watch the LED on D13 and the status LED on the relay module. Wave your hand — the LED should toggle and you should hear a soft click from the relay as it switches. That click is the metal contact inside the relay snapping open or closed. Satisfying!
Troubleshooting: Fan Doesn't Switch
Fan always ON: Your relay might be Active High — try swapping LOW and HIGH in applyFanState().
Sensor doesn't trigger: Open Serial Monitor — if no messages appear when waving, check the IR OUT wire is on D2 and the sensor is powered (red indicator light on).
LED doesn't glow: Check the LED is the right way around (long leg to D13 side) and the 220Ω resistor is in the circuit.
Fine-Tune the Debounce Time
If the fan toggles multiple times per wave, increase DEBOUNCE_MS to 1200 or 1500. If it feels sluggish between waves, reduce it to 500. 800ms is the sweet spot for most people, but everyone waves at a slightly different speed!
Cool Upgrades to Try
Auto-Off Timer
Add a timer: fan automatically turns off after 5 minutes using millis(). Perfect for forgetting to switch off the fan when you leave!
Beep Confirmation
Add a piezo buzzer to D12 and beep once when turning ON, twice when turning OFF — audio confirmation without looking at the LED.
LCD Status Display
Add a 16×2 I2C LCD that shows "FAN: ON 🌀" or "FAN: OFF" so you always know the current state from across the room.
4-Channel Relay Board
Upgrade to a 4-channel relay to control four different devices — use different gesture patterns (quick wave / slow wave / double wave) for each one!
Wi-Fi Control via ESP8266
Replace the Arduino Uno with an ESP8266 NodeMCU — now you can also control the fan from your phone via Wi-Fi as a backup to the hand wave!
Temperature Auto-ON
Add a DHT11 sensor — the fan turns on automatically when temperature exceeds 30°C AND turns off when you wave. Smart and touchless!
Frequently Asked Questions
applyFanState() function. The code comments explain exactly which lines to change.DEBOUNCE_MS constant in the code — try 1000 or 1200 (milliseconds). This tells the Arduino to ignore new detections for at least that long after the first one, so one wave = exactly one toggle.
Comments
Post a Comment