Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created November 11, 2023 10:25
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 maxpromer/a7c8e60de346e6db5b94b7d9bc80471f to your computer and use it in GitHub Desktop.
Save maxpromer/a7c8e60de346e6db5b94b7d9bc80471f to your computer and use it in GitHub Desktop.
/* TMP36 analog temperature sensor with Arduino example code. More info: https://www.makerguides.com */
// Define to which pin of the Arduino the output of the TMP36 is connected:
#define sensorPin A0
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
}
void loop() {
// Get a reading from the temperature sensor:
int reading = analogRead(sensorPin);
// Convert the reading into voltage:
float voltage = reading * (5000 / 1024.0);
// Convert the voltage into the temperature in Celsius:
float temperature = (voltage - 500) / 10;
// Print the temperature in the Serial Monitor:
Serial.print(temperature);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.println("C");
delay(1000); // wait a second between readings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment