//MONITORING KANDANG AYAM
//MISWAN NOMOR REGISTRASI 152365067101-303
// TUGAS EVALUASI IOT 4 - 18
#include <WiFi.h>
#include <WiFiClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHTesp.h"
int buzzerPin = 2;
const int DHT_PIN = 15;
DHTesp dhtSensor;
#define TINGGI_LAYAR 64 // Tinggi layar OLED yang digunakan
#define LEBAR_LAYAR 128 // Lebar layar OLED yang digunakan
//OLED
Adafruit_SSD1306 oled(LEBAR_LAYAR, TINGGI_LAYAR, &Wire, -1);
void setup() {
// led
pinMode(19, OUTPUT);
pinMode(18, OUTPUT);
pinMode(5, OUTPUT);
//SENSOR DHT
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("SELAMAT DATANG DI MONITORING SUHU KANDANG");
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
oled.clearDisplay();
oled.setTextSize(1); // Atur ukuran text
oled.setTextColor(WHITE); // Atur warna text
oled.setCursor(20, 20); // Atur posisi text pada display
oled.println("SUHU KANDANG"); // Text yang dicetak
delay(2000);
oled.display();
oled.clearDisplay();// menampilkan display OLED
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
if(data.temperature <=29)
{
// put your main code here, to run repeatedly:
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print(data.temperature); //Tampilan LCD
oled.print(" SUHU RENDAH");
oled.display();
//LED BIRU
digitalWrite(18, HIGH);
digitalWrite(19, LOW);
digitalWrite(5, LOW);
}
if(data.temperature >29 && data.temperature <=35)
{
// put your main code here, to run repeatedly:
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print(data.temperature); //Tampilan LCD
oled.print(" SUHU CUKUP");
oled.display();
//LED KUNING
digitalWrite(18, LOW);
digitalWrite(19, LOW);
digitalWrite(5, HIGH);
}
if(data.temperature > 35)
{
// put your main code here, to run repeatedly:
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print(data.temperature); //Tampilan LCD
oled.print(" SUHU PANAS");
oled.display();
tone(buzzerPin, 150);
delay(500);
noTone(buzzerPin);
//LED MERAH
digitalWrite(18, LOW);
digitalWrite(19, HIGH);
digitalWrite(5, LOW);
}
delay(1000); // this speeds up the simulation
}