Servo only move 90 degrees

I made a circuit with the esp8266
I done all the setup
I uploaded the code also, you can see the code

#define BLYNK_PRINT Serial
#define USE_NODE_MCU_BOARD

#include "BlynkEdgent.h"
#include <Servo.h>

Servo servo1;
Servo servo2;

BLYNK_WRITE(V0)
{
  int s0 = param.asInt(); // parameter as int 
  if(s0 == HIGH)
  { digitalWrite(D8,HIGH);
    delay(10);
    }  
    if(s0 == LOW)
  { digitalWrite(D8,LOW);
    delay(10);
    } 
    
}
BLYNK_WRITE(V1) {

servo1.write(param.asInt());
delay(1000);
}
BLYNK_WRITE(V2) {

servo2.write(param.asInt());
delay(1000);
}

void setup()
{
  Serial.begin(115200);
  pinMode(D8,OUTPUT);
  digitalWrite(D8,LOW);
  servo1.attach(5);
  servo2.attach(4);
  BlynkEdgent.begin();
}

void loop() {

    BlynkEdgent.run();
}

AlI things are working good
but the main problem is when I move the app slider 0-180 degrees the servo moves only 0-90 degrees
can anyone help me with that!!
Thanks in advance.
Regards,
Abhijeet

1 Like

@techboystoys please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

done

Which virtual pin is your slider widget attached to?

How have you defined the min/max values for that datastream?

Why do you have delays here:

Pete.

I am using V1 and V2 virtual pins to control two sliders for two servos
The min value is 0 and the max is 180
I am adding delay for smooth motion of servos

Can I see a screenshot of your datastream setup?

Blynk doesn’t like blocking delays.

Pete.

Your max value is not showing, but try with Double instead of Integer.

Same problem with Double

What happens if you increase the MAX value?

Servo comes to initial position if I increase the max value

How are your slider widgets configured?

Pete.

So it goes beyond the 90° now?
Delete the delays and try again, if that won’t work try to write a fixed 180 value to V1 and see if that works.
Also try with slider setting “send on release”.

I got the solution
the main problem is in esp8266 servo.h library
So I changed MIN_PULSE_WIDTH 1000 to 500 and MAX_PULSE_WIDTH 2000 to 2500
Now my servo move freely
Thanks to PeteKnight and bazzio for your precious time
best,
Abhijeet

Hi there,

I have come up with the same problem with my servo only moving through 90degrees. I have attempted to adjust the Pulse widths as described by Abhijeet but it still doesnt appear to be working. I am using a nodeMCU ESP8266 with Blynk 2.0.

Datastreams - I have tried a few different settings but with no joy, they are currently set as integer, min = 0 and max = 180.

Not sure if I have updated the settings correctly or if anyone has any other ideas?

Many thanks
Dave

Code is

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_TEMPLATE_NAME "ServoControl"
#define BLYNK_AUTH_TOKEN "REDACTED"

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

#include<Servo.h>
Servo servo1;

#define DEFAULT_MIN_PULSE_WIDTH 500
#define DEFAULT_MAX_PULSE_WIDTH 2500
#define DEFAULT_NEUTRAL_PULSE_WIDTH 1500
#define REFRESH_INTERVAL 20000


char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "BT-SKATMF";
char pass[] = "K3vrQCyxMFcuXg";

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

void setup()
{
  Serial.begin(9600);
  servo1.attach(D2);
  //servo1.write(0);
  Blynk.begin(auth, ssid, pass);//Splash screen delay
  //delay(2000); 
}

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

And then the output from the console window is as follows…

C:\Users\dh526\AppData\Local\Temp\.arduinoIDE-unsaved2023111-1980-1e6e1yb.mr0zl\sketch_feb11d\sketch_feb11d.ino:12: warning: "DEFAULT_MIN_PULSE_WIDTH" redefined
   12 | #define DEFAULT_MIN_PULSE_WIDTH 500
      | 
In file included from C:\Users\dh526\AppData\Local\Temp\.arduinoIDE-unsaved2023111-1980-1e6e1yb.mr0zl\sketch_feb11d\sketch_feb11d.ino:9:
C:\Users\dh526\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.1\libraries\Servo\src/Servo.h:54: note: this is the location of the previous definition
   54 | #define DEFAULT_MIN_PULSE_WIDTH      1000 // uncalibrated default, the shortest duty cycle sent to a servo
      | 
C:\Users\dh526\AppData\Local\Temp\.arduinoIDE-unsaved2023111-1980-1e6e1yb.mr0zl\sketch_feb11d\sketch_feb11d.ino:13: warning: "DEFAULT_MAX_PULSE_WIDTH" redefined
   13 | #define DEFAULT_MAX_PULSE_WIDTH 2500
      | 
In file included from C:\Users\dh526\AppData\Local\Temp\.arduinoIDE-unsaved2023111-1980-1e6e1yb.mr0zl\sketch_feb11d\sketch_feb11d.ino:9:
C:\Users\dh526\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.1\libraries\Servo\src/Servo.h:55: note: this is the location of the previous definition
   55 | #define DEFAULT_MAX_PULSE_WIDTH      2000 // uncalibrated default, the longest duty cycle sent to a servo
      | 
. Variables and constants in RAM (global, static), used 29984 / 80192 bytes (37%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1564     initialized variables
╠══ RODATA   2492     constants       
╚══ BSS      25928    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 61247 / 65536 bytes (93%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     28479    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 252308 / 1048576 bytes (24%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     252308   code in flash   
esptool.py v3.0
Serial port COM5
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: b4:e6:2d:49:55:a7
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 288992 bytes to 211629...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 288992 bytes (211629 compressed) at 0x00000000 in 18.7 seconds (effective 123.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Try this

servo1.attach(4, 500, 2500);

Instead of

servo1.attach(D2);
4 Likes

Brilliant thanks John - that has worked perfectly!

1 Like