Skip to content

Instantly share code, notes, and snippets.

@giantmolecules
Created June 8, 2017 20:46
Show Gist options
  • Save giantmolecules/c03aeca6c4b70fc0c777054e92a2a473 to your computer and use it in GitHub Desktop.
Save giantmolecules/c03aeca6c4b70fc0c777054e92a2a473 to your computer and use it in GitHub Desktop.
Timer tempTimer(2000, publishTemp);
int val = 0;
float voltage = 0.0;
float temperatureC = 0.0;
void setup() {
pinMode(A0, INPUT);
Serial.begin(115200);
}
void loop() {
val = analogRead(A0);
voltage = val*(3.3/4096.0);
Serial.print("Voltage = ");
Serial.print(voltage);
temperatureC = (voltage - 0.5) * 100;
Serial.print(" Temperature = ");
Serial.print(temperatureC);
Serial.println(" C");
delay(100);
}
void publishTemp(){
Particle.publish("TEMPC", String(temperatureC));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment