Overview
This is a simple Industrial Automation Project using Amazon AWS IoT Core & ESP8266 WiFi Module. Earlier we learned about Getting Started with AWS IoT Core with ESP8266. We also made a Home Automation project using the ESP32 & controlled the Relays through the AWS Dashboard.
The AWS IoT Core is a managed cloud service that lets connected devices easily and securely interact with cloud applications and other devices. The AWS IoT Core MQTT messaging service lets you send and receive MQTT messages to and from AWS IoT Core. Using the Publish/Subscribe feature we can basically receive or send any data to & the AWS IoT Core dashboard.
This tutorial is all about Controlling Peripherals like AC Appliances like bulbs via Relay from AWS IoT Dashboard using ESP8266 WiFi Module. We would basically call it an Industrial Automation Project. Industrial Automation in IoT refers to the use of interconnected devices and software to monitor and control industrial operations, such as manufacturing and energy management, enhancing efficiency and reducing human intervention. Here we used AWS IoT Core because it’s used in many industries and for commercial applications.
Bill of Materials
For this project, we will need the following components. The component list, footprint, and quantity are given below.
| S.N. | Component | Designator | Footprint | Quantity |
|---|---|---|---|---|
| 1 | Capacitor 100nf | C1, C3, C5, C7, C8, C9, C10, C11 | C0805 | 8 |
| 2 | Capacitor 10uf | C2, C4, C6 | C0805 | 3 |
| 3 | Capacitor Electrolytic 100uf/25v | C12 | CAPPRD250W52D630H1250 | 1 |
| 4 | Capacitor Electrolytic 47uf/25v | C13 | CAPPRD200W55D500H1200 | 1 |
| 5 | Didoe 1N4007 SMD | D1, D2, D3, D4 | DIOM5027X262N | 4 |
| 6 | Optocoupler IC PC817 | IC1, IC3, IC4, IC5 | DIP762W60P254L458H450Q4N | 4 |
| 7 | ESP-12E WiFi Module | IC2 | ESP8266-12E | 1 |
| 8 | Terminal Block (1x2) | J1 | 1935776 | 1 |
| 9 | Terminal Block (1x3) | J2, J3, J4, J5 | 1985894 | 4 |
| 10 | Relay SRA-05VDC | K1, K2, K3, K4 | SRA-05VDC-CL | 4 |
| 11 | LED Red | LED1, LED2, LED3, LED4, LED5 | LED0805 | 5 |
| 12 | PROG (1x6 Header) | P1 | HDR1X6 | 1 |
| 13 | HLK-10M05 AC-DC 5V | PS1 | HLK10M05 | 1 |
| 14 | Transistor BC847 SMD | Q1, Q2, Q3, Q4, Q5, Q6 | BC847B | 6 |
| 15 | Resistor 220R | R1, R3, R9, R11, R14, R16, R17, R19 | R0805 | 8 |
| 16 | Resistor DNP | R2, R10, R15, R18 | R0805 | 4 |
| 17 | Resistor 12K | R4, R5, R6, R7, R8, R12, R13 | R0805 | 7 |
| 18 | Resistor 10K | R20, R21, R22, R23 | R0805 | 4 |
| 19 | Resistor 1k | R24, R25, R26, R27, R28 | R0805 | 5 |
| 20 | Push Button Switch | S1, S2, S3, S4, S5 | B3W-1020 | 5 |
| 21 | HT7333 3.3V LDO | U1 | IC_HT7333 | 1 |
Circuit Diagram & Hardware Design
Let us take a look at the Schematic of Industrial Automation with Amazon AWS IoT Core & ESP8266. The schematic is drawn using the Altium Designer Software.
We used SMD resistors, capacitors, and LED with the 0805 package. To convert 220V AC to 5V DC, we used an AC-to-DC Converter from Hi-Link. For providing power to ESP8266 raw chip and other peripherals, a low-power LDO HT7333 IC was used. To separate the high-power line from the 3.3V circuit PC817 optocoupler IC is used. The LED5 in the circuit is used to indicate power.
Similarly the LED1, LED2, LED3 & LED4 is used to represent Relay1, Relay2, Relay3 & Relay4 output respectively. The 4 Relays are connected to ESP8266 via GPIO16, GPIO14, GPIO12, GPIO10. A Reset button when pressed resets the ESP8266 Chip. The push buttons SW1, SW2, SW3, and SW4 are used in the manual controlling of Relays. They are connected to GPIO5, GPIO4, GPIO2 & GPIO13. You may attach a manual switch there and program the controller to control the circuit.
To program the ESP8266 Board, the Prog pin is provided. We can connect an FTDI Module to program the ESP8266 Chip directly. Two large value capacitors C12 (100uF) and C13 (47uF) are added to control voltage fluctuations.
Project PCB Gerber File & PCB Ordering Online
We have designed the PCB using the Altium Designer Software. It took quite a lot of time fixing all the isses in the PCB but still we managed to design a complete working custom PCB. The PCB design looks like this.
Here is the 3D View of the PCB from the front side as well as from the backside.


