Created
November 11, 2023 10:25
-
-
Save maxpromer/a7c8e60de346e6db5b94b7d9bc80471f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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