#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#include <Ultrasonic.h>
#define PIR_PIN 2 // Digital pin connected to the PIR motion sensor
#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define TRIG_PIN 5 // Digital pin connected to the ultrasonic sensor trigger
#define ECHO_PIN 18 // Digital pin connected to the ultrasonic sensor echo
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C // OLED display I2C address
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
DHT dht(DHTPIN, DHTTYPE);
Ultrasonic ultrasonic(TRIG_PIN, ECHO_PIN);
// Project title and team members' names
const char *projectTitle = "REAL TIME AGRICULTURE MONITORING USING IOT";
const char *teamMembers[] ={"SUJITH","KABIL","MUTHUKUMAR","MOHANDOSS"};
const int numTeamMembers = 4;
void setup() {
Serial.begin(9600);
pinMode(PIR_PIN, INPUT);
dht.begin();
ultrasonic.setTimeout(2000); // Set timeout value for ultrasonic sensor
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
}
void loop() {
int motion = digitalRead(PIR_PIN); // Read PIR sensor output
float humidity = dht.readHumidity(); // Read humidity from DHT sensor
float temperature = dht.readTemperature(); // Read temperature from DHT sensor
float distance_cm = ultrasonic.read(); // Read distance from ultrasonic sensor
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
// Display project title
display.println(projectTitle);
display.display();
delay(3000); // Delay for visibility
// Display team members' names
display.clearDisplay();
display.setCursor(0, 0);
for (int i = 0; i < numTeamMembers; i++) {
display.print("Member ");
display.print(i + 1);
display.print(": ");
display.println(teamMembers[i]);
}
display.display();
delay(3000); // Delay for visibility
// Display sensor readings
display.clearDisplay();
display.setCursor(0, 0);
display.println("Motion: " + String(motion ? "Yes" : "No"));
display.println("Temp: " + String(temperature) + "C");
display.println("Humidity: " + String(humidity) + "%");
display.println("Distance: " + String(distance_cm) + " cm");
display.display();
delay(3000); // Delay for stability
// Show animations
for (int i = 0; i < 3; i++) {
// Animation 1: Left to right scrolling dots
display.clearDisplay();
for (int j = 0; j < SCREEN_WIDTH; j += 2) {
display.drawPixel(j, SCREEN_HEIGHT / 2, SSD1306_WHITE);
display.display();
delay(50);
}
// Animation 2: Right to left scrolling dots
display.clearDisplay();
for (int j = SCREEN_WIDTH; j > 0; j -= 2) {
display.drawPixel(j, SCREEN_HEIGHT / 2, SSD1306_WHITE);
display.display();
delay(50);
}
// Animation 3: Top to bottom scrolling dots
display.clearDisplay();
for (int j = 0; j < SCREEN_HEIGHT; j += 2) {
display.drawPixel(SCREEN_WIDTH / 2, j, SSD1306_WHITE);
display.display();
delay(50);
}
// Animation 4: Bottom to top scrolling dots
display.clearDisplay();
for (int j = SCREEN_HEIGHT; j > 0; j -= 2) {
display.drawPixel(SCREEN_WIDTH / 2, j, SSD1306_WHITE);
display.display();
delay(50);
}
}
}