//include Libraries
#include<Arduino.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#include <Servo.h>
#include <Adafruit_Sensor.h>
//Define Parameters(DHT)
#define DHTPIN 8
#define DHTTYPE DHT22
//Create dht Object
DHT dht(DHTPIN,DHTTYPE);
//Create Servo Object
Servo myServo;
//define LCD Parameters
const int RS=13,EN=12,d4=6,d5=2,d6=7,d7=4;
//create LCD object
LiquidCrystal lcd(RS,EN,d4,d5,d6,d7);
//define Pins
int potentiometer=A4;
int tempLED=9;
int humLED=10;
int statLED=11;
int buzzer=5;
void setup() {
// put your setup code here, to run once:
//Set up leds off.
//begin Setup
dht.begin();
myServo.attach(3);
Serial.begin(9600);
lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("EGG INCUBATOR PROJ..");
delay(2000);
lcd.clear();
lcd.setCursor(0,2);
lcd.print("Loading Details...");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("EENG CLASS OF 2019");
lcd.setCursor(0,1);
lcd.print("INSTRCTOR:Dr.MACHOKA");
lcd.setCursor(0,2);
lcd.print("EGG INCUBATOR PROJ..");
lcd.setCursor(0,3);
lcd.print("YEAR: 2024");
delay(5000);
analogWrite(statLED,255);
delay(1000);
analogWrite(statLED,0);
delay(1000);
analogWrite(statLED,255);
delay(1000);
analogWrite(statLED,0);
delay(1000);
analogWrite(statLED,255);
delay(1000);
analogWrite(statLED,0);
//Set pinModes
pinMode(statLED, OUTPUT);
pinMode(humLED, OUTPUT);
pinMode(tempLED, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int potVal,moveAngle;
potVal=analogRead(potentiometer);
moveAngle=map(potVal,0,1024,0,90);
myServo.write(moveAngle);
//set statLEDBrightness
int statLEDbrightness=map(moveAngle,0,90,255,0);
analogWrite(statLED,statLEDbrightness);
//update on LCD Display
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Angle: ");
lcd.print(moveAngle);
lcd.print(" Degrees");
//Setting Up DHT Sensor
float temp=dht.readTemperature();
float humidity=dht.readHumidity();
//update on LCD Display
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" Deg.C");
lcd.setCursor(0,2);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print("% RH");
if (isnan(temp)||isnan(humidity))
{
lcd.setCursor(0,3);
lcd.print("DHT22 Status: FAULTY ");
}
else
{
lcd.setCursor(0,3);
lcd.print("DHT22 Status: OK ");
}
if(temp<35.00||temp>40.00)
{
analogWrite(tempLED,255);
tone(buzzer,1047,100);
}
else
{
analogWrite(tempLED,0);
}
if (humidity<50.00||humidity>55.00)
{
analogWrite(humLED,255);
tone(buzzer,600,100);
}
else
{
analogWrite(humLED,0);
}
delay(100);
}