IoT Smart Light Control with Ultrasonic Sensor Simulation
🔧 Introduction
Smart lighting is one of the most popular IoT applications. In this project, we’ll build a system where an ultrasonic sensor detects motion or proximity, and an LED light turns on automatically. We’ll demonstrate the setup using a simulation environment, making it easy for beginners to reproduce before moving to real hardware.
🛠️ Components Needed
- Arduino Uno
- HC-SR04 Ultrasonic Sensor
- LED
- 220Ω resistor
- Jumper wires
⚡ Wiring Overview
- Ultrasonic Sensor (HC-SR04):
- VCC → 5V
- GND → GND
- TRIG → Pin 8
- ECHO → Pin 9
- LED:
- Anode (+) → Pin 10 (through 220Ω resistor)
- Cathode (–) → GND
💻 Arduino Code
// IoT Smart Light Control with Ultrasonic Sensor
const int trigPin = 12;
const int echoPin = 11;
const int ledPin = 8;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Trigger ultrasonic pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read echo
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
if (distance < 20) {
digitalWrite(ledPin, HIGH); // Turn LED ON
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF
}
delay(100);
}
🧠How It Works
- The ultrasonic sensor measures distance using sound pulses.
- If an object is within 20 cm, the LED turns ON.
- Otherwise, the LED stays OFF.
- This simulates a smart light system that reacts to presence.
🚀 Extensions
- Replace LED with a relay + bulb for real-world lighting.
- Add WiFi (ESP8266) to control lights remotely.
- Log sensor data to a cloud platform like ThingSpeak.
📥Download Wiring Diagram PDF (Simulation) —

Comments
Post a Comment