UNO Version

Simplified Pump Program using Arduino UNO

 

const int sensorPin = A0; // Pin that the sensor is connected to

const int pumpPin = 8; // pin that turns on the transistor that drives the pump

const int threshold = 400;// the threshold level between ‘dry’ and moist

 

/*-----------sets up optional DHT-11 humidity/temp sensor----*/

 

#include <DFRobot_DHT11.h> // sets up optional humidity/temp sensor

DFRobot_DHT11 DHT;

#define DHT11_PIN 10

 

/*------------sets up optional OLED display-------------*/

 

#include <SPI.h> // sets up optional OLED display

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

 

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

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

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

#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D

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

 

/*-------------setup for pump pin and display(optional)-----*/

 

void setup()

{

  // initialize the LED and pump pins as outputs:

  pinMode(pumpPin, OUTPUT);

  Serial.begin(9600);

 

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address

    Serial.println(F("SSD1306 allocation failed"));

  for (;;);

  }

}

 

  void loop() {

    // display sensor readings to the serial monitor

    int moisture = analogRead(sensorPin);

 

    DHT.read(DHT11_PIN);

    Serial.println("temp:");

    Serial.print(DHT.temperature);

    Serial.println("humi:");

    Serial.print(DHT.humidity);

    Serial.println(“moisture:”);
Serial.print(moisture);

  

    // if soil is dry, turn on the pump- edit code for timing

    if (moisture < threshold) {

      digitalWrite(pumpPin, HIGH);

    } else {

      digitalWrite(pumpPin, LOW);

    }

 

  // Display moisture on the OLED(optional)

  display.clearDisplay();

  display.setTextSize(2);

  display.setTextColor(WHITE);

  display.setCursor(0,0);

  display.println("Moisture=");

  display.setCursor(0, 20);

  display.println(moisture);

  display.display();


  delay(2000);


  }