#include <DHT.h>
#include <LiquidCrystal_I2C.h>
// Define the pin where the DHT22 data pin is connected
#define DHTPIN 15
// Define the type of sensor you're using
#define DHTTYPE DHT22
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Define the pin where the potentiometer is connected
#define POT_PIN A0 // GP26 corresponds to ADC0
// Initialize the LCD, set the I2C address to 0x27, and the dimensions to 16 columns by 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize serial communication at 9600 baud rate
Serial1.begin(9600);
Serial1.println("Hello, Raspberry Pi Pico!");
//Serial.print(tempC);
//Serial.println(" °C");
lcd.init();
// Initialize the DHT sensor
dht.begin();
// Initialize the LCD
lcd.begin(16, 2);
// Turn on the backlight of the LCD
lcd.backlight();
// Print a message to the LCD
lcd.setCursor(0, 0);
lcd.print("Temp : ");
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read the temperature in Celsius
float tempC = dht.readTemperature();
// Check if any reads failed and exit early (to try again)
if (isnan(tempC)) {
Serial1.println("Failed to read from DHT sensor!");
return;
}
// Print the temperature to the Serial Monitor
Serial1.print("Temperature: ");
Serial1.print(tempC);
Serial1.println(" °C");
lcd.setCursor(0, 1); // Set cursor to the beginning of the second line
lcd.print(" "); // Clear the previous voltage reading
lcd.setCursor(0, 1);
lcd.print(tempC, 2); // Print voltage with 2 decimal places
lcd.print(" * C");
// Wait a bit before the next loop
delay(500);
}