0% found this document useful (0 votes)
43 views7 pages

WATERING Fertilizing

The document describes code for an automated plant watering and fertilizing system. It uses a soil moisture sensor to determine when to turn a water pump on or off. It also uses an NPK sensor and OLED display to measure and display nitrogen, phosphorus, and potassium levels in the soil. The code initializes the sensors and display, then enters a loop to read the sensors, display the readings, and water the plants as needed based on the soil moisture reading.
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)
43 views7 pages

WATERING Fertilizing

The document describes code for an automated plant watering and fertilizing system. It uses a soil moisture sensor to determine when to turn a water pump on or off. It also uses an NPK sensor and OLED display to measure and display nitrogen, phosphorus, and potassium levels in the soil. The code initializes the sensors and display, then enters a loop to read the sensors, display the readings, and water the plants as needed based on the soil moisture reading.
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/ 7

// WATERING

int WATERPUMP = 13; //motor pump connected to pin 13

int sensor = 8; //sensor digital pin vonnected to pin 8

int val; //This variable stores the value received from Soil moisture sensor.

void setup() {

pinMode(13,OUTPUT); //Set pin 13 as OUTPUT pin

pinMode(8,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.

//Initialize serial and wait for port to open:

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

while (! Serial);// wait for serial port to connect. Needed for native USB

Serial.println("Speed 0 to 255");

void loop()

if (Serial.available()) //loop to operate motor

int speed = Serial.parseInt(); // to read the number entered as text in the Serial Monitor

if (speed >= 0 && speed <= 255)

analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed

val = digitalRead(8); //Read data from soil moisture sensor

if(val == LOW)

{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value to motor pump
and motor pump goes off

else

digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to motor pump
and motor pump get on

delay(400); //Wait for few second and then continue the loop.

}
// SUPPLYING LIQUID FERTILIZER

include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define RE 8

#define DE 7

//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};

const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};

const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};

const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};

byte values[11];

SoftwareSerial mod(2,3);

void setup() {

Serial.begin(9600);

mod.begin(9600);

pinMode(RE, OUTPUT);

pinMode(DE, OUTPUT);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)

delay(500);
display.clearDisplay();

display.setCursor(25, 15);

display.setTextSize(1);

display.setTextColor(WHITE);

display.println(" NPK Sensor");

display.setCursor(25, 35);

display.setTextSize(1);

display.print("Initializing");

display.display();

delay(3000);

void loop() {

byte val1,val2,val3;

val1 = nitrogen();

delay(250);

val2 = phosphorous();

delay(250);

val3 = potassium();

delay(250);

Serial.print("Nitrogen: ");

Serial.print(val1);

Serial.println(" mg/kg");

Serial.print("Phosphorous: ");

Serial.print(val2);

Serial.println(" mg/kg");

Serial.print("Potassium: ");
Serial.print(val3);

Serial.println(" mg/kg");

delay(2000);

display.clearDisplay();

display.setTextSize(2);

display.setCursor(0, 5);

display.print("N: ");

display.print(val1);

display.setTextSize(1);

display.print(" mg/kg");

display.setTextSize(2);

display.setCursor(0, 25);

display.print("P: ");

display.print(val2);

display.setTextSize(1);

display.print(" mg/kg");

display.setTextSize(2);

display.setCursor(0, 45);

display.print("K: ");

display.print(val3);

display.setTextSize(1);

display.print(" mg/kg");

display.display();
}

byte nitrogen(){

digitalWrite(DE,HIGH);

digitalWrite(RE,HIGH);

delay(10);

if(mod.write(nitro,sizeof(nitro))==8){

digitalWrite(DE,LOW);

digitalWrite(RE,LOW);

for(byte i=0;i<7;i++){

//Serial.print(mod.read(),HEX);

values[i] = mod.read();

Serial.print(values[i],HEX);

Serial.println();

return values[4];

byte phosphorous(){

digitalWrite(DE,HIGH);

digitalWrite(RE,HIGH);

delay(10);

if(mod.write(phos,sizeof(phos))==8){

digitalWrite(DE,LOW);

digitalWrite(RE,LOW);

for(byte i=0;i<7;i++){

//Serial.print(mod.read(),HEX);

values[i] = mod.read();
Serial.print(values[i],HEX);

Serial.println();

return values[4];

byte potassium(){

digitalWrite(DE,HIGH);

digitalWrite(RE,HIGH);

delay(10);

if(mod.write(pota,sizeof(pota))==8){

digitalWrite(DE,LOW);

digitalWrite(RE,LOW);

for(byte i=0;i<7;i++){

//Serial.print(mod.read(),HEX);

values[i] = mod.read();

Serial.print(values[i],HEX);

Serial.println();

return values[4];

You might also like