how to control servo using blynk App

 how to control servo using blynk App




Here's a step-by-step guide on how to control a servo motor using the Blynk app with an IoT setup. This tutorial will cover the hardware and software components needed to make it work.

Components Required:

  1. Arduino Board (e.g., Arduino Uno or any compatible board)
  2. Servo Motor (e.g., SG90 or any other small servo)
  3. Jumper Wires
  4. Breadboard (optional)
  5. Wi-Fi Module (e.g., ESP8266 or ESP32) or Ethernet Shield (for internet connectivity)
  6. Smartphone with Blynk App installed (available on Android/iOS)
  7. Blynk Account (Sign up if you don't have one)

Step 1: Set Up the Hardware

  1. Connect the Servo Motor to Arduino:

    • Connect the PWM pin of the servo motor (usually the Yellow or Orange wire) to a digital pin on the Arduino (e.g., D9).
    • Connect the VCC pin (usually Red) to 5V on Arduino.
    • Connect the GND pin (usually Brown or Black) to the GND of Arduino.
  2. Connect the Wi-Fi Module (e.g., ESP8266/ESP32):

    • For ESP8266:
      • Connect VCC to 3.3V (or 5V, depending on your module).
      • Connect GND to GND.
      • Connect TX of ESP8266 to RX on Arduino and RX of ESP8266 to TX on Arduino.
    • Make sure you’re using the correct serial pins and communication settings based on the module.

Step 2: Set Up the Blynk App

  1. Create a New Project in Blynk:

    • Open the Blynk app on your smartphone.
    • Create a new project and choose your board (e.g., Arduino Uno, ESP8266).
    • Select the Connection Type (Wi-Fi for ESP8266/ESP32).
    • Blynk will send an Auth Token to your email. Keep this token safe as it will be used in your code.
  2. Add a Widget:

    • In the Blynk app, drag and drop a Slider widget onto the canvas.
    • Set the Slider Range to 0-180 (for the servo motor movement range).
    • Assign the slider to a virtual pin (e.g., V1).

Step 3: Arduino Code

Here’s the Arduino code to control the servo motor via the Blynk app:


//////////////////////////////////////////////////////////////////////////

 //Servo Motor Control With Blynk

#define BLYNK_TEMPLATE_ID "..............."
#define BLYNK_TEMPLATE_NAME "................."
#define BLYNK_AUTH_TOKEN "..................."


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

#include<Servo.h>
Servo servo1, servo2;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "..................";
char pass[] = "..................";

BLYNK_WRITE(V0)
{
  int s0 = param.asInt();
  servo1.write(s0);
  Blynk.virtualWrite(V2, s0);
}

BLYNK_WRITE(V1)
{
  int s1 = param.asInt();
  servo2.write(s1);
  Blynk.virtualWrite(V3, s1);
}


void setup()
{
  Serial.begin(9600);
  servo1.attach(D2); //Connect to Pin D2 in NodeMCU
  servo2.attach(D3); //Connect to Pin D3 in NodeMCU
  Blynk.begin(auth, ssid, pass);//Splash screen delay
  delay(2000);
}

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

///////////////////////////////////////////////////////////////////////


Step 4: Upload the Code

  1. Install Necessary Libraries:

    • Install the Servo library (for controlling the servo motor).
    • Install the Blynk library for your board (e.g., BlynkSimpleEsp8266 for ESP8266 or BlynkSimpleEsp32 for ESP32).
    • Install the ESP8266/ESP32 board library through Arduino IDE’s Board Manager.
  2. Upload Code:

    • Select your Arduino board and the correct COM port in the Arduino IDE.
    • Upload the code to your Arduino (or ESP8266/ESP32).

Step 5: Testing the Servo Motor

  1. Open the Blynk app and run your project.
  2. Move the slider on the app to control the servo motor. The servo should rotate based on the slider value, from 0° to 180° (or whatever range you set).

Troubleshooting Tips:

  • Ensure your Wi-Fi credentials and Auth Token are correct.
  • Check your servo's power requirements; some servos may need a separate power supply if they draw too much current.
  • If using the ESP8266, ensure it’s properly connected and compatible with your Arduino.

Conclusion

You’ve now successfully set up an IoT project using the Blynk app to control a servo motor via your smartphone. You can expand this project by adding more controls, sensors, or automating movements based on other inputs.

No comments:

Post a Comment

Wifi Home automation Diy kit

 Wifi Home automation Diy kit By Manmohan Pal Wifi Home Automation Kit Hi, This is Manmohan Pal, I am glad to present a DIY kit for Home Aut...