arduinogeek15
Published

Automatic Plant Watrerotron

Waters the right amount of water with the push of a button.

IntermediateWork in progress297
Automatic Plant Watrerotron

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
TM1637 4digit 7segment display
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Power MOSFET N-Channel
Power MOSFET N-Channel
×1
Resistor 10k ohm
Resistor 10k ohm
×1
submersible water pump
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

schematic

Code

the code

Arduino
int z = 0;
int y;
int v = 0;
int m = 0;
int b = 0;
int j = 0;
int prev = 0;
int pres = 0;
int prev1 = 0;
int pres1 = 0;

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <TM1637Display.h>

#define CLK 9
#define DIO 8
TM1637Display display(CLK, DIO);
LiquidCrystal_I2C lcd(0x27, 16, 2);
unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(12, INPUT_PULLUP);
  lcd.begin();
  lcd.backlight();
  display.setBrightness(0xF);
  uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
  display.setSegments(data);
  lcd.setCursor(0, 0);
  lcd.print(" Soil Moisture  ");
}

void loop() {

  v = analogRead(A1);
  v = map(v, 0, 982, 139, 0);
  pres1 = v;
  int sensorVal = digitalRead(12);
  if (sensorVal == HIGH) {
    digitalWrite(3, LOW);
  } else {
    j = analogRead(A0);
    j = map(j, 0, 982, 139, 0);
    pres = j;
    if (j > 98) {
      j = 100;
    }
    b = j;
    lcd.setCursor(6, 1);
    lcd.print(j);
    lcd.print("%");
  }

  while (b != 0 || b < 0 ) {
    int c = 100 - b;
    Serial.print("moisture = ");
    Serial.println(j);
    Serial.print("Integer val ");
    Serial.println(b);
    Serial.print("timer ");
    Serial.println(c);
    int d = c * 10;
    
    for ( z = 0; z <= d; z++ ) {
      Serial.print("count ");
      Serial.println(z);
      digitalWrite(3, HIGH);
      m = d - z;
      display.showNumberDec(m, false);

      if (z == d) {
        b = 0;
        digitalWrite(3, LOW);

      }
    }
  }
} 


/*
Title : Science Exibition Final Code
Created on : 2 December 2019
*/

Credits

arduinogeek15

arduinogeek15

0 projects • 0 followers

Comments