Smart Home Control Using ESP32, Touch Sensors, IR Remote, and Wi-Fi

Smart Home Control Using ESP32, Touch Sensors, IR Remote, and Wi-Fi

Smart Home Control Using ESP32, Touch Sensors, IR Remote, and Wi-Fi

Smart Home Control Using ESP32, Touch Sensors, IR Remote, and Wi-Fi

In this project, we explore how to build a smart home control system using the ESP32, touch sensors, an IR sensor, and Wi-Fi connectivity. The system is designed to control multiple devices (like lights, fans, or appliances) using both touch input and remote IR commands, while also offering remote control via Wi-Fi.

This kind of project is perfect for smart home automation where flexibility, convenience, and wireless connectivity are required.

Project Components

  1. ESP32 Development Board:
    • The core of the system, which provides Wi-Fi and Bluetooth connectivity. It also processes input from touch sensors and IR sensors.
  2. Relay Modules:
    • Used to control high-power appliances. Each relay corresponds to an output device (e.g., lights or fans).
  3. Touch Sensors:
    • Touch-sensitive input modules that allow physical interaction with the control system. Each sensor controls a relay or triggers an action.
  4. IR Sensor Module:
    • An IR receiver that accepts signals from a remote control, allowing users to operate the system from a distance.
  5. Wi-Fi Module (ESP32):
    • Provides wireless control and can be accessed via a smartphone or web app to manage connected devices.
  6. Power Supply:
    • A 5V or 12V DC power supply is used to power the relay board and ESP32.
  7. Other Components:
    • LED indicators for visual feedback, connecting wires, PCB, and basic electronic components.

System Overview

The ESP32 acts as the brain of the project, handling multiple input signals and controlling various devices. The touch sensors provide direct control over appliances, while the IR remote sensor allows users to control the devices from a distance. The Wi-Fi functionality enables users to remotely manage the system from their phone or web interface.

 

Circuit Diagram and Setup

The image shows a neatly laid-out system with the following connections:

  • ESP32 connected to a relay board to control the relays for switching appliances.
  • Touch Sensors connected to the GPIO pins of the ESP32 for direct input control.
  • IR Sensor wired to another GPIO pin to receive signals from the IR remote.
  • Power is provided by a voltage regulator module to ensure a stable 5V or 12V supply for the relays and sensors.

Key Wiring:

  • ESP32 GPIO Pins:
    • Several GPIO pins are used to control each relay.
    • Other GPIO pins are used for touch sensors.
    • The IR receiver is connected to a designated GPIO pin (e.g., GPIO 4).
  • Touch Sensors:
    • Connect multiple touch sensors to different GPIO pins of the ESP32.
  • IR Sensor:
    • The IR sensor receives signals and passes them to the ESP32, which decodes the remote control commands.
  • Relay Board:
    • Connect the relay board to the ESP32 to control high-power appliances. Each relay corresponds to a touch sensor or IR command.

Code for the ESP32

Here’s a simple ESP32 code that demonstrates how to control relays using both touch sensors and an IR remote. It also includes Wi-Fi capabilities for remote control.

///////////////////////

#include <WiFi.h>
#include <IRremote.h>
#include <ESPAsyncWebServer.h>

// Define relay pins
const int relay1 = 16;
const int relay2 = 17;
const int relay3 = 18;
const int relay4 = 19;

// Define touch sensor pins
const int touch1 = T0; // GPIO 4
const int touch2 = T3; // GPIO 15

// IR Receiver
const int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;

// WiFi credentials
const char* ssid = “your_SSID”;
const char* password = “your_PASSWORD”;

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

void setup() {
Serial.begin(115200);

// Initialize relay pins as OUTPUT
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);

// Start IR receiver
irrecv.enableIRIn();

// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to WiFi”);

// Web server to control the relays
server.on(“/relay1/on”, HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(relay1, LOW); // turn on
request->send(200, “text/plain”, “Relay 1 ON”);
});

server.on(“/relay1/off”, HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(relay1, HIGH); // turn off
request->send(200, “text/plain”, “Relay 1 OFF”);
});

// Repeat for other relays…

// Start server
server.begin();
}

void loop() {
// Check for IR signals
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);

// Example: Check if the IR code corresponds to a relay command
if (results.value == 0xFFA25D) { // Adjust to match your remote code
digitalWrite(relay1, !digitalRead(relay1)); // Toggle relay
}
irrecv.resume(); // Receive the next value
}

// Touch sensor control
if (touchRead(touch1) < 20) { // Adjust sensitivity
digitalWrite(relay1, LOW); // Turn on relay 1
} else {
digitalWrite(relay1, HIGH); // Turn off relay 1
}

// Add similar logic for other touch sensors…
}

/////////////////////

How It Works

  1. IR Remote Control:
    • The IR remote sends encoded signals to the IR sensor. The ESP32 decodes these signals and triggers the corresponding relay. For example, when the “ON” button is pressed, relay 1 is activated.
  2. Touch Sensor Control:
    • When a touch sensor is pressed, the ESP32 reads the input and toggles the corresponding relay. The relay turns ON or OFF, depending on the sensor state.
  3. Wi-Fi Control:
    • The ESP32 hosts a simple web server that allows the user to control relays through a browser interface. By visiting the IP address of the ESP32 and clicking on the relevant control links, the relays can be toggled.

Applications

This project is highly versatile and can be used for a range of applications, including:

  • Smart Home Lighting Control: Control lights and appliances using touch sensors, IR remotes, or through a smartphone app.
  • IoT Automation Projects: Remotely monitor and control devices over Wi-Fi from anywhere in the world.
  • Home Security Systems: Integrate sensors for doors and windows to trigger alarms or notifications.

Conclusion

By combining the ESP32 with touch sensors, an IR sensor, and Wi-Fi, we’ve created a flexible and convenient smart home automation system. This setup allows multiple methods of control, whether it’s physical touch, remote IR control, or over-the-air Wi-Fi commands. Such a system is a perfect entry point into the world of IoT (Internet of Things) and smart home solutions.