#include #include #include // Set these to run example. #define FIREBASE_HOST "xxxx.firebaseio.com" // firebase host adress #define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // firebase authentification code #define WIFI_SSID "xxxxx" // wifi name #define WIFI_PASSWORD "xxxxxxxxxxxx" / wifi password #define SRV_PIN D2 // servo pin connection pin on Wemos D1 mini float servoAngle; //variable for the value we want to set servo to Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position long duration, distance; // Duration used to calculate distance void setup() { Serial.begin(115200); myservo.attach(SRV_PIN); // attaches the servo on pin 2 to the servo object delay(500); // connect to wifi. WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("connecting"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("connected: "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connection to webhost } void loop() { float meassurement = Firebase.getFloat("dist"); Serial.println(meassurement); servoAngle = (106./7.) * meassurement + 37 ; //Calculate Servo Angle from targetDistance myservo.write(servoAngle); // write servoAngle to the servo Serial.println("Angle of motor"); Serial.println(servoAngle); delay(500); return; }