Smart Plug With Esp32/Esp8266 and Solid State Relays
by RakaAmburo in Circuits > Arduino
1379 Views, 9 Favorites, 0 Comments
Smart Plug With Esp32/Esp8266 and Solid State Relays
Welcome again to this new Amburo tutorial. In previous tutorials, we have seen many ways to trigger an action and how to propagate that action to a variety of systems. Now let's get fiscal, what about controlling an object that is not directly within our reach? For example, anything that is connected to an electric power source. let's say a gate a dor, some kind of motorized device or a simple light. So sit back, because switches are coming to our aid.
What is a relay? A relay is an electrically operated switch. What is a solid-state relay? well is exactly the same but with no moving parts. And it requires an Alternate current.
In this project, we will be using a solid-state relay since we will be working with an Alternating current, we are able to use this kind of device. And we will be applying it to the simple things. we will be creating a power switch with 4 outputs.
Supplies
For this project, we will need a NodeMCU, a four-relay switchboard, a transformer that can deliver 5 volts to feed the NodeMCU, and the relay board as well. Of course cables for the connections and a couple of breadboards.
Wiring
The wiring is super simple. You will have to manage to connect everything with patience to make sure everything goes where it should.
The power supply and the ground are connected to the transformer input. The output as black and read will supply energy to the NodeMCU and the relay board as well. Bear in mind, that this is very important, you will have to adjust with the driver the output to 5 volts.
Channels 1 to 4 from the relay board will be connected to NodeMCU pins D1, D2, D5, and D6. And last you will have to connect the power supply to the light or to the outlet and to the relay switch that will be closing or breaking the circuit to turn on and off the light.
Adjust the Voltage of the Transformer
Very important to remember to adjust the transformer to 5v. This is the voltage required to feed the relay board and the NodeMCU. You can check this with a tester.
The Arduino Code
You will see that the code we will be uploading to the NodeMCU is pretty simple. At the top are the WIFI and UDP libraries. The variables we will be using for the relay state. The setup configuring the pins and the beginning of the WIFI and UDP. The loop with the processing of the incoming UDP signal. In the end, the UDP feedback sending and a utility function to get a string from the char array UDP packet.
Place All the Components in a Box
It would be more professional if you manage to fit everything inside some kind of rack or box.
Testing
With this small piece of code, you can send the required UDP signals to trigger the different switches. Remember to make sure you are sending it to the right port.
Coming Next
In future tutorials of these series, we will explore different ways we can build a device to control these switches in a super futuristic fashion
See you in the next one and have a good one.