Adventures with Arduino Part 22

 

My plan now is to combine the use of the Moisture sensor from my previous post in this series with the LCD display.

Directing output to the display should be simple as there is a function where you redirect where you want something to go.

Serial print and lcd print, should go to the respective so

Serial.println("Soil moisture sensor");

 

directs out put to the serial port,  where as

lcd.print("Arduino Sketch");

Should send output to the LCD screen,  if I then adjust what is displayed it should be possible to create a project that if the probe is inserted in to a plant pot, to get a readout on how much moisture is in the pot soil.

 

My code for this so far is

// Soil Moisture Sensor Hygrometer example code
// Code author:  aafent. This code is copy free, if you want please mention the author's name and/or the site
//Interface Description (4-wire)
//VCC: 3.3v-5v
//GND: GND
//DO: Digital output interface (0 and 1) threshold taken from potentiometer
//AO: Analog output interface
 
// include the library code:
#include <LiquidCrystal.h>
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
 
const int moistureAO = 0;
 
int AO = 0;
int tmp = 0;
int LED = 13;
 
 
 
void setup (){
  Serial.begin(9600);
  Serial.println("Soil moisture sensor");
  pinMode(moistureAO, INPUT);
 
  // set up the LCD's number of columns and rows: 
 
  //legacy code - for testing
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print("Torbay Tech Jam");
  //lcd.setCursor(0,1);
  //lcd.print("November 2015");
  //delay(2000);
 
 
 
}
void loop ()
{
  tmp=analogRead( moistureAO );
  if ( tmp != AO ) 
  {
    AO=tmp;
    Serial.print("A=");
    Serial.println(AO);
    lcd.begin(16, 2);
    lcd.print("A=");
    lcd.println(AO);
    delay(2000);
  }
 
  delay (1000);
    {
if(analogRead(0) > 900){ // depends on soil moisture
 
 
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,HIGH);
}else{
digitalWrite(LED, LOW);
}
    }
}

 

Which prints A0= value on A0 on the lcd display,  the next step from this is to do something with the values, so as with the LED code:

if(analogRead(0) > 900){ // depends on soil moisture
 
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,HIGH);
}else{
digitalWrite(LED, LOW);
}
    }
}

The next step is to print either “wet” or “dry” on the lcd display depending on the value written.

In the meantime.  With the probes shorted by my fingers I get a value of 499,  otherwise I get 1022.  Which gives a range of 498.   I can therefore use these values to display wet or dry as above.

I will update this post when I have figured out how to do this.  In the meantime I can the project so far at the next tech jam on the 14th November.