Αυτόνομο Θερμόμετρο TMP36 και I2C LCD
θέλετε να εμφανίσετε τις ενδείξεις θερμοκρασίας σε πραγματικό χρόνο και να εμφανίσετε μια ειδοποίηση όταν η θερμοκρασία είναι εκτός του καθορισμένου εύρους. Τότε μάλλον θα χρειαστείτε μια οθόνη LCD 16×2 χαρακτήρων αντί για σειριακή οθόνη.
Σε αυτό το παράδειγμα, θα συνδέσουμε την οθόνη LCD I2C στο Arduino μαζί με το TMP36.
Η σύνδεση της οθόνης LCD I2C είναι αρκετά εύκολη όπως μπορείτε να δείτε στο παρακάτω διάγραμμα καλωδίωσης.
Το παρακάτω διάγραμμα σάς δείχνει πώς να καλωδιώσετε τα πάντα.
// Include the LiquidCrystal_I2C library
#include <LiquidCrystal_I2C.h>
// Create a new instance of the LiquidCrystal_I2C class
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Define a custom degree character
byte Degree[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
// Define the analog pin, the TMP36's Vout pin is connected to
#define sensorPin A0
void setup() {
// Start the LCD and turn on the backlight
lcd.init();
lcd.backlight();
// Create a custom character
lcd.createChar(0, Degree);
}
void loop() {
// Get the voltage reading from the TMP36
int reading = analogRead(sensorPin);
// Convert that reading into voltage
// Replace 5.0 with 3.3, if you are using a 3.3V Arduino
float voltage = reading * (5.0 / 1024.0);
// Convert the voltage into the temperature in Celsius
float temperatureC = (voltage - 0.5) * 100;
// Print the temperature on the LCD;
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print(temperatureC, 1);
lcd.write(0); // print the custom degree character
lcd.print("C ");
// Print the temperature in Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
lcd.print(temperatureF, 1);
lcd.write(0); // print the custom degree character
lcd.print("F ");
delay(1000); // wait a second between readings
}
Θα πρέπει να δείτε την ακόλουθη έξοδο στην οθόνη LCD:
Σχόλια
Δημοσίευση σχολίου