Servo control on ESP8266 is eratic

Hey Community,

Disclaimer: So I am new to writing code as well as electronics hardware (background is machining and welding stuff) so be gentle. I have spent considerable time combing the forum and googling. None of the code is mine, I’m mostly finding different people doing similar things to what I want to do and trying to mash them together… so thanks to everyone who uploads their own code for me to butcher.

Goal: The goal I am trying to achieve is the use of the ESP to manually throw a switch with a servo, controlled by the blynk app. This is for a buddy to remotely turn on his coffee machine.

Hardware: Running an Adafruit HUZZAH ESP8266 breakout board flashed with the arduino package. I am powering it through an arduino connected to a battery to attempt to isolate any electrical issues I may have been causing it by powering it through USB power.

Blynk: using a slider to attempt to control the servo movement. Slider is set to the correct pin and from 0 to 255 using PWM (wavy line with circle around it…?)

Problem: Just like the subj. The servo reacts to the slider I am using to control it thorough the blynk app, but it does it erratically, and I cant figure out a rhyme or reason to it. It will respond to extremes, but not gradually as I would expect a slider to make it work…

Any feedback is much appreciated!

Current code that I am running.: 

/*
 *  some of this info came from: https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/Servo/Servo.ino 
 */
//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <BlynkApiArduino.h>
#include <WidgetLCD.h>
#include <WidgetLED.h>
#include <SPI.h>
#include <Servo.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "mykeyhere";

Servo servo;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "SSIDhere", "PWhere");
   servo.attach(5);
}

BLYNK_WRITE(V3)
{
  servo.write(param.asInt());
}

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

Try setting slider Min/Max to 0-180 (this is the usual range in degrees for servo).

This is called Data mapping and it should be OFF (not highlighted). You can read about Data Mapping here

Let me know if it worked!

Pavel, great work on Blynk.

Thanks for the response. Got it on the Data Mapping, thanks.

It didn’t help the problem, using 0-180 only gets me about 90 degrees of motion, which is no change from the 0-225…

It is still very twitchy. Even when there is no input or change to the slider, it keeps twitching back and forth.

At this point I am starting to think it could be a bad servo? I don’t have a second servo to compare.

It’s a usual servo thing… I was once so annoyed with the noise at night, so i used a MOSFET to isolate it when it’s not operated.

Can you control your servo with the code without Blynk? Are you sure, that servo library is working?

I mean, it’s definitely not a Blynk issue.

Gotcha, I will keep working it from my end. Thanks for the great support!

I don’t know if this thread is still relevant, but I had a similar situation and it had to do with the control signal level from the esp8266 which is powered by 3.3 Volts… The control signal from the esp had a peak voltage of about 3 volts and the servo I was using (TowerPro MG946R) required a control signal of 4.8 volts minimum. It turned out that the servo would react to the signal from the esp, but it was very erratic and sporadic. Maybe this is what you are experiencing also. The solution is to translate the control signal to 5 volts through a level shifter. Hope this helps.

2 Likes

if all you’re trying to do is turn on the coffee pot, it would be easier and less costly to just sever the switch and use a MOSFET as an electrical switch rather than trying to move a mechanical switch.

Or buy Sonoff.

@tzapulica made it work with Blynk

1 Like

You should have everything here to switch mains with a sonoff safely and cheaply and easily

Thanks @Pavel

1 Like