>DIY Touchless Switch with IR Sensor, Relay & LED | Turn on a Fan Without Touching!

DIY Touchless Switch with IR Sensor, Relay & LED | Turn on a Fan Without Touching! | Kids Arduino Project
✨ Robo Circuit Labs — Episode 13

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! ✨

📡 IR Sensor ⚡ Relay Module 💡 LED Indicator 🌀 Fan Control ⏱️ 1–2 Hours 🎓 Ages 8+ 💰 ~₹350 / $5
ARDUINO UNO FC-51 IR RELAY ~coil NO C NC LED FAN Wave! HAND WAVE → IR DETECTS → RELAY CLICKS → FAN + LED ON!

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!

⚡ The Science Bit

How Does It Work?

Three little heroes make this project work together like a team. Each one has a very important job:

📡 1
IR Sensor — The Eye

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!

2
Relay — The Muscle

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!

💡 3
LED — The Voice

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!"

🧠
The Toggle LogicThis project uses toggle mode — the first wave turns the fan ON, the second wave turns it OFF, the third turns it ON again… just like a light switch, but contactless! The Arduino remembers the current state using a boolean variable.
🧰 Shopping List

Parts You'll Need

🧠
Arduino Uno
The brain of the project; any Arduino Uno clone works
📡
FC-51 IR Obstacle Sensor
3-pin module (VCC, GND, OUT); range adjustable by potentiometer
5V 1-Channel Relay Module
Controls the fan; comes with opto-isolated protection circuit
💡
LED (any colour) × 1
Visual indicator; red or green looks great
🌀
5V USB Fan (small)
Safe for beginners — no mains voltage needed!
🔲
220Ω Resistor × 1
Limits current to the LED so it doesn't burn out
🍞
Breadboard
Half-size (400 tie-points) is plenty
🔌
Jumper Wires (M-to-M)
~20 wires; male-to-male for breadboard connections
🖥️
USB Cable + PC / Laptop
To power the Arduino and upload code via Arduino IDE
💡
Safest Fan to UseFor your first build, use a small 5V USB fan (like a phone cooler fan) powered by the relay instead of a mains AC fan. It works with the relay circuit but without the dangerous mains voltage. You can upgrade to an AC fan later with adult supervision.
🔌 Electronics Map

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!

ARDUINO UNO D2 → IR Sensor OUT D8 → Relay IN D13 → LED (+ 220Ω) 5V → Sensor + Relay GND → All GNDs FC-51 IR SENSOR TX RX POT VCC GND OUT RELAY MODULE COIL JD-VCC COM NO NC IN VCC GND LED INDICATOR LED 220Ω + (anode) − (cathode) 5V USB FAN Purple=IR Signal · Orange=Relay IN · Cyan=LED Signal · Yellow=Fan Power · Red=VCC · Black=GND
IR Signal (OUT→D2) Relay IN (→D8) LED Signal (→D13) Fan Power (via relay) VCC 5V GND
🛠️ Pin by Pin

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 PinArduino PinWire ColourWhat It Does
VCC5VREDPowers the IR sensor module
GNDGNDBLACKCompletes the power circuit
OUTDigital Pin D2PURPLESends LOW when hand detected; HIGH when clear

⚡ Relay Module → Arduino Uno

Relay PinArduino / ConnectionWire ColourWhat It Does
INDigital Pin D8ORANGEArduino controls the relay here (LOW = ON for most modules)
VCC5VREDPowers the relay coil
GNDGNDBLACKRelay ground
COMFan positive wire (+)YELLOWCommon terminal — always connected internally
NOFan power supply +YELLOWNormally Open — connects to COM when relay triggers

💡 LED Indicator → Arduino Uno

LED LegConnectionWire ColourWhat It Does
Anode (+) long leg220Ω resistor → Digital Pin D13CYANReceives signal from Arduino; resistor limits current
Cathode (−) short legGNDBLACKCompletes the LED circuit
⚠️
Check Your Relay Logic!Most 5V relay modules are Active LOW — meaning writing 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.
🔧 Let's Build!

