by Adwoa Asare

August 8th 2019

Materials

  • Water Pump (5v)
  • DHT22
  • MOSFET
  • Non-Corrosive Soil Moisture Sensor
  • Silicone Sealant
  • Hot Glue/ Hot Glue Gun
  • Acrylic Cement
  • Laser Cutter
  • Basic Hand/ Electrical Tools
  • Scotch Tape
  • Disposable Gloves (for when you are gluing/ sealing)
  • (2) LED strips
  • 22 Gauge Wire
  • 1/4 inch tubing
  • Super Glue
  • Arduino Nano (an Uno would also work)

The Process

solderedPump

WaterPump:

  1. Solder the water pump. Connect the red wire to the terminal with the red dot next to it.
  2. Apply heat-shrink around the connections between the pump and the wiring.
  3. The pump needs to have its positive terminal connected to the 5V output on the arduino and its negative terminal connected to drain on the transistor.
  4. Heat Shrink the wire ends
  5. The ground of the transistor should be connected to the digital 3 pin on the arduino and the source should be connected to the ground of the arduino

More details for how to use a FET Transistor can be found here

DHT22:

tempSensor

The DHTXX series of sensors are used to measure temperature and humidity. They generally have four pins, and the third one is not used.

  1. Connect the 1st pin to 5 volts, the second pin to arduino digital pin 2, and the fourth pin goes to ground (as seen in the above picture)
  2. Tape the senor down to a surface to make it easier to solder
  3. Apply Heat Shrink

Soil Moisture Sensor

soilSensorSetup

  1. Cut off the plug in end of the wires and strip them
  2. Sauter red to 5 volts, black to ground, and blue to analog 0
  3. The sensor needs to be calibrated **

Water Level Sensor

I didn’t want the pump to run if the water tank was empty so I used capacitive measurement to determine whether or not there was water in the tank.

I cut two small rectangular pieces of copper tape and soldered a wire to each. I taped them to the bottom outside corner of the water tank. One wire went to analog pin 4 and the other to digital pin 4.

LEDs

The LED strips are labeled so it should be pretty obvious what to sauter… Attach one of them to digital pin 6 and one to digital pin 7.

Laser Cutting (… and some drilling)

Here are my dxf files:

I set the laser cutter to 60% power and speed 7

AcrylicConstruction

Pump holder: pumpHoldAcrylic

Gluing/ Sealing

You need acrylic cement to weld the pieces of acrylic together acrylicCement sealing

  1. Set the box up without gluing it first to get a feel of what is a good order to put the pieces together
  2. Label the outside of the pieces with tape to make sure you put it together in the correct orientation
  3. Using a paint brush (or in my case a cotton swab attached to a clothespin) apply acrylic cement to both of the surfaces you want to connect
  4. Put the two glued pieces together, then repeat until it’s done.

Wiring/ Tubing

I secured the tubing to the hole at the bottom of the tank using hot glue which worked surprisingly well. Then I attached that to the pump in and another tube from the pump out to the soil container. I also poked holed near the watering opening of the tube so the water woulb be better dispersed through the soil.

To keep sil from getting in the tubing i put a piece of colth over it and duct taped it to the end of the tube at the opening.

I did all the wiring on the outside using strips copper tape and using 22 gauge wire to make bridges. I used electrical tape over my soldering work to keep it from pulling. The wiring is fun because you can get creative with how you arrange the wires as long as you pat attention to the connections!

om the imside of the bottom of the pot I put 2 copper strips, one for 5 volts and one for ground.

finishedProj1

Difficulties In the Process

  • When sealing the acrylic tank to make it water proof I got a lot of leaks. It was very hard to get all of them and I eventually had to use a straw that I stuck through the water refill opening to apply sealant to the inside of the tank. I think it would probably be best to seal as much of it as possible before closing it!
  • When the wires pull on their connections it starts to tear and pull up the copper tape. My solution to this was putting electrical tape over the connections
  • It would probably be best to put a coat of acrylic or epoxy over the outside of the finished product
  • Never trust an Arduino Nano that was soldered by someone else… ever

The Code

Click to download my ino (arduino) file.


// REQUIRES the following Arduino libraries: (Tools>>Manage Libraries)
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor//++++++++++++++++++++ ANALOG AND DIGITAL IDS +
int tempSensor = 2;//DigitalPin_2
int waterPump = 3;//DigitalPin_3

