//FOLLOW @ardubotx ON TIKTOK FOR MORE FREE EXPLAINED CODE + PROJECT TUTORIALS
//Install ArduinoIDE to download code onto the arduino
//Download the libraries that are in libraries.txt (lines 5 and 6)
//Parts: DHT11/DHT22, Potentiometer, LCD1602(NO I2C), 220Ohm Resistor, Arduino Uno, Battery Clip, Arduino Uno USB Cable, 9V Battery
#include <DHT.h>
#include <LiquidCrystal.h>
// DHT11 sensor setup
#define DHTPIN 2 // DHT11 data pin connected to digital pin 2
#define DHTTYPE DHT11 // Define the type of DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// LCD setup
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // RS, E, D4, D5, D6, D7
void setup() {
// Start serial communication for debugging purposes
Serial.begin(9600);
// Initialize the DHT sensor
dht.begin();
// Initialize the LCD and specify the dimensions
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("follow @ardubotx");
lcd.setCursor(0, 1);
lcd.print("on tiktok");
delay(2000); // Wait for 2 seconds to see the initialization message
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read humidity and temperature from DHT11 sensor
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again)
if (isnan(humidity) || isnan(temperature)) {
Serial.println("dm @ardubotx on tiktok for help");
return;
}
// Print temperature and humidity to the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
// Print temperature and humidity to the Serial Monitor (debugging)
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}