Step-by-Step Build Guide

1

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).

🔍
Identify the Relay TerminalsYour relay module has a block of three screw terminals labelled COM, NO, and NC. You'll use COM and NO for this project (Normally Open — circuit is open when relay is off, closed when on).
2

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!

3

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

⚠️
Adult Supervision for Fan Wiring!If using a 5V USB fan, cut the USB cable, identify the red (+) and black (−) wires inside. Connect red (+) to relay COM terminal, and the USB charger positive to relay NO terminal. For mains-powered fans, always have a qualified adult handle ALL high-voltage wiring.
4

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!

5

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!

💻 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!

touchless_switch.ino Arduino C++
// ============================================================
//  ✨ 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
// ============================================================
🧠
What is Debouncing?When you wave your hand, the IR sensor might detect "hand present" dozens of times in one second. Without the debounce timer, the fan would toggle on–off–on–off rapidly during one single wave. The 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:

Serial Monitor OutputOUTPUT
✨ 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 🌀
✅ Try It Out!

Testing Your Touchless Switch

A

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.

B

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!

C

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.

D

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!

🚀 Go Further!

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️⃣

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!

❓ Good Questions!

Frequently Asked Questions

How does a touchless switch actually work?
The FC-51 IR sensor fires invisible infrared light from its emitter LED (like a tiny invisible flashlight). When your hand gets close and reflects that light back to the receiver LED, the sensor sends a LOW signal to the Arduino. The Arduino detects this change and toggles the relay on or off — turning your fan on or off without any physical contact!
Why do I need a relay? Can't I connect the fan directly to the Arduino?
An Arduino pin can only supply about 40mA of current at 5V — that's enough to blink an LED, but nowhere near enough to spin a fan! A relay is a tiny electrically-controlled switch: the Arduino sends a tiny 5V signal to the relay coil, which physically closes a metal contact that switches a separate, higher-power circuit. Think of it as a tiny robot hand that flicks a powerful switch for you!
My relay seems inverted — LOW turns it off and HIGH turns it on. Is something wrong?
Nope, perfectly normal! Most relay modules use "Active LOW" logic — they activate when you write LOW and deactivate when you write HIGH. This is because of the internal circuit design. If your relay behaves the opposite way to what the code expects, just swap LOW and HIGH in the applyFanState() function. The code comments explain exactly which lines to change.
The fan toggles multiple times from one wave. How do I fix it?
This is a debounce problem! Your hand passes the sensor slowly and the sensor detects multiple ON–OFF–ON transitions. Increase the 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.
Is it safe for kids to build this project?
The Arduino, IR sensor, LED, and relay control wiring are all safe 5V DC electronics — perfectly fine for kids aged 8 and up with basic adult supervision. The only potentially dangerous part is if you connect the relay to a mains AC-powered fan (220V/110V). For beginners, always use a 5V USB fan to avoid mains voltage completely. If you want to control an AC fan, ask a qualified adult to handle that wiring.
Can I use this to control a light bulb or any other device?
Yes! The relay doesn't care what's connected to its COM and NO terminals — it can switch any device that fits within its rated current (most 5V relay modules handle up to 10A at 250V AC). That means lights, pumps, buzzers, motors, even a kettle (with adult supervision). The Arduino code stays exactly the same!

🎉 You're a Wizard Now!

Seriously — you just built the same technology used in automatic hand sanitiser dispensers, touchless elevator buttons, and hospital hygiene systems. The same circuit. The same principle. You did it!

Now upgrade it: add a buzzer, connect a light, build a 4-channel version and control your entire desk setup with waves. The circuit knows no limits!

⚠️ Always supervise soldering and any wiring connected to mains voltage (220V/110V AC). Use a 5V USB fan when building for the first time. The Arduino sections are safe to explore independently.

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course