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

Codee

Uploaded by

Ikhlass Bn
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)
6 views

Codee

Uploaded by

Ikhlass Bn
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 <WiFi.

h>

#include <BlynkSimpleEsp32.h>

#include <OneWire.h>

#include <DallasTemperature.h>

// Blynk Auth Token

char auth[] = "Your_Blynk_Auth_Token";

// WiFi credentials

char ssid[] = "Your_SSID";

char pass[] = "Your_PASSWORD";

// Pin Definitions

#define TRIG_PIN 12

#define ECHO_PIN 14

#define DS18B20_PIN 4

#define PH_PIN 35

#define IN1_PIN 26

#define IN2_PIN 27

// Blynk Virtual Pins

#define V_TEMP_C 2

#define V_TEMP_F 3

#define V_PH 4

#define V_WATER_LEVEL 1

#define V_PUMP_CONTROL 5

// Sensor Setup

OneWire oneWire(DS18B20_PIN);

DallasTemperature sensors(&oneWire);
// Pump Control

bool pumpState = false;

// Function Prototypes

float readWaterLevel();

float readPH();

void checkTemperature(float tempC);

void checkPH(float phValue);

void controlPump(float waterLevel);

void setup() {

Serial.begin(115200);

Blynk.begin(auth, ssid, pass);

// Sensor Initialization

sensors.begin();

// Motor Driver Pins

pinMode(IN1_PIN, OUTPUT);

pinMode(IN2_PIN, OUTPUT);

// Trigger pin setup for ultrasonic sensor

pinMode(TRIG_PIN, OUTPUT);

pinMode(ECHO_PIN, INPUT);

void loop() {

Blynk.run();
// Read Temperature

sensors.requestTemperatures();

float tempC = sensors.getTempCByIndex(0);

float tempF = (tempC * 9.0 / 5.0) + 32.0;

// Read pH value

float phValue = readPH();

// Read Water Level

float waterLevel = readWaterLevel();

// Send data to Blynk

Blynk.virtualWrite(V_TEMP_C, tempC);

Blynk.virtualWrite(V_TEMP_F, tempF);

Blynk.virtualWrite(V_PH, phValue);

Blynk.virtualWrite(V_WATER_LEVEL, waterLevel);

// Check conditions

checkTemperature(tempC);

checkPH(phValue);

controlPump(waterLevel);

delay(2000); // Adjust delay as needed

float readWaterLevel() {

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

long duration = pulseIn(ECHO_PIN, HIGH);

float distance = (duration * 0.034 / 2); // Distance in cm

return distance;

float readPH() {

// Placeholder for pH reading logic

// Replace with actual pH sensor reading code

return analogRead(PH_PIN) * (5.0 / 1023.0); // Example conversion

void checkTemperature(float tempC) {

if (tempC > 30.0) {

Blynk.notify("Temperature Alert: Above 30°C!");

} else if (tempC < 20.0) {

Blynk.notify("Temperature Alert: Below 20°C!");

void checkPH(float phValue) {

if (phValue < 6.5 || phValue > 7.5) {

Blynk.notify("pH Alert: Out of range (6.5 - 7.5)!");

void controlPump(float waterLevel) {

if (waterLevel < 10.0) {

pumpState = true;
} else if (waterLevel > 50.0) {

pumpState = false;

if (pumpState) {

digitalWrite(IN1_PIN, HIGH);

digitalWrite(IN2_PIN, LOW);

} else {

digitalWrite(IN1_PIN, LOW);

digitalWrite(IN2_PIN, LOW);

// Blynk control for manual pump operation

BLYNK_WRITE(V_PUMP_CONTROL) {

int value = param.asInt();

pumpState = value;

if (pumpState) {

digitalWrite(IN1_PIN, HIGH);

digitalWrite(IN2_PIN, LOW);

} else {

digitalWrite(IN1_PIN, LOW);

digitalWrite(IN2_PIN, LOW);

You might also like