Firebase + WEMOS D1 mini

  • Hello!

    In my project I am uploading data of a distance sensor to firebase ( in real-time.
    I want to use these data to trigger a servo motor on another site.
    This is the code for it down there.

    What I am still missing is the variable "distance" which is the one send from the distance sensor. I want to get that number back from firebase to control my servo.
    Unfortunately I can't find any information on that and the ones provided by firebase ( doesn't help me as a beginner.

    Any ideas on how to get there?

    #include <Servo.h>
    #include <ESP8266WiFi.h>
    #include <FirebaseArduino.h>

    // Set these to run example.
    #define FIREBASE_HOST ""
    #define FIREBASE_AUTH "xx"

    #define WIFI_SSID "xxx"
    #define WIFI_PASSWORD "xxx"

    #define SRV_PIN D4

    float servoAngle; //Variable for the value we want to set servo to.

    Servo myservo; // create servo object to control a servo
    // twelve servo objects can be created on most boards
    int pos = 0; // variable to store the servo position

    long duration, distance; // Duration used to calculate distance

    void setup() {
    myservo.attach(SRV_PIN); // attaches the servo on pin 4 to the servo object

    // connect to wifi.
    while (WiFi.status() != WL_CONNECTED) {
    Serial.print("connected: ");



    void loop() {

    servoAngle = (106./7.) * distance + 37; //Calculate Servo Angle from targetDistance
    //for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(servoAngle); // write servoAngle to the servo __ tell servo to go to position in variable 'pos'
    delay(150); // waits 15ms for the servo to reach the position


  • Hi, have a look here line 69 and below.
    It shoud answer your question for float, other datatype are similar.

Log in to reply

Looks like your connection to WEMOS Forum was lost, please wait while we try to reconnect.