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

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

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 Blynk 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. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. For that, use the Circuit diagram below.

Servo motor control using ESP8266 and Blynk app

Step 3

Thirdly, let’s set up the Blynk application interface. I think you have already installed the Blynk app on your smartphone. Otherwise, please visit the “How to set up Blynk app” tutorial.

  • OK, first click the “New Project” button. After, name it as you like and select the device and connection type. Then, click the “Confirm” button.
  • Then, let’s add the widget to this interface. To do this, click on the “+” sign on the right. After, add a “slider” widget.
Servo motor control using ESP8266 and Blynk app - Step by step instructions
  • Now, click the slider widget. Then, enter the slider name as you like. After, set the 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.

/*Servo motor control with Nodemcu ESP8266.
 * This code created by the SriTu Hobby team.
 * https://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, the 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 auth token and WIFI credentials. 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 servo PIN is included.

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

Finally, select the 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. Have a good day.

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

Similar Posts

Leave a Reply

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