ESP32IOT Projects and ESP32 based two-way communication system and ESP32: and ESP32 based two-way communication system– In my previous tutorial, I used IoT Cloud platform with Nodemcu ESP8266 WiFi module for controlling electrical devices. This project was based on one-way communication and I was only able to control electrical devices. I did it on purpose, as my main focus was to explain how to get started with So, if you are just getting started with then I highly recommend, you should read my previous article.

Now, in today’s article, I am going to explain how to make a two-way communication monitoring and control system using my designed ESP32 WiFi + Bluetooth development board, a potentiometer which I am going to use as an analog sensor, and some 110/220Vac bulbs. and ESP32

Anyway, this is the prototype model. I have connected everything as per the circuit diagram which I will explain in a minute. Previously, I was using a separate relay module while this time I have soldered everything on a single PCB except the Potentiometer.

For demonstration purposes, I am using 4 bulbs that are connected to 4 relays. Besides lights, you can use any other 110/220Vac loads or use any other DC type loads.

If you want to use 110/220Vac supply, you must not forget to use protective gloves, because 110/220Vac can prove fatal. So, as far as possible you must ensure the presence of a friend or any companion while carrying on work on such projects. When the AC supply is ON, do not touch the relay module. Let’s go ahead and start a practical demonstration so that you can see everything for yourself.

Altium Designer + Altium 365 + Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.

Practical Demonstration:

Let me remind you one more time, never touch the relay contacts when the AC supply is ON. and ESP32

Anyway, right now the Laptop and ESP32 both are connected to WiFi. You can use the same or different WiFi networks it’s totally up to you. It’s an IoT “Internet of things” based project you can control these bulbs and monitor this potentiometer from any part of the world provided if the internet connection is available.

You can see all the Bulbs are OFF and currently the Potentiometer value on the Gauge is 1075. Now, I am going to rotate the knob of the Potentiometer to change the value, and I will also turn ON two Bulbs. and ESP32

You can randomly control all the 4 Bulbs, if you want you can increase or decrease the number of loads. You can also increase the number of sensors. For the practical demonstration watch video tutorial available on my YouTube channel “Electronic Clinic”.

I am sure by now, you might have got an idea of how does this system work. So, without any further delay let’s get started!!!

Amazon Links:

12v Adaptor:

ESP32 Wifi + Bluetooth Module:

LM7805 Voltage Regulator:

470uf capacitor:

DC Female Power Jack:

Female Headers:

1n4007 diode:

10k Resistor:

2n2222 NPN transistor

12V SPDT Relay:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

ESP32 Development Board Circuit: and ESP32 circuit diagram

J1 is the female power jack and this is where we connect a 12v adaptor, battery or a solar panel. Two 470uf capacitors are connected on the input and output sides of the 7805 voltage regulator. The output of the voltage regulator is connected to the 5v pin of the ESP32 module and the ground of the power supply is connected to the ground of the ESP32 module.

A Potentiometer R1 is connected to the GPIO Pin 36 which is an analog pin.

These are 12v SPDT type relays and can’t be directly controlled using the ESP32 Module, So, that’s why we need a driver to control these relays. You can use a relay driver IC or you can use 2N2222 NPN transistors and 10k resistors. One pin of the relay coil is connected with the collector of the 2n2222 NPN transistor while the other pin of the relay coil is connected with the 12 volts. The emitter of the transistor is connected with the ground while the base is connected with the 10k ohm resistor.

Freewheeling diodes are also connected across the relay coils. These diodes provide protection against the Back EMF.

Now to control these relays you simply need to connect these 10k resistors with the ESP32 I/O pins. In this project, I am using GPIO pins 13, 12, 14, and 27. I will be using the same pins in the programming.

The neutral wire from the 110/220Vac supply is connected with the neutral of all the lights. While the Live wire from the AC supply is connected to the bulbs through these relays. and ESP32 development board

Download Gerber files

These are the PCB boards which I received from the JLCPCB as you can see the quality is really great. The silkscreen is quite clear and the Black Solder mask looks amazing. Next, I started off by placing the components and completed the soldering job. and ESP32 development board with relays

This is how my ESP32 Development board looks after soldering all the components. I will use this development board for testing all my ESP32-based projects. Now, let’s start with the

Thinger.IO Dashboard Setup for ESP32:

Login into your account and click on the Add Device. and ESP32

Then enter the device configuration and ESP32

Now, after filling all the device details, copy the Device id and open the programming which is given in the programming section below, and paste it next to the DEVICE_ID in the arduino_secrets.h.

Next, copy the Device Credentials and past it next to the DEVICE_CREDENTIAL in the programming.

The USERNAME in the arduino_secrets.h should be the same as your gmail id you used to register on the cloud platform. and ESP32

Before, you upload the program, first you will need to install the ThingerESP32 library. For this go to the Sketch menu, then to Include Library, and click on Manage Libraries. Search for the As you can see I have already installed the latest version of the and ESP32

If you are using the ESP32 WiFi module for the first time then you will also need to install the ESP32 board in the Arduino IDE, for this you can read my getting started article on the ESP32 WIFI + Bluetooth module.

After you have installed your ESP32 Board and the required library. Next, copy the arduino_secrets.h and the main code given below. Make sure you keep the arduino_secrets.h in the same folder with the main code file .ino. If you don’t get it, watch the video tutorial on my YouTube channel Electronic Clinic.


#define USERNAME "electroniclinic"
#define DEVICE_ID "nodemcu"
#define DEVICE_CREDENTIAL "electronic"

#define SSID "AndroidAP3DEC"
#define SSID_PASSWORD "electroniclinic" ESP32 Code:


#include <ThingerESP8266.h>
#include "arduino_secrets.h"


int light1=D0;
int light2=D1;
int light3=D3;
int light4=D4;
void setup() {
  // open serial for monitoring

  // set builtin led as output

  pinMode(light1, OUTPUT);
    pinMode(light2, OUTPUT);
  pinMode(light3, OUTPUT);
  pinMode(light4, OUTPUT);

  // add WiFi credentials
  thing.add_wifi(SSID, SSID_PASSWORD);

//  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["led"] << digitalPin(light1);
thing["led1"] << digitalPin(light2);
thing["led2"] << digitalPin(light3);
thing["led3"] << digitalPin(light4);

  // more details at

void loop() {


Make sure you modify the arduino_secrets.h header file as per your device settings. Anyway, after you are done with all the required things next you can upload the code. Make sure you have selected the right communication port and the correct ESP32 board before you click on the Upload button.

After the program has been successfully uploaded, now go back to and click on the Add Device. and ESP32

The online status shows that the ESP32 is connected with the Thinger io. and ESP32

Then click on the dashboard and enter the credentials and click on the add dashboard. and ESP32

Then click on the edit button and ESP32

Then click on the Add Widget button, first we will start by adding all the four switches. and ESP32

Then fill the form for the widget setting and select the on/off state which will be used to control the light or led. and ESP32

Then in the target value, select Device resource, select the ESP32 device, and in resource select the device 1. and ESP32

Now the button is added in the dashboard; in a similar way we will add other three buttons. and ESP32

Now in the similar way we will insert a gauge and ESP32

The other settings are just like the button, the only difference is in changing the sampling time which will be 1 second and click on the save button. and ESP32 and ESP32

My dashboard is ready, and now using these buttons I can control my Home appliances or other electrical loads, and using this Gauge I can monitor the Potentiometer.

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button