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

Arduino UNO Based Air Freshener Control System with Wi-Fi Connectivity and Motion Detection

Image of Arduino UNO Based Air Freshener Control System with Wi-Fi Connectivity and Motion Detection

Circuit Documentation

Summary

The circuit is designed to control an air freshener system using an Arduino UNO as the main controller. It features a DHT11 sensor for measuring temperature and humidity, a 0.96" OLED display for outputting sensor data, an ESP8266 ESP-01 WiFi module for network connectivity, a PIR (Motion Sensor) for detecting motion, a 5V relay for controlling the air freshener dispensing motor, a bi-directional logic level converter for voltage level translation between 3.3V and 5V devices, and an LED with a resistor to indicate system status. The system's behavior is programmed into the Arduino UNO, which interacts with the other components to display sensor readings, control the relay, and communicate with the ESP8266 for web-based control.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • Used as the main controller for the system

5V Relay

  • Electromechanical switch used to control the air freshener dispensing motor

0.96" OLED

  • Small display for showing temperature and humidity readings

ESP8266 ESP-01 WiFi Module

  • WiFi module that enables network connectivity and hosts a web page for system control

PIR/Motion Sensor

  • Sensor that detects motion and triggers the system to respond accordingly

DHT11

  • Sensor for measuring temperature and humidity

Bi-Directional Logic Level Converter

  • Device that safely steps down 5V signals to 3.3V and steps up 3.3V to 5V

LED: Two Pin (red)

  • Indicator light that shows system status

Resistor

  • 220 Ohm resistor used to limit current to the LED

Wiring Details

Arduino UNO

  • 3.3V connected to the logic level converter LV, relay VCC, OLED VDD, ESP8266 CH_PD and VCC, DHT11 VCC, and PIR sensor VCC
  • 5V connected to the logic level converter HV
  • GND connected to the resistor, logic level converter GND, OLED GND, relay GND, ESP8266 GND, DHT11 GND, and PIR sensor GND
  • A4 (SDA) connected to OLED SDA
  • A5 (SCL) connected to OLED SCK
  • D11 connected to logic level converter HV1
  • D10 connected to logic level converter HV2
  • D5 connected to LED anode
  • D4 connected to PIR sensor OUTPUT
  • D3 connected to relay In
  • D2 connected to DHT11 DATA

5V Relay

  • In connected to Arduino UNO D3
  • GND connected to Arduino UNO GND
  • VCC connected to Arduino UNO 3.3V

0.96" OLED

  • SDA connected to Arduino UNO A4
  • SCK connected to Arduino UNO A5
  • GND connected to Arduino UNO GND
  • VDD connected to Arduino UNO 3.3V

ESP8266 ESP-01 WiFi Module

  • RXD connected to logic level converter LV1
  • TXD connected to logic level converter LV2
  • CH_PD and VCC connected to Arduino UNO 3.3V
  • GND connected to Arduino UNO GND

PIR/Motion Sensor

  • OUTPUT connected to Arduino UNO D4
  • GND connected to Arduino UNO GND
  • VCC connected to Arduino UNO 3.3V

DHT11

  • DATA connected to Arduino UNO D2
  • GND connected to Arduino UNO GND
  • VCC connected to Arduino UNO 3.3V

Bi-Directional Logic Level Converter

  • HV connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND
  • HV1 connected to Arduino UNO D11
  • HV2 connected to Arduino UNO D10
  • LV connected to Arduino UNO 3.3V
  • LV1 connected to ESP8266 RXD
  • LV2 connected to ESP8266 TXD

LED: Two Pin (red)

  • anode connected to Arduino UNO D5
  • cathode connected to one end of the resistor

Resistor

  • One end connected to LED cathode
  • Other end connected to Arduino UNO GND

Documented Code

/*
 * Air Freshener Control System
 *
 * This code reads temperature and humidity from a DHT11 sensor and displays
 * the values on an OLED display and a web page hosted by an ESP8266 module.
 * An LED blinks every 2 seconds to indicate no motion and stays on when
 * motion is detected by a PIR sensor. The relay module controls the air
 * freshener dispensing motor, and the dispensing interval can be set via
 * the web page.
 */

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define DHTPIN 2         // Define the pin connected to the DHT11 data pin
#define DHTTYPE DHT11    // Specify the type of DHT sensor
#define LED_PIN 5        // Define the pin connected to the LED
#define PIR_PIN 4        // Define the pin connected to the PIR sensor output
#define RELAY_PIN 3      // Define the pin connected to the relay input
#define SCREEN_WIDTH 128 // OLED display width in pixels
#define SCREEN_HEIGHT 64 // OLED display height in pixels

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // Initialize the OLED display

unsigned long previousMillis = 0; // Stores the last time the LED was updated
const long interval = 2000;       // Interval at which to blink the LED (milliseconds)
bool motionDetected = false;      // Flag for motion detection

void setup() {
  pinMode(LED_PIN, OUTPUT);    // Set the LED pin as an output
  pinMode(PIR_PIN, INPUT);     // Set the PIR sensor pin as an input
  pinMode(RELAY_PIN, OUTPUT);  // Set the relay pin as an output
  digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off at startup
  dht.begin();                 // Start the DHT sensor
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize the OLED display with the I2C address
  display.display();           // Show the display buffer on the screen
  delay(2000);                 // Wait for 2 seconds
  display.clearDisplay();      // Clear the display buffer

  Serial.begin(115200); // Start serial communication with ESP8266 at 115200 baud
  // Initialize ESP8266
  Serial.println("AT+RST"); // Reset the ESP8266
  delay(1000);
  Serial.println("AT+CWMODE=1"); // Set ESP8266 to Station mode
  delay(1000);
  Serial.print("AT+CWJAP=\"your_SSID\",\"your_PASSWORD\""); // Connect to WiFi network
  delay(5000);
  Serial.println("AT+CIPMUX=1"); // Enable multiple connections
  delay(1000);
  Serial.println("AT+CIPSERVER=1,80"); // Start the server on port 80
  delay(1000);
}

void loop() {
  unsigned long currentMillis = millis(); // Get the current time
  if (digitalRead(PIR_PIN) == HIGH) { // Check if motion is detected
    motionDetected = true;
    digitalWrite(LED_PIN, HIGH); // Turn on the LED
  } else {
    motionDetected = false;
    if (currentMillis - previousMillis >= interval) { // Check if it's time to blink the LED
      previousMillis = currentMillis;
      digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Toggle the LED state
    }
  }
  float h = dht.readHumidity();    // Read humidity from DHT11
  float t = dht.readTemperature(); // Read temperature from DHT11
  display.clearDisplay();          // Clear the display buffer
  display.setTextSize(1);          // Set text size to 1
  display.setTextColor(SSD1306_WHITE); // Set text color to white
  display.setCursor(0, 0);         // Set cursor to top-left corner
  display.print("Temp: ");         // Print the temperature label
  display.print(t);                // Print the temperature value
  display.print(" C");             // Print the temperature unit
  display.setCursor(0, 10);        // Move cursor to the next line
  display.print("Humidity: ");     // Print the humidity label
  display.print(h);                // Print the humidity value
  display.print(" %");             // Print the humidity unit
  display.display();               //