IoT led

Now controlling devices through internet / mobile app is easy. With the help of Blynk IoT platform and ESP-01 module. 

STEP 1 - Gather these components

  1. CP2102 USB to UART module.
  2. ESP-01 module.
  3. LED
  4. Push Switch
  5. 220ohm resistor
  6. Jumper wires (female to male) , single core breadboard wire, breadboard.

STEP 2 - Make connections as per circuit.

STEP 3 - Create Blynk account.

1. Go to Blynk website and click on "log in".


2. Click on create new account.



3. Enter your email id.



4. You will receive email by Blynk to set password.
 

5. Create a strong password

6. Click on "cancel" because we don't want a "Quickstart template".



The Blynk account is now created.

STEP 4 - Creating Blynk Template.

1. Click on the "square grid like icon" that's for template and create new template.




2. Give name to your template and Hardware - "ESP8266", connection type - Wi-Fi.



3. Under info you will get "Blynk template ID" and "Blynk template name" that we have to use in our code. 

4. Create a Blynk Datastream , we are going to use a "virtual pin", that's like a space in Blynk server to store our switch state (0 or 1) data. 


5. Give name to virtual pin, select Pin - V0, Datatype - Integer, min - "0" , max - "1", Click on create.



6. Create a web dashboard , add new widget like switch, guage, slider. We are going to use a switch widget. Drag and place the switch and go to it's settings.





7. Give name to the switch widget as switch and link Datastream V0 to our widget. eg - It's like attaching string to a puppet. 



8. Set on value as "1" and off value as "0".  ON LABEL is "ON" and OFF LABEL is "OFF". Choose colour and Click on Save.


9. Click on "save" at top left corner. This will save changes we made to our template. Our template is now created. 


STEP 5 -  Getting the Arduino IDE to upload the Blynk IoT code.

1. To add ESP boards to Arduino IDE. open Arduino IDE >> file >> preference 


2. Copy and paste below given link in additional board manager URL's
http://arduino.esp8266.com/stable/package_esp8266com_index.json



3. Go to tools >> board >> board manager



4. Search for esp8266 and install the boards.


5.  you will get a list of ESP boards in TOOLS >> board . Select the board "Generic ESP8266 Module" and set the proper com port to which ESP module is connected.
Then click on "Manage libraries".


6. Search for blynk and install the Blynk library by Volodymyr.
 

7. Now open new sketch. File >> Examples >> Blynk >>Blynk Edgent >>Edgent_ESP8266.
 

8. Replace the example code with the below given code. Many blynk header files will also open, don't close them.
*note - Copy the template name and template id and paste it at the top of the code provided by Blynk when we created the template.
code:-

#define BLYNK_TEMPLATE_ID " " // Copy and paste the template id from blynk template
#define BLYNK_TEMPLATE_NAME " " // Copy and paste the template name from blynk template

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial

#define APP_DEBUG

#include "BlynkEdgent.h"

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI

int led = 2;  //D2 on the board

BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
  Serial.println(param.asInt());

  if(param.asInt() == 1)
  {
    digitalWrite(led,HIGH);
  }
 else
  {
    digitalWrite(led,LOW);
  }
}

void setup()
{
  Serial.begin(115200);
  pinMode(led,OUTPUT);
  delay(100);
  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
}
// end of code



9.Now "save as" the code give it another name (eg - "IoT led") a new sketch will open.
Close the example code. Connect the CP2102 to the COM port. Select the board
"generic esp8266" and COM port.



If the board is connected it will show "Generic ESP8266 on COM ". This video will show
you how to upload program in ESP-01 module.


NOW CLICK ON UPLOAD.


STEP 6 - Creating Blynk device using Blynk app. Watch the below given video


 Now you can controll led from your smart phone.

If you found this blog useful and want to support me, then you can donate me. The money you give will be used to make more advance electronics projects and setting up better lab.



Comments