Soil Water Sensor
This is not a soil water sensor like most common ones. This sensor adds water to the soil, knowing how much water has been added to a small part of soil will result in knowing how much water was in the soil to begin with. This is purely for research purposes only since it used to measure water in samples.
Parts list:
- (1x) Arduino uno
- (1x) Breadboard
- (1x) USB cable (Type A male to Type B male)
- (12x) Male to Male wire
- (11x) Male to Female wire
- (2x) 10k ohm resistor
- (1x) PVC tube, diameter 50mm, length 350mm
- (1x) PVC tube, diameter 110mm, length 350mm
- (4x) Nail, length 4cm
- (1x) 5V relay
- (1x) 12V water pump
- (1x) LCD with module
- (1x) Ultrasonic sensor
- (2x) Water bucket
- (1x) Roll of duct tape (not much)
- (1x) Water hose, 1 meter
- (1x) Hose clamp
- (1x) Powerbank (Can also use laptop to supply power to the arduino, so powerbank is not essential)
Building the Circuit
The circuit consists out of 5 parts total:
- Two sets of nails, these will act as a switch.
- Ultrasound (distance) sensor.
- Relay switch.
- Water pump.
- LCD display screen, with module.
Before building any part of the circuit, one wire will go from the 5V pin of the arduino into the the + side of the breadboard and another wire will go from the ground pin (GND) to the - side of the breadboard (see red and blue wires leaving the arduino to the breadboard in the picture).
The first part is the build for the nailset, since there are two sets the setup will be identical. Requirements are 10 Male to Male wires and two 10k ohm resistors. Per set two wires go off to the nails in the tube, these are the blue lines shooting up out of the picture presented.
Setup for one set of nails (see picture for reference):
- Run one wire from + up into any breadboard pin on the breadboard.
- On the same line have one wire go to a nail.
- Move a few lines over and have the other wire from the remaining nail go into the breadboard.
- On this line on the breadboard have one side of the resistor put in and have another wire go from that line to a pin on the arduino, in this case it's either pin 12 or 13.
- On the line where the resistor ends, have a wire go from that line into the - side.
- That's the setup done for the first nailset, repeat for the second set.
The second part will be the ultrasound sensor (again for reference see the picture presented):
- The ultrasound sensor has got four pins: VCC, Trig, Echo and GND. Connect the VCC pin with the + side.
- Connect GND pin with the - side.
- Connect Trig and Echo to the pins on the arduino, in this case Echo is connected to pin 6 and Trig is connected to pin 7 on the arduino.
The relay switch circuit is equal to the setup of the ultrasound sensor:
- The relay has got 3 pins: the signal pin, VCC and GND.
- Again connect VCC and GND like done for the ultrasound sensor, VCC to + and GND to -.
- The signal pin will be connected to the arduino, pin 5 is the signal pin used in the setup.
The water pump has to be connected to the realy switch, this is done within a few steps:
- Connect the negative of the pump to the negative of the 12V adapter.
- Connect the positive of the pump to COM on the relay switch.
- Connect thet positive of the 12V adapter to NO on the relay switch.
Relay switch and pump are now working.
The last thing on the list for the circuit is the LCD screen and the module for a 4 pin setup. The LCD screen and module have 4 pins as explained, those are: VCC, GND, SDA and SCL.
- Connect the VCC and GND to the required pins, VCC to + and GND to - yet again.
- The arduino uno has pre-set pins for SDA and SCL, SDA will be connected to A4 (analog pin 4) and SCL to A5. This could be different for other boards, in that case look up the pins in the Wire Library.
Now that the circuit is build it's time to move on to the next thing which is the setup of the tube and nails.
The Water Tube
In the previous step the circuit has been build, in this step there are 4 wires which aren't connected to anything yet. This is the step where those wires will be connected to the nails.
The point of these nails is to act like a switch, when the water hits the nails the circuit will be closed and it will give of the signal to start pumping water and when to stop pumping water into the tube.
So now that the purpose of the nails is clear its on to the setup. The length of the tube (50 mm diameter tube) has to be 350 mm, the first set of nails have to be placed 100 mm down from the top and the second set has to be placed 50 mm down from the first set as shown in the picture.
Now that the nails are in place it's time to connect the wires to the nails, either solder the wire to the nail for a clean look or twist it around the nail and cover it with tape.
The other tube with a diameter of 110 mm is used for a double ring infiltration system, this used to control the water flow through the first tube and can be used to determine the water infiltration of the soil. The length of this tube is equal to the length of the other tube, so also 350 mm.
The Hose
Just is a very short step but necessary for the pump. The nozzle where the water comes out of needs to be connected to the hose, the hose will slide over the nozzle and the hose clamp will secure the hose on the nozzle.
The Code (arduino Uno)
#include <Wire.h> #include <LiquidCrystal_I2C.h> // constants won't change const int RELAY_PIN = 5; // the Arduino pin, which connects to the IN pin of relay const int echoPin = 6; // attach pin D2 Arduino to pin Echo of HC-SR04 const int trigPin = 7; //attach pin D3 Arduino to pin Trig of HC-SR04 // the setup function runs once when you press reset or power the board const int nailset1 = 12; // the number of the highest nail pin const int nailset2 = 13; // the number of the lowest nail pin int buttonState = 0; long duration; // variable for the duration of sound wave travel float distance1; // variable for the distance measurement float distance2; // variable for the distance measurement float Volume_reservoir; int percentage; int nailState1 = 0; // variable for reading the highest nail status int nailState2 = 0; // variable for reading the lowest nail status int TIJD; LiquidCrystal_I2C lcd(0x27,20,4); bool startMeting = false; void setup() { // initialize digital pin A5 as an output. pinMode(RELAY_PIN, OUTPUT); pinMode(buttonPin, INPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); lcd.init(); // initialize the lcd lcd.init(); // Print a message to the LCD. lcd.backlight(); lcd.setCursor(3,0); Serial.begin(9600); digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance1 = (float) duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back) // Displays the distance on the Serial Monitor Serial.print("Distance: "); Serial.print(distance1); Serial.println(" cm"); } // the loop function runs over and over again forever void loop() { nailState1 = digitalRead(nailset1); nailState2 = digitalRead(nailset2); if (nailState1 == LOW ) { digitalWrite(RELAY_PIN, HIGH); startMeting = false; // keep watering for 3 sec delay(3000); // turn off water digitalWrite(RELAY_PIN, LOW); delay(5000); } else { digitalWrite(RELAY_PIN, LOW); } if (nailState1 == HIGH && nailState2 == HIGH && startMeting == false) { TIJD = millis(); startMeting = true; } if ((TIJD-millis() > 30000) && startMeting == true){ digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance2 = (float) duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back) // Displays the distance on the Serial Monitor Serial.print("Distance: "); Serial.print(distance2); Serial.println(" cm"); delay(8000); Volume_reservoir = (distance2 - distance1)* 13* 13 * 3.1415926535897932384626433832795; Serial.print("Volume of reservoir: "); Serial.print(Volume_reservoir); Serial.println(" cm^3"); percentage = (1- ((Volume_reservoir-181.525)/217.83)) * 100; //15 cm sand, 12.5cm waterpins, 10 cm top Serial.print("Percentage: "); Serial.print(percentage); Serial.println(" %"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Percentage:"); lcd.setCursor(0,1); lcd.print(percentage); lcd.setCursor(14,1); lcd.print("%"); while(true) { //do nothing } } }
The Test Setup
With everything connected and wired up its time to upload the code to arduino and test it out.
Up first fill one bucket with enough water (roughly 15 cm), this will act as the reservoir and the pump will be laid in there. The second bucket will have a small layer of water at the bottom (roughly 2 cm) and on top of that a layer of sand (about 15 cm).
With the buckets filled up and in place the rest of the setup will be explained in short steps:
- Hang the ultrasound sensor over the edge of the water reservoir. This sensor needs to be held still, this could be done with a zip-ty for example.
- Lower the pump into the water reservoir.
- Push the 110 diameter tube into the sand until it reaches the bottom, do this for the other tube as well.
- Make sure everything is still connected and ready to be used.
- Plug in the 12V adapter to supply power for the pump.
- Connect the arduino to the powerbank and start the measurement.
At the end the LCD should give a percentage, this percentage is the initial percentage of water in the soil.