This circuit is designed to interface an Arduino UNO with various sensors, actuators, and an OLED display. The primary components include an Arduino UNO microcontroller, an L298N DC motor driver, two DC motors, a buzzer, two white LEDs, a flame sensor, a DHT11 temperature and humidity sensor, an OLED display, two IR sensors, and a 12V battery. The circuit is capable of reading sensor data, displaying information on the OLED, controlling the buzzer and LEDs based on sensor inputs, and driving the motors through the motor driver.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// DHT11 settings
#define DHTPIN 10
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// Flame sensor pin
#define FLAME_SENSOR_PIN 9
// Buzzer pin
#define BUZZER_PIN 8
// LED pins
#define LED1_PIN 7
#define LED2_PIN 6
// L298N motor driver pins
#define IN1_PIN 2
#define IN2_PIN 3
#define IN3_PIN 4
#define IN4_PIN 5
// IR sensor pins
#define IR_SENSOR1_PIN 11
#define IR_SENSOR2_PIN 12
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
// Initialize DHT11 sensor
dht.begin();
// Initialize flame sensor pin
pinMode(FLAME_SENSOR_PIN, INPUT);
// Initialize buzzer pin
pinMode(BUZZER_PIN, OUTPUT);
// Initialize LED pins
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
// Initialize motor driver pins
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
pinMode(IN3_PIN, OUTPUT);
pinMode(IN4_PIN, OUTPUT);
// Initialize IR sensor pins
pinMode(IR_SENSOR1_PIN, INPUT);
pinMode(IR_SENSOR2_PIN, INPUT);
}
void loop() {
// Read DHT11 sensor data
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read flame sensor data
int flameSensorValue = digitalRead(FLAME_SENSOR_PIN);
// Read IR sensor data
int irSensor1Value = digitalRead(IR_SENSOR1_PIN);
int irSensor2Value = digitalRead(IR_SENSOR2_PIN);
// Display data on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Temp: ");
display.print(temperature);
display.print(" C");
display.setCursor(0, 10);
display.print("Humidity: ");
display.print(humidity);
display.print(" %");
display.setCursor(0, 20);
display.print("Flame: ");
display.print(flameSensorValue ? "No" : "Yes");
display.setCursor(0, 30);
display.print("IR1: ");
display.print(irSensor1Value ? "No" : "Yes");
display.setCursor(0, 40);
display.print("IR2: ");
display.print(irSensor2Value ? "No" : "Yes");
display.display();
// Control buzzer based on flame sensor
if (flameSensorValue == LOW) {
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(BUZZER_PIN, LOW);
}
// Control LEDs based on IR sensors
digitalWrite(LED1_PIN, irSensor1Value == LOW ? HIGH : LOW);
digitalWrite(LED2_PIN, irSensor2Value == LOW ? HIGH : LOW);
// Control motors (example: forward motion)
digitalWrite(IN1_PIN, HIGH);
digitalWrite(IN2_PIN, LOW);
digitalWrite(IN3_PIN, HIGH);
digitalWrite(IN4_PIN, LOW);
delay(1000);
}
To upload the code to your Arduino UNO, follow these steps:
Install the Arduino IDE:
Connect the Arduino UNO:
Open the Arduino IDE:
Create a New Sketch:
Copy and Paste the Code:
Install Required Libraries:
Select the Board and Port:
Upload the Code: