EXPERIMENT NO.
6
AIM : IoT based home Automation using Arduino.
SOFTWARE REQUIRED : TINKERCAD Software
HARDWARE REQUIRED :
Name Quantity Component
U1 1 Arduino
Uno R3
L1 1 Light bulb
K1 1 Relay SPDT
P1 1 5 , 5 Power
Supply
THEORY : A Relay is an electromechanical switch used to control high-power electrical
circuits with a low-power signal. It operates on the principle of electromagnetism,
allowing the isolation of control and load circuits.
Key Features:
1. Control Voltage: Typically 3V to 12V (for low-power control).
2. Load Voltage/Current: Can switch AC/DC loads with high power (e.g., 250V AC,
10A).
3. Pins:
o Coil Pins: For energizing the electromagnet.
o Common (COM): The central connection point.
o Normally Open (NO): Circuit remains open until relay is activated.
o Normally Closed (NC): Circuit remains closed until relay is activated.
PROCEDURE :
22EEAEC024 Submitted By :- Kunal Singh Chauhan
Step 1:- Build the circuit.
Step 2:- Program
// Define pins
#define CLAP_BUTTON_PIN 11 // Pin connected to the push button
(clap simulation)
#define VOICE_LIGHT_ON_PIN 9 // Pin connected to Button1 (simulates
"light on" voice command)
#define VOICE_LIGHT_OFF_PIN 6 // Pin connected to Button2 (simulates
"light off" voice command)
#define VOICE_FAN_ON_PIN 5 // Pin connected to Button3 (simulates
"fan on" voice command)
#define VOICE_FAN_OFF_PIN 3 // Pin connected to Button4 (simulates
"fan off" voice command)
#define LED_PIN 2 // Pin connected to the LED (light)
#define RELAY_PIN 12 // Pin connected to the relay (fan)
bool lightState = false; // Current state of the light
bool fanState = false; // Current state of the fan
bool lastButtonState[6] = {HIGH}; // Previous states of all buttons
bool currentButtonState[6] = {HIGH}; // Current states of all buttons
unsigned long lastDebounceTime[6] = {0}; // Last time button states
were checked
unsigned long debounceDelay = 50; // Debounce time (ms)
void setup() {
pinMode(CLAP_BUTTON_PIN, INPUT_PULLUP);
pinMode(VOICE_LIGHT_ON_PIN, INPUT_PULLUP);
pinMode(VOICE_LIGHT_OFF_PIN, INPUT_PULLUP);
pinMode(VOICE_FAN_ON_PIN, INPUT_PULLUP);
pinMode(VOICE_FAN_OFF_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
digitalWrite(RELAY_PIN, HIGH);
Serial.begin(9600); }
void loop() {
const int buttonPins[] = {CLAP_BUTTON_PIN, VOICE_LIGHT_ON_PIN,
VOICE_LIGHT_OFF_PIN, VOICE_FAN_ON_PIN, VOICE_FAN_OFF_PIN};
22EEAEC024 Submitted By :- Kunal Singh Chauhan
const char* buttonNames[] = {"Clap Button", "Voice Light On", "Voice
Light Off", "Voice Fan On", "Voice Fan Off"};
for (int i = 0; i < 6; i++) {
int reading = digitalRead(buttonPins[i]);
if (reading != lastButtonState[i]) {
lastDebounceTime[i] = millis();
} if ((millis() - lastDebounceTime[i]) > debounceDelay) {
if (reading != currentButtonState[i]) {
currentButtonState[i] = reading;
if (currentButtonState[i] == LOW) {
switch (i) {
case 0: // Clap Button
lightState = !lightState;
fanState = !fanState;
digitalWrite(LED_PIN, lightState ? HIGH : LOW);
digitalWrite(RELAY_PIN, fanState ? LOW : HIGH);
Serial.print(buttonNames[i]);
Serial.print(" Pressed. Light: ");
Serial.print(lightState);
Serial.print(", Fan: ");
Serial.println(fanState);
break;
case 1: // Voice Light On Button
lightState = true;
digitalWrite(LED_PIN, HIGH);
Serial.println(buttonNames[i]);
break;
case 2: // Voice Light Off Button
lightState = false;
digitalWrite(LED_PIN, LOW);
Serial.println(buttonNames[i]);
break;
case 3: // Voice Fan On Button
fanState = true;
digitalWrite(RELAY_PIN, LOW);
Serial.println(buttonNames[i]);
break;
case 4: // Voice Fan Off Button
fanState = false;
digitalWrite(RELAY_PIN, HIGH);
Serial.println(buttonNames[i]);
break;}}}}
lastButtonState[i] = reading;}}
22EEAEC024 Submitted By :- Kunal Singh Chauhan
Step 3:- Compile the program.
RESULT : IoT based Home Automation have been successfully done.
22EEAEC024 Submitted By :- Kunal Singh Chauhan