top of page

Controlling Ceiling Light using NodeMCu, AWS, and Relay | IoT Project

Updated: Mar 17

IoT based Home Automation enables to control of home appliances by using the internet. This technology allows us to control or monitor any devices at any place with our fingertip. It assures energy conservation and optimized use of money and energy.

In this article, let us learn to design a simple home automation system for controlling ceiling lights by using NodeMCU, AWS, and Relay module. Let's first start with the requirements that we will need to design the IoT project.

Hardware Requirements:

1. Breadboard


A breadboard is an essential component that is in a rectangular shape with small holes in it that are used to insert the components to test the circuits. The connections are not fixed and can be varied. In a breadboard, the holes in one horizontal line are in series connection with each other. Breadboards are made from plastic or wood and come in all shapes, sizes, and even different colors, the most commonly used sizes for designing the circuits are "full-size," "half-size," and "mini" breadboards.

Buy the Breadboard from here.

2. Node MCU ESP 8266

Node MCU ESP 8266
NodeMCU ESP8266

NodeMCU is an inexpensive, open-source hardware #development board. It best suits for building the Internet of Things (IoT) projects. It has an operating voltage of 3.3Volt. It consists of 4-power pins, 4 -ground pins, I2C pins, 17-GPIO pins, UART pins, SPI pins, SDIO pins, PWM pins, and Control pins. NodeMCU uses an IDE environment to upload programs to the board by creating an Arduino add-on.

Buy NodeMCU ESP8266 from here.

3. Relay Module

Relay Module
Relay Module

In this project, a single-channel #relay module is used. The relay module is an electromagnetically operating switch. It consists of three voltage terminals in which the controlling device is connected. The pins are Normally closed (NC), Normally Open (NO), and Common terminal. And on another side, has 3 terminals it is connected to the controller board. The Three pins are the Ground pin (Gnd), Supply pin (Vcc), and the Input pin (IN).

Buy Relay Module from here.

4. Jumper Wires

Jumper Wires
Jumper Wires

These are the main components that are used to establish the connections between different devices of the circuit. There are three types male to female, female to female, and male to male.

Buy Jumper Wires from here.

5. USB Cable

USB Cable
USB Cable

This cable is used to connect the development boards to the power supply. It also helps in the transmission of data.

Buy USB Cable from here.

Software Requirements:

1. Arduino IDE

Arduino IDE LOGO
Arduino IDE LOGO

Arduino #IDE (Integrated Development Platform) which is used to interface the boards like NodeMCU to run the desired code designed to interface hardware devices.

2. Amazon Web Service (AWS)

Amazon Web Service (AWS) LOGO
Amazon Web Service (AWS) LOGO

Amazon Web Services is an inexpensive, reliable cloud service platform that allows the creation of #IoT projects. It is a flexible platform to store, compute, and secure the data.

3. OpenSSL:


OpenSSL tool is an open-source software used to provide a secure network connection. It is a command-line tool that generates certificates, private keys, or changes the file format.

Hardware Implementation:

Circuit Connection:

The connection between the NodeMCU and the Relay Module by using jumper wires involves the following steps:

  • The Supply pin (Vcc) is connected to the 5V of the Relay module which is further connected to the Vin terminal of the NodeMCU using a Red jumper wire.

  • The Input pin (IN) is connected to the digital pin 5 of the NodeMCU using a Yellow jumper wire.

  • Finally, the ground pin (GND) is connected to the ground terminal of the NodeMCU board.

After connecting #NodeMCU with the relay, connect the ceiling light with AC load to the Normally open and the common pin of the relay module.

Software Implementation:

In the software part first, open the AWS website by clicking the AWS Management Console link to create your account. It will charge a minimum amount to create the AWS account. In #AWS it includes three to four processes to control the light. They are Generation of Certificates, Creation of policy, and Attachment of policy to the Certificates. Let us understand these processes in detail.

Generation of Certificates:

  • On creating the account set the service to 'IoT Core' and click the manage icon ---> Thing option to create a new thing.

  • Now add the device that we are going to use to the Thing registry and create the certificate.

  • Download the Certificate and also the private key and CA certificate.

Creation of policy:

  • To create a policy, Click on the Secure icon ---> Policy option.

  • Enter New Name and add the action and Resource ARN has '*' to all the IoT resources.

  • Allow the Effect Option.

  • Click the Create icon to create the policy.

Attachment of policy to the Certificates:

  • Go to the Certificate page that we created and click on the three-dotted icon ---> Attach Policy.

  • Select the policy that we created and the policy gets attached.

The downloaded Certificates are in PEM format. Hence the NodeMCU understands only the DER format, now convert it into DER format. For this conversion, the OpenSSL tool is used.

To open OpenSSL click the Command prompt in the Desktop or use this link to download the OpenSSL tool.

After Downloading, Open the tool and copy-paste the following Commands:

openssl x509 -in xxxxxxx-certificate.crt -out cert.der -outform DER 
openssl rsa -in xxxxxxx-private.pem.key -out private.der -outform DER
openssl x509 -in AmazonRootCA1.pem -out ca.der -outform DER

Download the following file for the Complete Command.


Before copy-pasting, the commands remove the xxxxxxx and replace it with the certificate names that we downloaded from the AWS. Now run the commands individually the format of the certificates is changed from PEM to DER and stored in the directory.

The Next step is to upload these files in the file system of NodeMCU. For this store the certificates and the code for the esp8266 in a single folder. Then Open the Arduino IDE now go to Tool and search for "ESP8266 Sketch Data Upload" if the tool is not available download the tool from the given ESP8266 Sketch Data Upload link. Download the tool and extract it and store it in the same folder in which the certificates and esp8266 coding are stored.

Now open the #ESP8266 Sketch Data Upload and upload the certificates to the file system of the NodeMCU. Then copy-paste the esp8266 coding in the #Arduino IDE. Before compiling the program select the required specifications for the NodeMCU board and enter the endpoint value in the code. To get the endpoint value go to the AWS account setting option and copy-paste the endpoint in the code.

Note: Please change the file extension to .ino(Arduino IDE) file format before you upload the code to the Arduino board.


On uploading the program to the NodeMCU, go to the AWS account and click the test option to test the working of the hardware. In the Publish section specify the topic and type the message "Device_1_LED" = "1 or 0". The 1 command will enable the #LED to glow and 0-command will switch off the LED.

The below image shows the picture of the circuit when the code is not applied.

Connection, Before Uploading the program
Connection, Before Uploading the program

After Uploading the code and passing the required command the light starts glowing.

Connection, After Uploading the program
Connection, After Uploading the program

A detailed explanation of the hardware and software implementation, coding part, and the working are explained clearly in the given video.

Video By - Harshit Gupta

Further, this #automation technology can also be demonstrated to control other appliances like fans, door, AC, etc by using mobile phones or computers for any large places like hospitals, industries, institutions, etc.



Check the other IoT based automation projects listed below:

Related Posts

See All


Informative and concise! LearnElectronics India always delivers quality content.


Anushka Gupta
Anushka Gupta
Jul 24, 2023

This blog is a fantastic source for those looking to dive into the world of IoT and home automation. The blend of theory and practical implementation helps readers grasp the project's core concepts and replicate it with ease. Learn Electronics India has undoubtedly sparked my interest in exploring more IoT projects. Thank you for sharing this invaluable piece.

bottom of page