Sending float data | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Sending float data
No permission to create posts
April 3, 2012
8:22 am
Avatar
ailtonfacanha
Fortaleza - CE - Brasil
New Member
Members
Forum Posts: 1
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

 

How do I send float data using  updateThingSpeak?

 

 // Read value from Analog Input Pin 0
  int lightresistor = analogRead(A0);      
  float vout= lightresistor *0.0048828125;      
  float lux = 500/(10*((5 - vout)/vout));

 

updateThingSpeak("field1="+???????????????);

 

Ailton

April 4, 2012
9:31 am
Avatar
Hans
Natick, MA

Admin
Forum Posts: 411
Member Since:
January 18, 2011
sp_UserOfflineSmall Offline

I found a post on the Arduino forum:

 

#include<stdlib.h>
dtostrf(FLOAT,WIDTH, PRECISION,BUFFER);
 
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1205038401
(At the bottom of the post, that may help...) 
 
If this works, please let us know and I will add it the Arduino tutorials.
June 27, 2013
10:57 am
Avatar
turgo

Gold
Members
Forum Posts: 77
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

Here's how I have done it:

char buffer2[14]; //make buffer large enough for 7 digits
String tempStr = dtostrf(allSensors[i].averageTemp, 7,2,buffer2);
//'7' digits including '-' negative, decimal and white space. '2' decimal places
tempStr.trim(); //trim whitespace, important so ThingSpeak will treat it as a number

The std lib.h is included by default.

January 25, 2014
3:56 pm
Avatar
gadjet
New Member
Members
Forum Posts: 3
Member Since:
January 25, 2014
sp_UserOfflineSmall Offline

I used this: -
updateThingSpeak("field1="+ String(sensors.getTempC(Thermometer),DEC));

This takes the float value from my DS18B20 temp sensor.

January 25, 2014
4:29 pm
Avatar
turgo

Gold
Members
Forum Posts: 77
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

Thanks, gadjet, thats very cool. That led me to read all the String object methods:
http://arduino.cc/en/Reference/StringObject

October 11, 2015
1:52 pm
Avatar
BSB

Silver
Members
Forum Posts: 19
Member Since:
October 10, 2015
sp_UserOfflineSmall Offline

gadjet said

I used this: -
updateThingSpeak("field1="+ String(sensors.getTempC(Thermometer),DEC));

This takes the float value from my DS18B20 temp sensor.

If anyone is around I used a slightly different take to get decimal values to two decimal places.
I needed 3 values passed to thingspeak. Most of the code below is just debug stuff but I left it in.
The lines that do the work are the FLOAT.

Yes I borrowed the code from another thingspeak member and just tweaked it a little as it seemed slightly more modular and easier to add sensor routines see http://community.thingspeak.com/forum/arduino/ds18b20-temp-sensor/ Raklinks post

//Print Temperatures
Serial.print("Getting temperatures...

");
sensors.requestTemperatures();
float WT = sensors.getTempC(WaterTemp); // was int
Serial.print("INVALID: ");
Serial.print(WT);
Serial.print("C: ");
Serial.print("

");
float OT = sensors.getTempC(OutsideTemp); // was int
Serial.print("Room Temp is: ");
Serial.print(OT);
Serial.print("C: ");
Serial.print("

");
// read value of 5V solar panel 0 to 500
float LT = (analogRead(A0)); // was int
//String AP = String(analogRead(A0), DEC);
Serial.print("light: ");
Serial.print(LT/100); // divide by 100 to get voltage produced
Serial.print("V: ");
Serial.print("

");

// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak("field1="+String(WT, DEC) +"&field2="+String(OT, DEC)+"&field3="+String(LT, DEC));

January 10, 2019
12:54 am
Avatar
garrymacin
New Member
Members
Forum Posts: 1
Member Since:
January 10, 2019
sp_UserOfflineSmall Offline

Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float. Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.

http://net-informations.com/q/faq/float.html

February 18, 2019
4:07 pm
Avatar
Asche
New Member
Members
Forum Posts: 1
Member Since:
February 18, 2019
sp_UserOfflineSmall Offline

I am sending voltage readings to thingspeak as float values, but I'm only seeing two decimals at this end. As my values are in the range of 0,001 -0,5 V, I am loosing everything below 0,01V. As far as I understand, the float values from the arduino should not be truncated, so do i need to change anything in thingspeak?

February 19, 2019
8:21 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 727
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Asche,
Are you seeing truncated values on plots or on data that you have exported? You can use a rest call or the data export button or tab to view your data. ThingSpeak does not truncate data you send but data on plots might be rounded. There is a setting in the plot settings for rounding.

If you try this in your browser, you should get the raw data back for the last data point in a private channel (be sure to change to your Read API key:
https://api.thingspeak.com/channels/266256/feeds/last?api_key=xxxxxxxxxxxxxxxx

Does the last point have the number of decimals you need?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
31 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

faaramin, swarnak32, SaiHarish.M, vikas, abhisheksharma, khoshghadam

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457