BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Servo run in one direction instead of following slider movement

shield
uno
esp8266

#1

I WANT TO LEARN ABOUT INTEGRATION BETWEEN SERVO SG90 AND BLYNK. i WANT TO CREATE A SIMPLE IOT PROJECT WHICH THE SERVO SUPPOSEDLY MOVES ALONG WITH THE SLIDER MOVEMENTS. NOW THE PROBLEM IS THE SERVO KEEP SPINNING IN ONE DIRECTION WITHOUT STOPPING. CAN YOU GUYS GIVE ME ADVICE. HERE IS THE CODING I USED.

#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = " 665ee52ea4b74ceb9eb7bab18f6c0f4b";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Jalur Sempit";
char pass[] = "*ser8423#";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);
Servo servo;
BLYNK_WRITE(V3)
{
  servo.write(param.asInt());
}
void setup()
{
  // Debug console
  Serial.begin(9600);

 // delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
 // delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  servo.attach(9);
}

void loop()
{

  Blynk.run();
 }

#2

Please… less YELLING and more code formatting :stuck_out_tongue_winking_eye:

I fixed the formatting this time… you have to learn to use the shift key for less yelling :smiley:


#3

Not really a Blynk specific issue… but it sounds like you are using a modified continuous rotation servo… the constant spinning is normal for that type of servo until you adjust the slider back to the servos “neutral” position (usually midway on a typical servo range of 0-180).


#5

how to know that i am using modified continuous rotation servo?


#6

Umm… because it is continuously rotating? A standard servo only moves within whatever arc range it is built for… typically 180 degrees. Google servos for more info.


#7

sorry for troubling u? actually i want it to move 180 degrees back and forth by using slider in Blynk. i set the slider from 0 to 180. i know it is my code that cause the problem for continuous rotating. I show you two code here. can u tell me which one can do what i wanted.


BLYNK_WRITE(V3)
{
    
   int  SrvoPos = param.asInt();  // Get slider value
  servo.write(SrvoPos);  // Move servo to value
  delay(50);  // Set minimum delay for servo to reach desired position, keep as low as possible.
  
}
void loop()
{

 // Blynk.run();
  
}

or

void setup() {
  myservo.attach(9);  
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { 
   
    myservo.write(pos);              
    delay(15);                      
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    myservo.write(pos);  
            
    delay(15);                       
  }
}

#8

Dear @Mus_Sopee,
If you have doubts regarding those codes…start using the “search” function in this site, you will find several examples about your project that will help you as example:

Check also below link for better understanding about for statement:

https://www.arduino.cc/reference/en/language/structure/control-structure/for/

Regards!


#9

No, no, no… If the servo is a continuously rotating one, then it will NOT work like a normal servo, and visa versa.

The code doesn’t matter in that way… the same signals will produce different reactions that is all.

G :eyes:GLE the info you need about how a servo works and why a continuous rotation servo is different.