0% found this document useful (0 votes)
9 views

arduino modefied

The document is an Arduino sketch for monitoring water quality using pH, TDS, and turbidity sensors. It controls multiple pumps based on sensor readings and runs a series of stages with timed delays. The program checks the water quality every hour and adjusts the pump operations accordingly to maintain optimal conditions.

Uploaded by

botaassamy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

arduino modefied

The document is an Arduino sketch for monitoring water quality using pH, TDS, and turbidity sensors. It controls multiple pumps based on sensor readings and runs a series of stages with timed delays. The program checks the water quality every hour and adjusts the pump operations accordingly to maintain optimal conditions.

Uploaded by

botaassamy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <EEPROM.

h>

#include "GravityTDS.h"

#include "DFRobot_PH.h"

#define TdsSensorPin A1

#define PH_SENSOR_PIN A0

#define TURBIDITY_SENSOR_PIN A2

float PH_7_VOLTAGE = 3.69;

float PH_4_VOLTAGE = 4.1;

float OFFSET = 0.00;

GravityTDS gravityTds;

float tdsValue = 0;

int pump12 = 2;

int pump1 = 3;

int pump2 = 4;

int pump3 = 5;

unsigned long lastRunTime = 0;

const unsigned long runInterval = 3600000; // 60 minutes

const unsigned long extraWait = 720000; // 12 minutes in ms

void setup() {

Serial.begin(9600);
pinMode(pump12, OUTPUT);

pinMode(pump1, OUTPUT);

pinMode(pump2, OUTPUT);

pinMode(pump3, OUTPUT);

gravityTds.setPin(TdsSensorPin);

gravityTds.setAref(5.0);

gravityTds.setAdcRange(1024);

gravityTds.begin();

lastRunTime = millis();

void loop() {

// Stage 1

digitalWrite(pump12, HIGH);

readDuringDelay(120000); // 2 minutes

digitalWrite(pump12, LOW);

readDuringDelay(240000); // 4 minutes

// Stage 2

digitalWrite(pump1, HIGH);

readDuringDelay(120000);

digitalWrite(pump1, LOW);

readDuringDelay(240000);
// Stage 3

digitalWrite(pump2, HIGH);

readDuringDelay(120000);

digitalWrite(pump2, LOW);

// Stage 4 check after 60 minutes

if (millis() - lastRunTime >= runInterval) {

float pHValue, turbidity;

readSensors(pHValue, turbidity);

if (pHValue > 6 && pHValue < 8 && tdsValue < 500 && turbidity < 5) {

digitalWrite(pump3, HIGH);

readDuringDelay(120000); // Run pump3 for 2 minutes

digitalWrite(pump3, LOW);

lastRunTime = millis(); // Reset timer

} else {

digitalWrite(pump12, HIGH); // Restart initial pump for 2 min

readDuringDelay(120000);

digitalWrite(pump12, LOW);

readDuringDelay(extraWait); // Wait 12 minutes before checking again

lastRunTime = millis(); // Reset timer after the delay

// Non-blocking delay that reads sensors every second


void readDuringDelay(unsigned long ms) {

unsigned long start = millis();

while (millis() - start < ms) {

float pHValue, turbidity;

readSensors(pHValue, turbidity);

delay(1000); // Read every second

// Reads all sensors and prints results

void readSensors(float &pHValue, float &turbidity) {

// pH Sensor

int sensorValue = analogRead(PH_SENSOR_PIN);

float voltage = sensorValue * (5.0 / 1023.0);

float PH_SLOPE = (PH_7_VOLTAGE - PH_4_VOLTAGE) / (7.00 - 4.00);

pHValue = 7.00 + ((voltage - PH_7_VOLTAGE) / PH_SLOPE) + OFFSET;

// TDS Sensor

gravityTds.update();

tdsValue = gravityTds.getTdsValue();

// Turbidity Sensor (custom calibrated)

int rawValue = analogRead(TURBIDITY_SENSOR_PIN);

float voltage_ty = rawValue * (5.0 / 1023.0);

turbidity = -49.02 * voltage_ty + 188.23;

if (turbidity < 0) turbidity = 0;


// Print readings

Serial.print("pH: ");

Serial.print(pHValue, 2);

Serial.print(" | TDS: ");

Serial.print(tdsValue, 0);

Serial.print(" ppm | Turbidity: ");

Serial.print(turbidity, 2);

Serial.println(" NTU");

You might also like