Skip to content

Instantly share code, notes, and snippets.

@sidwarkd
Created December 22, 2016 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidwarkd/9f430eb92c0dbca3a0c3c0867a97ae54 to your computer and use it in GitHub Desktop.
Save sidwarkd/9f430eb92c0dbca3a0c3c0867a97ae54 to your computer and use it in GitHub Desktop.
A simple temperature sensor that publishes an event to the Particle cloud if it gets above 82 degrees Fahrenheit
void setup() {
Serial.begin(9600);
}
void loop() {
int val = analogRead(A0);
float voltage = val * 3.3 / 4096; // Convert analog reading to voltage value
float tempC = (voltage - 0.5) * 100;
float tempF = (tempC * 9.0 / 5.0) + 32.0;
Serial.printlnf("Temp F: %3.1f Temp C: %3.1f", tempF, tempC);
if(tempF > 82.0)
{
String msg = "Device " + Particle.deviceID() + " is reading " + String(tempF) + " degrees";
Particle.publish("server_room_too_hot", msg, 60, PRIVATE);
}
delay(3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment