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

Arduino Nano-Based Smart Water Quality Monitoring System with OLED Display

Image of Arduino Nano-Based Smart Water Quality Monitoring System with OLED Display

Circuit Documentation

Summary

This circuit is designed to monitor and control various environmental parameters such as pH, turbidity, water level, and temperature. It uses an Arduino Nano microcontroller to read sensor data and control actuators like a water pump and a pneumatic solenoid valve. The data is displayed on an OLED screen, and alerts are provided via a buzzer.

Component List

  1. Arduino Nano

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. pH Sensor (ph4502c)

    • Description: Sensor to measure the pH level of a solution.
    • Pins: VCC, G1, G2, Po, Do, To
  3. Turbidity Module

    • Description: Sensor to measure the turbidity (cloudiness) of water.
    • Pins: VCC, GND, OUT
  4. DS18B20 Temperature Sensor

    • Description: Digital temperature sensor.
    • Pins: GND, VCC, OUT
  5. Water Level Sensor

    • Description: Sensor to measure the water level.
    • Pins: SIG, VCC, GND
  6. Water Pump

    • Description: Pump to control water flow.
    • Pins: VCC, GND
  7. OLED 1.3" Display

    • Description: OLED display for visual output.
    • Pins: GND, VCC, SCL, SDA
  8. 12V Pneumatic Solenoid Valve

    • Description: Valve to control the flow of air or liquid.
    • Pins: VCC, GND
  9. Battery 12V

    • Description: Power source.
    • Pins: +, -
  10. 1 Channel 5V Relay Module

    • Description: Relay module to control high voltage devices.
    • Pins: VCC+, VCC- (GND), IN, N.O., COM, N.C.
  11. Buzzer

    • Description: Buzzer for audio alerts.
    • Pins: PIN, GND

Wiring Details

Arduino Nano

  • GND connected to:

    • Turbidity Module (GND)
    • Water Level Sensor (GND)
    • 1 Channel 5V Relay Module (GND)
    • Buzzer (GND)
    • pH Sensor (G1, G2)
    • OLED Display (GND)
    • DS18B20 Temperature Sensor (GND)
  • 5V connected to:

    • Turbidity Module (VCC)
    • Water Level Sensor (VCC)
    • 1 Channel 5V Relay Module (VCC+)
    • pH Sensor (VCC)
    • OLED Display (VCC)
    • DS18B20 Temperature Sensor (VCC)
  • D2 connected to:

    • DS18B20 Temperature Sensor (OUT)
  • D3 connected to:

    • 1 Channel 5V Relay Module (IN)
  • D4 connected to:

    • 1 Channel 5V Relay Module (IN)
  • D5 connected to:

    • Buzzer (PIN)
  • A5 connected to:

    • OLED Display (SCL)
  • A4 connected to:

    • OLED Display (SDA)
  • A2 connected to:

    • Water Level Sensor (SIG)
  • A1 connected to:

    • Turbidity Module (OUT)
  • A0 connected to:

    • pH Sensor (Po)

Turbidity Module

  • GND connected to:

    • Arduino Nano (GND)
  • VCC connected to:

    • Arduino Nano (5V)
  • OUT connected to:

    • Arduino Nano (A1)

DS18B20 Temperature Sensor

  • GND connected to:

    • Arduino Nano (GND)
  • VCC connected to:

    • Arduino Nano (5V)
  • OUT connected to:

    • Arduino Nano (D2)

Water Level Sensor

  • GND connected to:

    • Arduino Nano (GND)
  • VCC connected to:

    • Arduino Nano (5V)
  • SIG connected to:

    • Arduino Nano (A2)

Water Pump

  • VCC connected to:

    • Battery 12V (+)
  • GND connected to:

    • 1 Channel 5V Relay Module (N.O.)

OLED 1.3" Display

  • GND connected to:

    • Arduino Nano (GND)
  • VCC connected to:

    • Arduino Nano (5V)
  • SCL connected to:

    • Arduino Nano (A5)
  • SDA connected to:

    • Arduino Nano (A4)

12V Pneumatic Solenoid Valve

  • VCC connected to:

    • 1 Channel 5V Relay Module (N.O.)
  • GND connected to:

    • Battery 12V (-)

Battery 12V

  • + connected to:

    • Water Pump (VCC)
    • 1 Channel 5V Relay Module (COM)
  • - connected to:

    • 12V Pneumatic Solenoid Valve (GND)
    • 1 Channel 5V Relay Module (COM)

1 Channel 5V Relay Module

  • VCC+ connected to:

    • Arduino Nano (5V)
  • VCC- (GND) connected to:

    • Arduino Nano (GND)
  • IN connected to:

    • Arduino Nano (D3)
    • Arduino Nano (D4)
  • N.O. connected to:

    • Water Pump (GND)
    • 12V Pneumatic Solenoid Valve (VCC)
  • COM connected to:

    • Battery 12V (+)
    • Battery 12V (-)

Buzzer

  • PIN connected to:

    • Arduino Nano (D5)
  • GND connected to:

    • Arduino Nano (GND)

Documented Code

#include <Wire.h>                        // For OLED Display
#include <Adafruit_GFX.h>                 // For OLED Display
#include <Adafruit_SSD1306.h>             // For OLED Display
#include <OneWire.h>                      // For DS18B20 Temperature Sensor
#include <DallasTemperature.h>            // For DS18B20 Temperature Sensor

#define SCREEN_WIDTH 128                  // OLED display width
#define SCREEN_HEIGHT 64                  // OLED display height
#define OLED_RESET -1                     // Reset pin (not used)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Pin Definitions
#define PH_SENSOR_PIN A0                  // pH Sensor connected to A0
#define TURBIDITY_SENSOR_PIN A1           // Turbidity Sensor connected to A1
#define WATER_LEVEL_SENSOR_PIN A2         // Water Level Sensor connected to A2
#define TEMP_SENSOR_PIN 2                 // DS18B20 Temperature Sensor on digital pin 2
#define RELAY_SOLENOID_PIN 3              // Relay for Solenoid Valve on digital pin 3
#define RELAY_PUMP_PIN 4                  // Relay for Pump on digital pin 4
#define BUZZER_PIN 5                      // Buzzer connected to digital pin 5

// DS18B20 Sensor Setup
OneWire oneWire(TEMP_SENSOR_PIN);
DallasTemperature sensors(&oneWire);

// Threshold values (You can adjust these based on your requirements)
float pHThresholdLow = 6.5;               // Lower pH threshold
float pHThresholdHigh = 8.0;              // Upper pH threshold
int turbidityThreshold = 300;             // Turbidity threshold (analog value)
int waterLevelThreshold = 500;            // Water level threshold (analog value)

// Variables
float pHValue;
int turbidityValue;
int waterLevelValue;
float temperatureValue;

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);

  // Initialize the OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Initialize OLED with I2C address 0x3C
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);  // Loop forever if the display initialization fails
  }
  
  // Clear the display
  display.clearDisplay();
  display.display();

  // Initialize the DS18B20 temperature sensor
  sensors.begin();

  // Set pin modes for the relay, buzzer, etc.
  pinMode(RELAY_SOLENOID_PIN, OUTPUT);
  pinMode(RELAY_PUMP_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Turn off relays and buzzer