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.