Need help to replace 4 potentiometer by a nodemcu to control it by using blynk to control 4servos

i am actually trying to make a robotic hand using 4 or 5 servos . and i had found a code from the channel drone bot workshop written by dave to control 4 servos using 4 potentiometers.i just thought that if i could replace the 4 potentiometres by a nodemcu i can control the robotic hand using blynk.if some one could please also uses pca9685 servo driver
this is the code

  PCA9685 PWM Servo Driver Example
  Demonstrates use of 16 channel I2C PWM driver board with 4 servo motors
  Uses Adafruit PWM library
  Uses 4 potentiometers for input

  DroneBot Workshop 2018

// Include Wire Library for I2C Communications
#include <Wire.h>

// Include Adafruit PWM Library
#include <Adafruit_PWMServoDriver.h>

#define MIN_PULSE_WIDTH       650
#define MAX_PULSE_WIDTH       2350
#define FREQUENCY             50

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// Define Potentiometer Inputs

int controlA = A0;
int controlB = A1;
int controlC = A2;
int controlD = A3;

// Define Motor Outputs on PCA9685 board

int motorA = 0;
int motorB = 4;
int motorC = 8;
int motorD = 12;

void setup() 

void moveMotor(int controlIn, int motorOut)
  int pulse_wide, pulse_width, potVal;
  // Read values from potentiometer
  potVal = analogRead(controlIn);
  // Convert to pulse width
  pulse_wide = map(potVal, 0, 1023, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
  pulse_width = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
  //Control Motor
  pwm.setPWM(motorOut, 0, pulse_width);


void loop() {

  //Control Motor A
  moveMotor(controlA, motorA);
  //Control Motor B
  moveMotor(controlB, motorB);
  //Control Motor C
  moveMotor(controlC, motorC);
  //Control Motor D
  moveMotor(controlD, motorD);


please anybody help. pete are you there

What you need to understand is that this forum is not a code factory. Even if it were, you’d need someone with the same hardware to be able to test and debug the code to ensure that it works. The chances of that happening are very slim.
So, it’s down to you to develop the code and test it.

A few pointers…

  1. Blynk doesn’t like to have lots of code running in the void loop, like in your example.So, instead you’d call the appropriate moveMotor commands when they are triggered by an input from Blynk.

  2. This bit of code is about taking the analogue readings and making them into digital values. You don’t need to do that, the Blynk widgets can provide you with the digital values.

  // Read values from potentiometer
  potVal = analogRead(controlIn);

  // Convert to pulse width
  pulse_wide = map(potVal, 0, 1023, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
  pulse_width = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
  1. You should take a look at the Sketch Builder examples for clues about how to perform certain functions in Blynk. You;ll want to use virtual pins and the BLYNK_WRITE(Vpin) callback to trigger your movement functions.

  2. You’ll want to think about pre-defined movements (open hand, close hand, touch finger & thumb etc) rather than moving each digit with a widget in the app. Structure your code so that is possible. You’ll also want to move digits simultaneously, so structure your code so that is possible too.

Good luck!


1 Like

pete thanks for this much.i need a little bit more help

the problem is that when i try to upload the blynk into the nodemcu using thr arduino ide .it keeps on telling me “ERROR COMPILING FOR NODEMCU”.Ialso would you tell me a place to learn more about the digital pins(i have never used it).

It’s all here if you look…


1 Like

thanks man.what about the error i am having with ide

Start by closing down the IDE and rebooting your computer.

If that doesn’t work go to File>Preferences in the IDE and turn on verbose compilation messages.
Start at the top of those messages and work your way through them to identify the issue. Use google to help if necessary.


As i know NODEMCU has only one analog pin that is A0.
But you have defined 4 pins which dont even exists !!!

Those 4 pins won’t be used. They are currently used to take the reading from the potentiometers, which will be replaced by digital inputs from Blynk.


Ooh !!! That sounds great… But there are no physical pins to hook up on a NODEMCU !! Where should we hook up the remaining A1, A2 & A3 ?

Use an ESP32, cost 3$ :wink:

There are no physical devices to hook to hook-up to the NodeMCU in place of the potentiometers. They will be widgets in the app connected to virtual pins.

The only physical connections will be the PCA9685 motor controller.


1 Like

Ok … my bad . I thought he also needs a physical control over the blynk app…
if only blynk app is needed then virtual pins are the best thing ever created in IOT !! :sunglasses:

I think it’s safe to say that the project will never be built, at least by the OP.
He visited once, two days ago, spent 36 minutes of reading time and hasn’t been seen since.
I cleaned-up the thread quite a bit, because the first half a dozen posts were the painful process of trying to get the OP to edit is post and add triple backticks.
I’d love it if I were proven wrong, but I can’t see it happening.



i thought of using the sketch builder and found out this

  Download latest Blynk library here:

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials:
    Sketch generator: 
    Blynk community:  
    Follow us:        

  Blynk library is licensed under MIT license
  This example code is in public domain.


  Rotate a servo using a slider!

  App project setup:
    Slider widget (0...180) on V3

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

Servo servo;


void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);


void loop()

i understood that i cant use pots.
so someone please help to use 3 more virtual pins and connect 3 more servos.
currently virtual pin3 is used so i conected the servo signal pin to d8 of nodemcu.
if i use 3 other virtual pins. which pins to which should i coonect my other servo signal pins.