The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.
You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
PCB & Hardware Assembly
After ordering the PCB, it took almost 5 days and I got my PCB.
The PCB quality from ALLPCB is superb with very high quality. That is why most people trust ALLPCB for PCB/PCBA Services.
First solder all the SMD components like resistors, capacitors, transistors, LEDs, voltage regulators & diodes. Be careful about the SMD LED polarity, place it in the proper direction. The SMD soldering is to be done on the both sides.
After soldering all these, you can solder the ESP8266 raw chip. The final stage would be soldering all the through-hole components like Optocoupler IC, terminal block, Relays, male-female headers, and AC-to-DC Converter Module.
After soldering all the components, the ESP8266 Industrial Automation Board is ready for the test. You can upload a blink sketch by connecting a USB-to-TTL Converter Module.
Note: There were some voltage fluctuation issues in the designed PCB, so I have updated the design by adding some large capacitors. Also, some connection issues have been fixed. The Gerber file above is updated and the PCB would be little different from shown above. But overall the functionality is same.
Setting up Amazon AWS IoT Core Dashboard
The signing up part for the Amazon Web Services is already explained in the previous post. You can follow the AWS IoT Core Getting Started tutorial.
After successfully signing in, the AWS Management Console window will open. In the services search tab at the top right ‘IoT core’ & hit enter.
You can click on IoT Core, so an AWS IoT Dashboard will appear now.
On the left side of the dashboard, there are so many options. But we need to work with two options here. One is the manage option and the other one is the secure option.
Creating a Thing
Now we need to create a thing associated with our project. For this, follow the following steps:
- Specifying thing properties
- Configuring device certificate
- Attaching policies to certificate
Under the manage option click on Thing. Now we need to create a Thing here. So, click on Create Things here.
You can select whether create a single thing or create many things. But for our applications, select create a single thing. Then click on Next.
Specify Thing Properties
Here we need to specify the Thing properties. First, give a thing name. You can name it anything. For example, I will name it Home_Automation.
Under additional configurations, there is no need to make any changes.
Under the device shadow option, select the first option as No shadow. Then click on Next.
Generate Device Certificate
Now you need to configure device certificate. So here you can auto-generate a new certificate or use your own certificate or upload CSR or skip this.
But the AWS recommendation is to select the Auto Generate New Certificate. Then click on Next.
Create & Attach Policy
Now we need to attach a policy to the Things we created. But no policies are here right now. So we need to create a policy first.
So click on create policy. Here give any name to the policy. For example, I will give it a name as “Automation_Policy“.
Now the add statement part is very important. Under the action, type IoT. So multiple options will pop up. From here we will only need to Subscribe, Connect and Receive.
Now click on create to create the policy. So the policy has been created successfully.
Now go back to Create Thing option. So a policy option will appear. We need to attach the policies to the certificate. So select the appeared policy and click on create a thing.
Downloading Certificates and Keys
Now we need to download the required certificates from this list.
First, download the device certificate and then rename it as a device certificate for identification.
Also, download the public key and rename it as a public key. Then download the private key and rename it as a private key.
In the Root CA Certificates, there are two certificates here. But we just need a Root CA1 certificate, so download it as well.
So we have downloaded all the certificates that we need for our project. Finally the dashboard setup is complete and we can move to the programming part for the project Industrial Automation with Amazon AWS IoT Core & ESP8266.
Source Code/Program
The Source Code/Program for the project “Industrial Automation with Amazon AWS IoT Core & ESP8266” is written in Arduino IDE. Before moving to the code part, we need to install few libraries to the Arduino IDE. Download the following libraries and add it to the Arduino IDE library folder,
1. Arduino JSON Library: https://github.com/bblanchon/ArduinoJson
2. PubSubClient Library: https://github.com/knolleary/pubsubclient
The code is divided into two sections. One is the main file and the other is the header file.
Main.ino
Open a new sketch in Arduino IDE & paste the following code and save it.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
#include <ESP8266WiFi.h> #include <WiFiClientSecure.h> #include <PubSubClient.h> #include <ArduinoJson.h> #include <time.h> #include "secrets.h" #define TIME_ZONE -5 #define RELAY1 16 // change these pins according to your setup #define RELAY2 14 #define RELAY3 12 #define RELAY4 10 unsigned long lastMillis = 0; unsigned long previousMillis = 0; const long interval = 5000; #define AWS_IOT_SUBSCRIBE_TOPIC "esp8266/sub" WiFiClientSecure net; BearSSL::X509List cert(cacert); BearSSL::X509List client_crt(client_cert); BearSSL::PrivateKey key(privkey); PubSubClient client(net); time_t now; time_t nowish = 1510592825; void NTPConnect(void) { Serial.print("Setting time using SNTP"); configTime(TIME_ZONE * 3600, 0 * 3600, "pool.ntp.org", "time.nist.gov"); now = time(nullptr); while (now < nowish) { delay(500); Serial.print("."); now = time(nullptr); } Serial.println("done!"); struct tm timeinfo; gmtime_r(&now, &timeinfo); Serial.print("Current time: "); Serial.print(asctime(&timeinfo)); } void messageReceived(char *topic, byte *payload, unsigned int length) { Serial.print("Received ["); Serial.print(topic); Serial.print("]: "); String received_msg = ""; for (int i = 0; i < length; i++) { received_msg += (char)payload[i]; // Append the payload into string Serial.print((char)payload[i]); } Serial.println(); // Check if the received message is "ON" or "OFF" to control the LEDs if (received_msg == "ON1") { digitalWrite(RELAY1, HIGH); // Turn on the RELAY1 Serial.println("RELAY1 turned on"); } else if (received_msg == "OFF1") { digitalWrite(RELAY1, LOW); // Turn off the RELAY1 Serial.println("RELAY1 turned off"); } else if (received_msg == "ON2") { digitalWrite(RELAY2, HIGH); // Turn on the RELAY2 Serial.println("RELAY2 turned on"); } else if (received_msg == "OFF2") { digitalWrite(RELAY2, LOW); // Turn off the RELAY2 Serial.println("RELAY2 turned off"); } else if (received_msg == "ON3") { digitalWrite(RELAY3, HIGH); // Turn on the RELAY3 Serial.println("RELAY3 turned on"); } else if (received_msg == "OFF3") { digitalWrite(RELAY3, LOW); // Turn off the RELAY3 Serial.println("RELAY3 turned off"); } else if (received_msg == "ON4") { digitalWrite(RELAY4, HIGH); // Turn on the RELAY4 Serial.println("RELAY4 turned on"); } else if (received_msg == "OFF4") { digitalWrite(RELAY4, LOW); // Turn off the RELAY4 Serial.println("RELAY4 turned off"); } } void connectAWS() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.println(String("Attempting to connect to SSID: ") + String(WIFI_SSID)); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(1000); } Serial.println(); Serial.println("WiFI Connected"); delay(1000); NTPConnect(); net.setTrustAnchors(&cert); net.setClientRSACert(&client_crt, &key); client.setServer(AWS_IOT_ENDPOINT, 8883); client.setCallback(messageReceived); Serial.println("Connecting to AWS IOT"); while (!client.connect(THINGNAME)) { Serial.print("."); delay(1000); } if (!client.connected()) { Serial.println("AWS IoT Timeout!"); return; } // Subscribe to a topic client.subscribe(AWS_IOT_SUBSCRIBE_TOPIC); Serial.println("AWS IoT Connected!"); } void setup() { Serial.begin(115200); pinMode(RELAY1, OUTPUT); // set the RELAY pins as output pinMode(RELAY2, OUTPUT); pinMode(RELAY3, OUTPUT); pinMode(RELAY4, OUTPUT); digitalWrite(RELAY1, LOW); digitalWrite(RELAY2, LOW); digitalWrite(RELAY3, LOW); digitalWrite(RELAY4, LOW); delay(3000); connectAWS(); } void loop() { now = time(nullptr); if (!client.connected()) { connectAWS(); } else { client.loop(); if (millis() - lastMillis > 5000) { lastMillis = millis(); } } } |
Secrets.h
Open a New Tab in Arduino IDE and name it as Secrets.h. And paste the following code to this file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <pgmspace.h> #define SECRET #define THINGNAME "**************" //change this const char WIFI_SSID[] = "**************"; //change this const char WIFI_PASSWORD[] = "**************"; //change this const char AWS_IOT_ENDPOINT[] = "**************"; //change this // Amazon Root CA 1 static const char cacert[] PROGMEM = R"EOF( -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- )EOF"; // Device Certificate //change this static const char client_cert[] PROGMEM = R"KEY( -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- )KEY"; // Device Private Key //change this static const char privkey[] PROGMEM = R"KEY( -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- )KEY"; |
Modifying Arduino Sketch according to the Thing
Now it’s time to modify the Arduino Sketch File. Go to secrets.h tab and begin the modification.
Here we need to include a thing name. You can go to the things section of AWS Console and copy the thing name. The Things name in this project is Home_Automation. Paste the thing name to the following line of code.
|
1 |
#define THINGNAME "***************" |
Under the WiFi SSID and password, enter the WiFi SSID and Password of your local network.
|
1 2 |
const char WIFI_SSID[] = "***************"; const char WIFI_PASSWORD[] = "***************"; |
Now, we need to insert the AWS IoT Endpoint here. To get the endpoint, go to the settings part of AWS Dashboard. Yow will get the endpoint.
Click on the copy icon to copy the endpoint. Go back to Arduino IDE and paste it on the following line.
|
1 |
const char AWS_IOT_ENDPOINT[] = "***************"; |
You need to insert the Amazon Root CA1 in between the following line.
|
1 2 3 4 5 6 |
// Amazon Root CA 1 static const char AWS_CERT_CA[] PROGMEM = R"EOF( -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- )EOF"; |
So for this, we need to go back to the certificate that we downloaded earlier. Open this file with Notepad++ and copy all the text.
Then go back to Arduino IDE and insert the copied text between begin certificate and the end certificate.
Under the “Device Certificate” lines, we need to paste the device certificate text. So open the device certificate file that we downloaded earlier. And again copy the text and paste it between the begin certificate and end certificate section.
|
1 2 3 4 5 |
// Device Certificate static const char AWS_CERT_CRT[] PROGMEM = R"KEY( -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- |
Under the “Device Private Key“, we need to insert the device’s private key. So go to the downloaded folder again and open the device’s private key file using Notepad++. Again copy the text and paste it between begin & end parts.
|
1 2 3 4 5 |
// Device Private Key static const char AWS_CERT_PRIVATE[] PROGMEM = R"KEY( -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- |
So all the modification of the Arduino Sketch for Industrial Automation with Amazon AWS IoT Core & ESP8266 is done now.
Industrial Automation with Amazon AWS IoT Core & ESP8266
Once all the modification is done, its time to progam the ESP8266 Raw Chip. To do that, connect the FTDI Module to your PROG Pin of PCB.
Then go to the tools & select ESP8266 Generic Module that you are using for this project. Also, select the COM port. Then click on the upload option to upload the code to the ESP8266 board.
Note: While uploading the code disconnect the relay from the power source.
Once the code uploading is done, open the Serial Monitor. The ESP8266 will try connecting to the WiFi Network. Once it gets connected to the WiFi Network, it will try connecting to the AWS IoT Server. The Serial Monitor will show this message once the connection with AWS Dashboard is established.
Now we need to check whether we are able to publish a topic to control all the home appliances.
To do that, you need to publish a topic. For that type “esp8266/sub“ under the topic filter section. Under Message Payload type the following command a command to turn ON/OFF the Relay respectively.
Type ON1, ON2, ON3, ON4 to turn ON Relay1, Relay2, Relay3, Relay4. Similarly type OFF1, OFF2, OFF3, OFF4 to turn OFF Relay1, Relay2, Relay3, Relay4 repectively.
Under additional configuration do nothing. Then click on publish. Immediately you can see the message sent to the Serial Monitor.
At this moment the Relay1 will turn ON immediately. And any appliances connected to the Relay1 will turn ON.
Now to turn OFF the Relay1, send OFF1 from the publish window of AWS Dashboard. The Relay should turn OFF immediately.
You can send other commands as well for testing the ON/OFF functionality.
This is how you can control any industrial appliances with Amazon AWS IoT Core using ESP2866 WiFi Module & make your own Industrial Automation project.
Video Tutorial & Guide
Conclusion
In conclusion, this tutorial has taken us through the process of creating an Industrial Automation Project using Amazon AWS IoT Core and the ESP8266 WiFi Module. We explored the basics of the AWS IoT Core service, including its MQTT messaging service, and the Publish/Subscribe feature, which enables the transmission and reception of data to and from the AWS IoT Core dashboard. We specifically focused on using this technology to control AC appliances such as bulbs via relay from the AWS IoT Dashboard, providing a practical application of Industrial Automation in IoT.
Industrial Automation essentially leverages interconnected devices and software to oversee and control industrial processes, augmenting efficiency and lessening human involvement. We adopted AWS IoT Core for this project due to its widespread use across numerous industries and its versatility in commercial applications. This tutorial is a stepping stone towards further exploration of IoT solutions for industrial automation and beyond.





































