#include <Ubidots.h>
#define TRIGPIN 4
#define ECHOPIN 5
#define TOKEN "BBFF-ed40790f85bec15b72564321c8c6c3db536"
#define DEVICE_LABEL "esp32"
#define VARIABLE_LABEL "distance"
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHOPIN, INPUT);
}
void loop() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
long duration = pulseIn(ECHOPIN, HIGH);
float distance = duration * 0.034 / 2;
ubidots.add(VARIABLE_LABEL, distance);
bool response = ubidots.send(DEVICE_LABEL);
if (response) {
Serial.println("Data sent to Ubidots");
} else {
Serial.println("Failed to send data to Ubidots");
}
delay(1000);
}