I often forgot to switch off appliances like a toaster or iron before going to the office. To resolve this issue, I have implemented a mobile app to control the switchboard, using ESP32 and AWS IoT services. This is a simple IoT project. I will explain, how to convert a simple switchboard to an automatic app-controlled switchboard.
Component Required
Components | Quantity | Buy |
ESP32 devkit v1 | 1 | |
Relay module 5v | 1 | |
Switchboard and light | 1 | |
Jumpers wire | 5-6 |
Relay Module
5v relay module is basically an electromagnetic switch. In the market, you will get a 5v module that is suitable for Arduino and 3.3v module suitable for ESP32 or ESP8266 microcontroller. Relay’s one side you can connect high power AC/DC device and on another side, you can connect a microcontroller.
High-Voltage connections
On this side, the relay has 3 pins. COM (common) pin, NO (normally open) pin, and NC (normally closed) pin.
NC (normal close) - This pin is connected to create a close circuit and its connection break when the signal is sent from the relay signal pin.
COM(Common) pin - This is generally connected with AC/DC load.
NO(normal open) - this pin is generally open and it becomes closed when the signal is sent from the relay signal pin.
Low-Voltage connections
On this side, it has 3-pin sets that connect with microcontrollers such as Arduino, Esp32/Esp8266.
Relay module Pins | Microcontrollers |
GND | GND |
Vcc | Vin/3.3V |
Inp1 | Any digital pin |
ESP32 Devkit V1(WROOM32)
ESP32 is a standalone and full-featured chip. Some of the features mentioned below:
- It has 2 preprocessor
- It has BLE and Wifi module in-built
- It has 512kb of internal memory
- 18 Analog to Digital Converter
- 3 SPI interfaces
- 3 UART interfaces
- 2 I2C interfaces
- 2 I2S interfaces
- 10 GPIO
- 2 Digital-to-Analog Converter
- 16 PWM pins
ESP32 comes up with 48 pins. Besides the digital input pin, it has 10 GPIO pins in ESP32, which connect to sensors D0, D2, D4, D12, D13, D14, D15, D27, D33, and D32.
Connections
Connect the positive end wire of the switchboard to the COM (Common) pin of the relay module. And connect the NO (Normal Open) pin to the switch ON side.
SwitchBoard Wire | Relay 5V |
+ve end of the wire | COM pin |
On the side of the switch | NO pin |
Between the relay module and ESP32, connect Vcc to Vin, GND to GND, and Input to D4 pin.
Relay 5V | ESP32 |
Vcc | Vin |
GND | GND |
Inp | D4 |
Coding
To publish/subscribe data from AWS, create a separate file and named it a 'Certificate.h' and add the Amazon Root CA1 certificate, Device certificate, and Device private key.
Certificate.h |
Include PubSub client library for publishing/submitting data using the MQTT protocol. and also include the wifiClientSecure library to establish a secure connection using TLS (SSL). To establish the secure connection add root certificate authority (CA) cert, device certificate and private key.
Define topic to subscribe/publish data to AWS, and add AWS endpoint. Add SSID username and password.
Set up AWS connection.
Implement a method to subscribe data whenever AWS broadcasts data. Broadcasting 1 from AWS to ON the light and 0 to switch OFF light.
The full code for subscribing/publishing data for the automated switchboard is mentioned below:
hope you liked this project. I will really appreciate it if you share valuable feedback. Also if you have any queries or want to say something, please mention them in the comment section. For mobile application development, check out next blog.