#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#include <DHT.h>
#define NEOPIXEL_PIN 5
#define NEOPIXEL_NUM 54
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_NUM, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
#define BUZZER_PIN 12
#define DHT_PIN 13
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);
#define LCD_I2C_ADDR 0x27
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, 16, 2);
#define LED_PIN 2
void setup() {
Serial.begin(115200);
// Initialize NeoPixel
strip.begin();
strip.show();
strip.setBrightness(100);
// Initialize DHT sensor
dht.begin();
// Initialize LCD display
lcd.begin(16, 2);
lcd.init();
lcd.backlight();
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Set up display
lcd.setCursor(0, 0);
lcd.print("Temperature:");
dht.begin();
}
void loop() {
// Read temperature from DHT sensor
float temperature = dht.readTemperature();
//
uint32_t color;
if (temperature > 25.0) {
// High temperature, use red color
color = strip.Color(255, 0, 0);
} else if (temperature < 15.0) {
// Low temperature, use blue color
color = strip.Color(0, 0, 255);
} else {
// Normal temperature, use green color
color = strip.Color(0, 255, 0);
}
if (temperature > 25.0) {
digitalWrite(LED_PIN, HIGH); // Turn on LED if temperature is above 25°C
tone(BUZZER_PIN, 1000); // Activate the buzzer
} else {
digitalWrite(LED_PIN, LOW); // Turn off LED otherwise
noTone(BUZZER_PIN); // Deactivate the buzzer
}
// Display temperature on LCD
lcd.setCursor(0, 1);
lcd.print(" "); // Clear the line
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
// Update NeoPixel color with animation
neoPixelAnimation(color);
delay(500); // Adjust the delay as needed
}
void neoPixelAnimation(uint32_t color) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0)); // Clear all pixels
strip.show();
delay(50);
}
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(50);
}
}