Servo motor control using ESP8266 and Blynk app – Step by step instructions

 Servo motor control using ESP8266 Blynk

            Hello, welcome back. This tutorial is based on IoT and covers how to control a servo motor using ESP8266 and the Blynk app. Nodemcu ESP8266 board and Blynk application are mainly used for this tutorial. Also, the servo motor can be considered an essential component in robot design. So I hope the knowledge in this tutorial will be useful for your creations. Also, the knowledge gained in this project will be of great help to us in our future projects.

The process of this tutorial

When the Nodemcu board is powered on, the Nodemcu board connects to the blink cloud via WIFI. Then the Nodemcu board connects with the Blynk app. So, we can rotate the servo motor through the interface we have created.
OK, let’s do this project step by step. To do this, the required components are given below.

Step 1

Firstly, identify these components.

Nodemcu ESP8266 board

Servo motor

Jumper wires

Breadboard

Step 2

Secondly, connect these components. For that, use the Circuit diagram below.
Servo motor control using ESP8266 and Blynk app

Step 3

Thirdly, we set up the Blink application interface. I think you already have the Blink app installed on your smartphone. Otherwise, please visit the “How to set up Blink app” tutorial.
  • OK, first click the “New Project” button. After, enter as you like name and select the device and connection type. Then, click the “Confirm” button.
Servo motor control using ESP8266 and Blynk app
Servo motor control using ESP8266 and Blynk app
  • Then, we add the widget to this interface. To do this, click on the “+” sign on the right. After, add a “slider” widget.
  • Now, click the slider widget. Then, enter the slider name as you like. After, set PIN as “virtual V0” and set the value 0 – 180. Lastly, customize the slider widget to your liking.

Step 4

OK, the app interface is ready. Now, let’s create the program for this project. It is as follows.
First, download and install the libraries below.
WIFI library — Download
Blynk app library — Download
/*Servo motor control with Nodemcu ESP8266.
 * This code created by the SriTu Hobby team.
 * https://www.srituhobby.com
 */
 
#include <Servo.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Servo servo;
char auth[] = ”  “;//Enter your Blynk auth token
char ssid[] = ”  “;//Enter your WIFI name
char pass[] = ”  “;//Enter your WIFI password
 
BLYNK_WRITE(V0){
  servo.write(param.asInt());
}
void setup() {
  Serial.begin(9600);
  servo.attach(D1);
  Blynk.begin(auth, ssid, pass);
}
 
void loop() {
  Blynk.run();
}
 

Code explanation

First, WIFI, Blynk, and servo libraries are included. Afterward, the servo object was created as “servo”.
#include <Servo.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Servo servo;
 
Secondly, we need to enter the Blynk code and WIFI connection information. Use your information for that.
char auth[] = ”  “;//Enter your Blynk auth token
char ssid[] = ”  “;//Enter your WIFI name
char pass[] = ”  “;//Enter your WIFI password
 
This code gets values from the Blynk app and rotates the servo motor using these values.
BLYNK_WRITE(V0){
  servo.write(param.asInt());
}
 
In the setup function, begins the Blynk library and serial monitor. Also, the PIN number connected with the servo motor is attached to the servo library.
void setup() {
  Serial.begin(9600);
  servo.attach(D1);
  Blynk.begin(auth, ssid, pass);
}
 
In the loop function, the Blink library is activated.
void loop() {
  Blynk.run();
}
 

Step 5

Lastly, select board and port, Afterward, upload this code to the Nodemcu board and run your Blynk app interface that we prepared earlier.
OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

Leave a Reply

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