ESP8266 nodeMCU-V3- and micro servo 9g - SSG90

Hi,

I am having problem with the SG90 servo. It won't move.
The nodeMCU is connected to wifi. It will get data from my desktop. Then on my loop if the data is the same, sg90 servo will move. But, unfortunately, it's noting moving.
May you kindly help me please.

Below is the code I am using.


#include <SPI.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <Servo.h>

const char *ssid = "testnet"; //WIFI NAME OR HOTSPOT
const char *password = "testpassword"; //WIFI PASSWORD POR MOBILE HOTSPOT PASSWORD

Servo servo;
void setup() {
  servo.attach(D1);//D4
  servo.write(0);
   delay(1000);
   Serial.begin(115200);
   WiFi.mode(WIFI_OFF);    
   delay(1000);
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid, password);
   Serial.println("");
   
   Serial.print("Connecting");
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
     Serial.print(".");
   }

   Serial.println("");
   Serial.print("Connected to ");
   Serial.println(ssid);
   Serial.print("IP address: ");
   Serial.println(WiFi.localIP()); 
   
   SPI.begin();

}


void loop() {
Serial.println("Connected to wifi");
 if(WiFi.status() == WL_CONNECTED) {
    
    HTTPClient http;
    String postData = "getRFIDcarddevicecard=1&rfidcard=1";
    String uri ="http://192.168.1.110/test/sendcard.php";
    http.begin("http://192.168.1.110/test/sendcard.php");              
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");  
    //Serial.println(String(cardid));
    //Serial.println(uri + postData);
     
    int httpCode = http.POST(postData); 
    String payload = http.getString();
    //int httpResponseCode = http.sendRequest("POST", postData);
   //Serial.println(String(cardid));
   Serial.println(httpCode);
   Serial.println(payload);
    
    if(payload.equals("connectedandvalid")) {


   servo.write(0);
   delay(1000);
   servo.write(90);
   delay(1000);
   servo.write(180);
   delay(1000);
   Serial.println("andito");
    } else {
      

    }
    
    http.end();
  }
 
  delay (2000);
     
}

I tried the connection here and there
ie - https://www.youtube.com/watch?v=tlgLA-PT5eE

Kindly help please.

Did You try the servo by applying a servo example test code?
What status/debug printouts do You get?
Schematics showing pin labels and powering often holds answers.

Hi,
Yes, I check the sample code. But I don't have pin 9 on my nodemcu.

I also tried this sample. But it's not working.

#include <Servo.h>
 
Servo servo;
 
void setup() {
    servo.attach(D1);
    servo.write(0);
    delay(2000);
}
 
void loop() {
    servo.write(0);
    delay(3000);
    servo.write(90);
    delay(3000);
    servo.write(180);
    delay(3000);
}

Please read more then the first line in reply #2.
Telling about other failed attempts adds nothing useful.

I got this error
Connecting.................._____.....

you have lost connection with the serial port
try unpluging/plugingin the USB connector

have you seen esp8266-servo-motor-control

Trying to connect, waiting I get. Then no clue.

The servo complicates things.
Try Uploading to the ESP without anything else connected.
A servo requires a good deal of power, possibly beyond the limit of your USB port. Exceeding that limit can tank your USB port - and then: "no connection".

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.