Skip to content

Instantly share code, notes, and snippets.

@SaraJo
Created August 27, 2014 11:52
Show Gist options
  • Save SaraJo/01ce2f8f4c98f63506d9 to your computer and use it in GitHub Desktop.
Save SaraJo/01ce2f8f4c98f63506d9 to your computer and use it in GitHub Desktop.
// Read temperature
// -----------------
// Create a variable that will store the temperature value
int temperature = 0;
void setup()
{
// Register a Spark variable here
Spark.variable("temperature", &temperature, INT);
// Connect the temperature sensor to A7 and configure it
// to be an input
pinMode(A7, INPUT);
}
void loop()
{
// Keep reading the temperature so when we make an API
// call to read its value, we have the latest one
temperature = analogRead(A7);
}The returned value from the Core is going to be in the range from 0 to 4095. You can easily convert this value to actual temperature reading by using the following formula:
voltage = (sensor reading x 3.3)/4095
Temperature (in Celsius) = (voltage - 0.5) X 100
The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature
# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.spark.io/v1/devices/0123456789abcdef/temperature \
-d access_token=123412341234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment