Hey, folks, I found a Ubidots article written by Isabel Lopez. It details the process for sending data from the Arduino MKR WiFi 1010 devise to Ubidots. It works just fine however I am trying to integrate the necessary code to send a value coming from an attached Pressure Sensor.
Any help would be great.
Here is the article URL for referring to Isabel’s code.
Next Here is both her code and my code for constructing the data to send. I only need to send pressure_inhg at this time.
/4 is the total lenght of number,maximun number accepted is 99.99/
float value = analogRead(A0);
dtostrf(value, 4, 2, str_val_1);
sprintf(payload, “%s”,"");
sprintf(payload, “{”");
sprintf(payload, “%s%s”:%s", payload, VARIABLE_LABEL_1, str_val_1);
sprintf(payload, “%s}”, payload);
//ISABELS CODE END
//MY CODE START
int sensorVal=analogRead(A1);
float voltage = (sensorVal5.0)/1024.0;
float pressure_pascal = (3.0((float)voltage-0.47))1000000.0;
float pressure_bar = pressure_pascal/10e5;
//FOR NOW I ONLY NEED TO SEND THE FOLLOWING VALUE - pressure_inhg float pressure_inhg = pressure_bar29.53;
float pressure_mpa = pressure_inhg/295;
//MY CODE END
//Send the payload to Ubidots
sendData(payload);
delay(5000);
}
DSR Thanks for your help I have a new challenge that I was hoping you could assist with. I would like to send multiple variables for Example Sound, Humidity, Temperature and Distance. All Separate Ubidots Variables coming from the one single MKR wifi 1010 devise. Here is my code for generating each of the variables
void loop() {
char payload[200];
char str_val_1[30];
delay(2000); // Delay so DHT-22 sensor can stabalize
hum = dht.readHumidity(); // Get humidity value
temp = dht.readTemperature(); // Get temperature value
// Calculate the Speed of Sound in M/S
soundsp = 331.4 + (0.606 * temp) + (0.0124 * hum);
// Convert to cm/ms
soundcm = soundsp / 10000;
duration = sonar.ping_median(iterations);
// Calculate the distance
distance = (duration / 2) * soundcm;
// Send results to Seria Monitor
// Variables to send to UBIDOTS
//Sound (soundsp), Humid (hum), Temp (temp), Distance (distance)
Serial.print("Sound: ");
Serial.print(soundsp);
Serial.print(" m/s, ");
Serial.print("Humid: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.print(" C, ");
Serial.print("Distance: ");
if (distance >= 400 || distance <=2) {
Serial.print("Out of Range");
}
else {
Serial.print(distance);
Serial.print(" cm");
delay(500);
}
Serial.println(" ");
sendData(payload);
//delay(5000);
}