In this tutorial, you will learn how to control a servo motor using the Blynk app on an IoT platform.

Hardware Requirements

  1. NodeMCU
  2. Servo
  3. Connection Wires

Software Requirements

  1. Arduino IDE
  2. Blynk App

This tutorial is divided into four parts:

Part 1: NodeMCU Initialization with WiFi Name and Password


#include <ESP8266WiFi.h> char ssid[] = "Your_WIFI_Name"; char pass[] = "Your_Password";

Explanation: This code includes the WiFi library and sets the WiFi name and password for internet connection.

Part 2: Blynk App Setup


#include <BlynkSimpleEsp8266.h> #define BLYNK_PRINT Serial char auth[] = "Your_Auth_Key";

Explanation: This code includes the Blynk library and sets the authentication key received from your email after setting up the Blynk app.

Part 3: Servo Operation


#include <Servo.h> Servo servo1; #define servo1Pin D2 void setup() { servo1.attach(servo1Pin); } void loop() { int PotReading = analogRead(A0); int servo1Angle = map(PotReading, 0, 1023, 0, 180); servo1.write(servo1Angle); delay(15); }

Explanation: This code includes the Servo library, creates a Servo object named "servo1", and defines the NodeMCU pin to attach the Servo. The map() function maps the analog reading (0 to 1023) to the servo angle (0 to 180 degrees).

Part 4: Creating a Blynk App to Control the Servo

Steps:

  1. Open the Blynk app and create a new project.
  2. Select NodeMCU as your hardware model.
  3. Add a slider widget to control the servo.
  4. Set the range of the slider from 0 to 180.
  5. Link the slider to a virtual pin (e.g., V1).
  6. Use the following code to update the servo position based on the slider value:

BLYNK_WRITE(V1) { int servoValue = param.asInt(); servo1.write(servoValue); } void setup() { Serial.begin(9600); Blynk.begin(auth, ssid, pass); servo1.attach(servo1Pin); } void loop() { Blynk.run(); }

Explanation: This code reads the slider value from the Blynk app and updates the servo position accordingly.

NodeMCU to Servo Connection

Schematic:

  • Connect the VCC of the servo to the 3.3V pin on the NodeMCU.
  • Connect the GND of the servo to the GND pin on the NodeMCU.
  • Connect the signal pin of the servo to D2 on the NodeMCU.
Nodemcu to Servo connection 
nodemcu to servo schematic

Download Code

Click Here to Download the Code

More Projects

  1. Introduction to NodeMCU8266 & Steps to Import ESP Board Libraries
  2. NodeMCU8266 Basic Project - Blink an LED
  3. NodeMCU8266 Digital Read (Push Button)
  4. Analog Data Read Using NodeMCU8266
  5. NodeMCU LED Control Using Blynk App in IoT Platform
  6. NodeMCU to DHT Interface in Blynk App | On IoT Platform
  7. The Best Way to NodeMCU GPS Tracker Blynk App | in IoT Platform
  8. NodeMCU RGB LED | For Beginners

This tutorial provides a step-by-step guide to control a servo motor using the Blynk app on an IoT platform, making it easy to integrate hardware and software for your IoT projects.









in the final step










No comments

Theme images by Dizzo. Powered by Blogger.