Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Environment Monitoring Robot with OLED Display and Flame Detection

Image of Arduino UNO Controlled Environment Monitoring Robot with OLED Display and Flame Detection

Circuit Documentation

Summary

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.

Component List

Microcontroller

  • Arduino UNO: A microcontroller board based on the ATmega328P, with a variety of digital and analog I/O pins.

Motor Driver

  • L298N DC Motor Driver: A high-power motor driver capable of driving up to two DC motors.

Motors

  • DC Motor: Two motors that can be controlled by the L298N motor driver for bidirectional movement.

Sensors

  • Flame Sensor: Detects the presence of a flame or fire.
  • DHT11: A sensor for measuring temperature and humidity.
  • IR Sensors: Two sensors that detect the presence of objects through infrared light.

Actuators

  • Buzzer: An audible signaling device.
  • LEDs: Two white LEDs used for visual signaling.

Display

  • OLED 1.3": A small display for showing sensor data and messages.

Power Supply

  • Battery 12V: Provides power to the motor driver and motors.

Wiring Details

Arduino UNO

  • A4 (SCL): Connected to OLED SCL.
  • A5 (SDA): Connected to OLED SDA.
  • D2-D6: Connected to L298N motor driver IN1-IN4.
  • D7: Connected to LED1 anode.
  • D8: Connected to buzzer PIN.
  • D9: Connected to Flame Sensor D0.
  • D10: Connected to DHT11 DATA.
  • D11: Connected to IR Sensor1 out.
  • D12: Connected to IR Sensor2 out.

L298N DC Motor Driver

  • IN1-IN4: Control inputs from Arduino D2-D5.
  • OUT1-OUT4: Connected to DC Motor pins.
  • 12V: Connected to battery +.
  • GND: Common ground with Arduino and other components.

DC Motors

  • Motor 1: Connected to L298N OUT1 and OUT2.
  • Motor 2: Connected to L298N OUT3 and OUT4.

Buzzer

  • PIN: Connected to Arduino D8.
  • GND: Common ground.

LEDs

  • LED1: Anode connected to Arduino D7, cathode to common ground.
  • LED2: Anode connected to Arduino D6, cathode to common ground.

Flame Sensor

  • D0: Connected to Arduino D9.
  • VCC: Connected to common VCC.
  • GND: Common ground.

DHT11

  • DATA: Connected to Arduino D10.
  • VCC: Connected to common VCC.
  • GND: Common ground.

OLED 1.3"

  • SCL: Connected to Arduino A4.
  • SDA: Connected to Arduino A5.
  • VCC: Connected to common VCC.
  • GND: Common ground.

IR Sensors

  • Sensor 1 Out: Connected to Arduino D11.
  • Sensor 2 Out: Connected to Arduino D12.
  • VCC: Connected to common VCC.
  • GND: Common ground.

Battery 12V

  • +: Connected to L298N 12V.
  • -: Common ground.

Documented Code

#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);
}

How to Upload Code

To upload the code to your Arduino UNO, follow these steps:

  1. Install the Arduino IDE:

    • If you haven't already, download and install the Arduino IDE from the official Arduino website.
  2. Connect the Arduino UNO:

    • Connect your Arduino UNO to your computer using a USB cable.
  3. Open the Arduino IDE:

    • Launch the Arduino IDE on your computer.
  4. Create a New Sketch:

    • Go to File > New to create a new sketch.
  5. Copy and Paste the Code:

    • Copy the provided code and paste it into the new sketch window in the Arduino IDE.
  6. Install Required Libraries:

    • The code uses the Adafruit_GFX and Adafruit_SSD1306 libraries for the OLED display and the DHT library for the DHT11 sensor. You need to install these libraries if you haven't already.
    • Go to Sketch > Include Library > Manage Libraries...
    • In the Library Manager, search for Adafruit GFX and Adafruit SSD1306, then click Install for both.
    • Similarly, search for DHT sensor library and click Install.
  7. Select the Board and Port:

    • Go to Tools > Board and select Arduino/Genuino UNO.
    • Go to Tools > Port and select the port to which your Arduino UNO is connected (e.g., COM3 on Windows or /dev/tty.usbmodem14101 on macOS).
  8. Upload the Code:

    • Click the Upload button (right arrow icon) in the Arduino IDE toolbar.
    • The IDE will compile the code and upload it to the Arduino UNO. You should see the "Done uploading" message once the process is complete