Create a gist now

Instantly share code, notes, and snippets.

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