In today’s post, we will design and convert an electrical socket to smart plug socket with ESP32 CAM Arduino Blynk app step by step. After reading this tutorial post, you will learn how to control an AC Socket point (socket plug) via the internet of things (IoT) using the Blynk app and ESP32-CAM WiFi Development Board. Ensure you read through to the end to understand it fully.
Why do we need to know this?
Well, when designing projects for Home automation, power management, and so on; we need to reduce the cost of the components and modules used in the project. This is the third tutorial on IoT-based Home Automation Using ESP32 Cam. We have aimed to use ESP32-CAM as the only microcontroller for the project. Streaming live video surveillance remotely from anywhere around the globe and also controlling the home appliances like home fans, and AC lightning bulbs with other features like room temperature in real-time.
A smart power socket falls under the category of electrical outlets; it is specially designed to be energy-efficient and easier to use. These sockets come equipped with sensors and WiFi capabilities. Allowing them to give feedback to their users through a connection to the internet or a network with enabled remote control over them. These features come in handy when trying to cut down energy costs and IoT home automation uses; helping reduce carbon footprint among others.
This works by auto-detect the type of device being used, supplying the device or appliances with the suitable energy it is rated for. Thereby removing worry on the part of users about if their device is getting enough power and allowing them to remotely control it using their smartphones and other mobile devices
When you plug a smart power socket into an outlet, the socket will automatically detect the type of device that is being used and adjust the power output accordingly. This means that you can use your devices without having to worry about how much power they are.
For this project we are going to be needing the following modules/components:
The circuit diagram shown above used the TIP41C NPN transistor to form a common emitter follower configuration. The 5V solid state relay is turned on and off without a based transistor since the ESP32-CAM dev board has a maximum out put voltage of 3.3V.
Two LEDs were connected in the circuit to show a blink without delay and also to visualize when the 5V relay is turned on and off from the Blynk app. These were tested without no current limiting resistors and they worked just fine. The PCB socket was used to connected the electrical wire plug. All Neutral lines were connected together. While the live line was controlled by the 5V solid state relay output. This is shown in the second breadboard schematic below.
The circuit diagram above works but we recommend using a method to control the 5V solid state relay to be in a two stable states, either ON or OFF; a transistor logic level inverter be created. This comprised of two 220kΩ resistor and a 10kΩ resistor configured around an NPN transistor. The setup of this logic level shifter is to convert the 3.3V HIGH on the ESP32 CAM GPIO pin to 0V and the 0V LOW to 5V. The need for this is to ensure that the 5V solid state relay switch the 5-9V needed to power the project.
This was noticed practically that when switching DC voltage using the 5V solid state relay, the HIGH voltage won’t be enough when using boards like ESP32, ESP32 CAM, ESP8266, Raspberry pi etc. To know more about the calculations used for this simple logic level shifter follow this link.
The ESP32-CAM development (dev) board was placed on the breadboard so that it can control the TIP41C NPN transistor through the base resistor 10kΩ. We attached the dev board to the breadboard and used the preformed jumper wires to finish off the rest of the connection between the transistor and the 5v solid state relay.
The 5V power needed for this bread setup was drawn from the programming CH340 adapter. The 5V of the ESP32-CAM is connected to the Vcc pin on the CH340 adapter; this is how the ESP32 Cam is connected. The emitter of the Transistor must have a common ground (GND) with the ESP32 Cam.
When working with Alternating current (AC) voltages, care must be taken to avoid electric shocks. The best way to control the flow of AC voltage through the socket outlet is to use the PCB socket header and terminate the wires carefully. The following steps are observed judiciously.
Strip off/Peel off the insulation AC wire terminals to expose the Live and Neutral wires to source the AC voltage to the PCB header. Screw and terminate these AC cables to the PCB header socket and ensure they are tight and firm.
Open the electrical socket and safely attach the Live and Neutral cable. Ensure they are tight and firm.
Use the 5V solid state relay to interrupt the AC Live (L) wire. This is shown in the schematic and breadboard diagram above. The remote control would talk to the ESP32-CAM development board and it will talk to the 5V solid state relay and tell it when it should turn on the AC socket.
Connect the rest of the wires to the 5v solid state relay, ensuring that all the Neutral lines (wires) are connected together.
Use insulation tape to insulate and isolate all exposed AC voltage wires joined together. This will reduce the electric shock when the system is powered.
Open the respective app store for your device and find Blynk legacy. Please get the Blynk legacy version because that was used for this project. However, if you can’t use this version, kindly leave a comment in the comment section so that we could tell you how to use the latest version of Blynk IoT app for this electrical socket to smart plug socket with ESP32 CAM Arduino Blynk app project.
We installed the app on our android or iPhone device as shown in the picture above.
After successful installation, we signed up or signed since we already have an account and click on New Project as shown below.
After setting the name of the project click, we selected our device type, and click create.
We went to our mailbox or alternatively our Blynk dashboard to copy the token. This would be used in the Arduino code later.
We clicked on the add button on the upper right side and add the button widget. Configure this button widget by clicking on it and selecting where the virtual pin is selected.
This was saved and it was done.
We removed the ESP32-CAM from the breadboard and placed it onto the ESP32-Cam programmer adapter. We connected the USB flex to the port of the programmer. The programmer used a type B USB flex to its USB programmer as shown here below. This was connected this cable to our PC, the power LED on the programmer came on. We opened the Arduino IDE and copied the code below and compiled it successfully.
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//int led_gpio = 13;
#define Authorization_key "CjMXMZ3xjcbpG7gtnSPTFisJFkJ3WxF9" //EExmWR-3B8jC7H0ttOzr9qmtAciGW8DR
#define SSID "AncII" // replace with your SSID
#define Password "eureka26" //replace with your password
void setup() {
//pinMode(led_gpio, OUTPUT);
Serial.begin(115200);
delay(10);
WiFi.begin(SSID, Password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Blynk.begin(Authorization_key,SSID,Password);
}
void loop(){
Blynk.run();
}
The Arduino sketch given above began with including the various libraries from Blynk and WiFi connectivity; The Authentication Key was inserted from the email sent by Blynk after creating the project; so was the Internet WiFi USSID and Password too from an existing network with good internet access.
Once these are all set, we select our port number, select AI thinker ESP32-Cam as the development board then upload code.
With the complete setup done, we have the following testing results as shown here.
The button on the phone would allow us to turn the electrical socket into a smart plug socket. we can turn it on and off remotely from anywhere around the globe.
The downside to this is the manual switch on the socket, this can be rectified for forcefully removing the switch and ensuring no more manual controls.
Once we are connected to the internet, the setup works nicely; as expected!
The project was aimed at using IoT to control an electrical socket via a mobile app. We have successfully shown that we can convert electrical socket to smart plug socket with ESP32 CAM, Arduino and Blynk app. Do you think you can do the same or even more than this? Kindly let us know by commenting below. Also if you have any questions, leave us a message in the comment section or on our Whatsapp handle or telegram group.
Don’t forget to share this post if you like it. You can read the next post on:
IoT Control Light bulb using ESP32 IoT Control of DC rechargeable home Fan.
See you on the next post.
Thank You.
The Alpha's Warlock In "The Alpha's Warlock," the narrative centers around two main characters: Alpha Kael,…
embracing imperfections Let’s talk about something that touches each of our lives in one way…
The Cold War: A Tense Standoff Introduction The Cold War was not just a period…
The Birth of Bitcoin Introduction In a world where traditional finance often feels cumbersome and…
The Broken Mute’s Revenge In "The Broken Mute's Revenge," the story revolves around a young…
Introduction Imagine a classroom where students take the reins of their own education, setting their…
This website uses cookies.