• Ankita Sharma

IoT Smart Bulb using NodeMCu and Blynk App


The Internet of Things ( IoT) aims towards making life simpler by automating every small task around us. A recent trend is the development of smart home IoT devices. As home automation has become very affordable, the global market for smart home automation has increased exponentially in the past few years.


Smart Bulb enables us to control the Bulb using an android phone with just one touch. It's pretty simple to make this at our home with few electrical components. In this article, we will learn How to make Smart Bulb using NodeMCU and Blynk App.


Hardware Requirements :


The required hardware components for interfacing are as follows -


NodeMCU Esp8266

NodeMCU Esp8266
NodeMCU Esp8266

#ESP8266 is a low-cost microcontroller chip that is used to interface various hardware components. It has inbuilt #WiFi and Bluetooth capabilities, making it a better candidate for IoT projects and Developments. Also, it is very cost-efficient as well as consumes less power. It allows us to use it as a micro-controller and manipulate input and output.


Buy Esp8266 from here.


USB Cable

USB Cable
USB Cable

#USB ( Universal Serial Bus ) Cable is used to connect the development boards ( NodeMCU in this case ) to the system ( For eg: Laptops ).


Buy USB Cable from here.


Jumper Wires

USB Cable
USB Cable

Jumper wires are the connecting wires that have connector pins at each end, allowing them to be used to connect the two points without soldering. They typically come in three versions - male-to-male, male-to-female, and female-to-female. Here, we will be using male-to-male jumper wires to interface the hardware components.


Buy Jumper Wires from here.


Breadboard

Breadboard
Breadboard

They are basically a construction base used for prototyping electronic circuits. #Breadboards allow us to make quick connections between hardware components, without soldering.


Buy Breadboard from here.


Relay

Relay
Relay

It is designed to interface with development boards such as NodeMCU to control high voltage and high current load. It is rated up to 10 A per channel at 30 VDC or 250VAC.


Buy the Relay module from here.


Bulb

Bulb
Bulb

A #bulb contains a filament enclosed inside glass to protect the filament from oxidation. Current is supplied to the filaments via terminal.


Buy Bulb from here.


Power Adaptor

Power Adaptor
Power Adaptor

An adaptor is used to give a power supply to the NodeMCU board.


Buy Power Adaptor from here.


Softwares :


Arduino IDE

Arduino IDE
Arduino IDE

Arduino Integrated Development Environment ( #IDE ) is open-source software that facilitates the development and uploading of codes to the microcontroller. Programs written in Arduino IDE are known as Sketch. These Sketch files are saved with the file extension ino.


Click on the link to download the software


Blynk App

Blynk App
Blynk App

#Blynk is an IoT platform that allows you to quickly build user interfaces for controlling and monitoring your hardware projects from your android phones. You can download this app from Google Play Store.


Circuit Connections :


The circuit connections are as follows -

Circuit Connections
Circuit Connections
  • The positive terminal and negative terminal of the 5V power supply are connected to the positive and negative of the breadboard respectively.

  • The positive terminal and negative terminal of the Relay Module are connected to the positive and negative of the breadboard respectively.

  • IN pin of the relay is connected to the D0 pin on the nodeMCU.

  • The positive terminal of the bulb is connected to pin D0 of the nodeMCU.


Blynk App Settings :


  1. Create an account on BlynkApp, and then log in.

  2. Go to New Project.

  3. Name your Project > Choose device as NodeMCU > Set Connection Type as WiFi. Then select Create.

  4. An authentication key will be sent to your registered Email address.

  5. Go to Widget Box, then select Button.

  6. Now, go to button settings by clicking on the Button Widget.

  7. Change the output pin to Do and then change the slider to Switch.

  8. Now, go back and click on the play button present on the top of the screen.


Installations :


The step by step instructions to install the required libraries are as follows -

  1. Click on the given-below links to download the required packages: Blynk Library ESP8266 support package

  2. Go to Code > Download ZIP.

  3. Open Arduino IDE > Sketch > Add .ZIP Library.

  4. Select the. ZIP files that you just downloaded.


Code Explanation :


The code explanation for Smart Bulb is as follows -

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

First of all, including all the necessary libraries.

char auth[] = "IzyA8DP3M7tJyAZqdypqG2WgwRI5K3Jh";
char ssid[] = "vivo 1801";
char pass[] = "harshit123";

Taking auth[ ], ssid[ ], pass[ ] as char arrays for storing authentication token( received in the mail after creating New Project on Blynk App ), WiFi username, and WiFi password respectively.

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  Blynk.syncAll();
}

The above function is used to sync the last state of the device in case of a power cut.

void loop()
{
  Blynk.run();
}

The above set of commands call Blynk.run( ) function repeatedly to establish a connection with the Blynk server.


Complete Code :


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "IzyA8DP3M7tJyAZqdypqG2WgwRI5K3Jh";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "vivo 1801";
char pass[] = "harshit123";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  Blynk.syncAll(); // For syncing the last state of your device.
}

void loop()
{
  Blynk.run();
}

Download the document given below, copy the code, and then paste it into the Arduino IDE code window.

NodeMCU
.txt
TXT • 2KB

Note :

  1. Do not forget to select NodeMCU board. ( Go to Tools > Boards menu > NodeMCU )

  2. Change the auth[ ], ssid[ ], pass[ ] as authentication token (received on mail), Wi-Fi Username and Wi-Fi password respectively.


Working :


Smart Bulb ( Unpowered Setup )
Smart Bulb ( Unpowered Setup )

Once the hardware connections are completed and the code is written, connect the NodeMCU board to the system. Now, Upload the code to the ESP8266 board.


Smart Bulb ( Powered Setup )
Smart Bulb ( Powered Setup )
Blynk App BUTTON Widget
Blynk App BUTTON Widget

You are all set! Now, Control the bulb using the BUTTON widget on BlynkApp.



Check out the video given below to get a better idea through practical implementation.


Video By - Harshit Gupta


Conclusion :


An #IoT Smart Bulb is very affordable and is no doubt an innovation with many future applications. It allows users to control the device from anywhere in the world with just one touch. You can check out some more Home Automation Projects in this section.


NodeMCU Projects :