int tempLEDpin = 6;// DigitalPin_6
int humidityLEDpin = 7;//DigitalPin_7
int soilPin = A0;//AnalogPin_0
int waterLevel = A4;//AnalogPin_4
#include <Adafruit_NeoPixel.h>
#include "DHT.h"
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht = DHT(tempSensor, DHTTYPE);
// initialize the library with the numbers of the interface pins
Adafruit_NeoPixel tempLEDs(5, tempLEDpin, NEO_GRB + NEO_KHZ800);//(number of leds in string, pin, type of led string)
Adafruit_NeoPixel humidLEDs(5, humidityLEDpin, NEO_GRB + NEO_KHZ800);
//++++++++++++++++++ DATA +++++++++++
const int AirValue = 550;   //you need to replace this value with Value_1
const int WaterValue = 150;  //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue) / 3;
int soilMoistureValue = 0;
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
long waterL;   //variable for the result of the tx_rx measurement.
boolean empty = true;
/*int sensorVal;
  unsigned long DELAY_TIME = 10000; // 10.00 sec
  unsigned long delayStart = 0; // the time the delay started
  bool delayRunning = false; // true if still waiting for delay to finish
  bool pumpOn = false; // keep track of the led state
*/
void setup() {
  // =====SENSORS======
  dht.begin();
  pinMode(4, OUTPUT);

  //=====ACTUATORS=====
  tempLEDs.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  tempLEDs.show();            // Turn OFF all pixels ASAP
  humidLEDs.begin();
  humidLEDs.show();
  pinMode(waterPump, OUTPUT);
  tempLEDs.setBrightness(25);
  humidLEDs.setBrightness(25);

  //=====OTHER=====
  Serial.begin(9600);
  /* pumpOn = false;

    // Start Delay:
    delayStart = millis();
    delayRunning = true;
  */
}//void setup()

/** VOID LOOP
   1. check water level
   2. check humidity & temp. set LEDs
   3. check if soil needs to be watered


*/
void loop() {
  /**
     1. check WATER LEVEL in storage tank
  */
  waterL = tx_rx();
  Serial.println();
  Serial.print("Water Level: "); Serial.print(waterL);
  Serial.println();
  if (waterL < 10)
    empty = true;
  else
    empty = false;
  /**
     2. check HUMIDOTY & TEMP, set LEDs accordingly
  */
  tempHumidityRead();
  /**
     3. WATERING SOIL
  */
  if (empty == false) {
    soilMoistureValue = 0;
    for (int x = 0; x < 20; x++) {
      soilMoistureValue += analogRead(soilPin);
    }
    soilMoistureValue = soilMoistureValue / 20;
    
    
    if (soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
    {
      Serial.println("Soil Moisture: Very Wet");
      digitalWrite(waterPump, LOW);
    }
    else if (soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
    {
      Serial.println("Soil Moisture: Wet");
      digitalWrite(waterPump, LOW);
    }
    else if (soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
    {
      Serial.println("Soil Moisture: Dry");
      digitalWrite(waterPump, HIGH);
      delay(5000);
    }
    else {
      Serial.println("unknown soil moisture ");
      digitalWrite(waterPump, LOW);
    }
  }
  delay(100);

}//void loop()
/**
   measures capacitance for 100 samples and averages data to reduce noise
   @return average out inputs from capacitive measurement
*/
long tx_rx() {        //Function to execute rx_tx algorithm and return a value
  //that depends on coupling of two electrodes.
  //Value returned is a long integer.
  int read_high;
  int read_low;
  int diff;
  long int sum;
  int N_samples = 100;    //Number of samples to take.  Larger number slows it down, but reduces scatter.
  sum = 0;
  for (int i = 0; i < N_samples; i++) {
    digitalWrite(4, HIGH);             //Step the voltage high on conductor 1.
    read_high = analogRead(waterLevel);        //Measure response of conductor 2.
    delayMicroseconds(100);            //Delay to reach steady state.
    digitalWrite(4, LOW);              //Step the voltage to zero on conductor 1.
    read_low = analogRead(waterLevel);         //Measure response of conductor 2.
    diff = read_high - read_low;       //desired answer is the difference between high and low.
    sum += diff;                       //Sums up N_samples of these measurements.
  }//for (int i = 0; i < N_samples; i++)
  return sum / N_samples;
}                         //End of tx_rx function.
/**
   reads humidity and temp then sets variables
*/
void tempHumidityRead() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }//if any values are null
  else {
    temperature = (int)t;
    humidity = (int)h;
    int rcolor = random (0, 255);
    int gcolor = random (0, 125);
    int bcolor = random (0, 255);
    //TEMPERATURE
    if (temperature >= 0) {
      for (int i = 0; i < (temperature / 10); i++) {
        tempLEDs.setPixelColor(i, tempLEDs.Color(rcolor, gcolor, 0));
      }//for each led
      tempLEDs.show();
    }//temperature>0
    else {
      for (int i = 0; i < (abs(temperature / 10)); i++) {
        tempLEDs.setPixelColor(i, tempLEDs.Color(rcolor, gcolor, 0));
      }//for each LED
      tempLEDs.show();
    }//temperature<0
    //HUMIDITY
    for (int i = 0; i < (humidity / 20) - 1; i++) {
      humidLEDs.setPixelColor(i, humidLEDs.Color(rcolor, gcolor, bcolor));
    }//for each LED
    humidLEDs.show();
  }//values not null


  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));


}