Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The TMP36 is an analog temperature sensor that outputs a voltage proportional to the temperature it measures. Here's an example of how to use the TMP36 with an Arduino to read the temperature and display it on the Serial Monitor:
- To wire the TMP36 sensor, connect its left pin (when facing the flat side) to the 5V pin on the Arduino, the middle pin to the TMP36_PIN (analog pin A0), and the right pin to the ground.
- This code will continuously read the temperature from the TMP36 sensor and print it on the Serial Monitor in degrees Celsius.
- */
- const int TMP36_PIN = A0; // TMP36 connected to Arduino analog pin A0
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- float temperature = readTMP36Temperature();
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- delay(1000); // Wait 1 second between readings
- }
- float readTMP36Temperature() {
- int sensorValue = analogRead(TMP36_PIN);
- float voltage = sensorValue * (5.0 / 1023.0); // Convert sensor value to voltage
- float temperature = (voltage - 0.5) * 100.0; // Convert voltage to temperature in Celsius
- return temperature;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement