Timothy & Ryan’s Water Level Sensor

Description

For our sensor and display project, we made a circuit that uses the moisture sensor as a means to determine the water level of a sample of dirt.  While out of the water, the display would say that the water level is low due to the lack of water as well as have a green LED blink.  When in the water the LCD would out print a number based on how much water was present and state the water level was high once past a certain threshold.

Code

// Portion of code borrowed from https://github.com/jlooper/thinglearn/blob/master/moisture-sensor.txt
// Portion of code borrowed from https://interactivematerials.wordpress.com/resources/

#include <SoftwareSerial.h>

SoftwareSerial lcd = SoftwareSerial(2,3);

//moisture sensor ints
int sensorPin = A0;
int led = 13;
int thresholdUp = 400;
int thresholdDown = 250;

void setup() {
//LCD startup
lcd.begin(9600);

//clearing screen
lcd.write(0xFE);
lcd.write(0xD0);

//color
lcd.write((uint8_t)0); //red
lcd.write((uint8_t)0); //green
lcd.write((uint8_t)255); //blue
delay(10); //time to adjust the backlight

//Moisture Sensor
Serial.begin(9600);
pinMode(led, OUTPUT);

}

void loop() {

int sensorValue;

sensorValue = analogRead(sensorPin);

Serial.println(sensorValue);
//clear screen
lcd.write(0xFE);
lcd.write(0x58);

if (sensorValue <= thresholdDown){
//clearing screen
lcd.write(0xFE);
lcd.write(0x58);

lcd.println(“Low Water”);
lcd.print(sensorValue);
lcd.print(” Moisture”);

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);

} else if (sensorValue >= thresholdUp){
//clearing screen
lcd.write(0xFE);
lcd.write(0x58);

lcd.println(“High Water”);
lcd.print(sensorValue);
lcd.print(” Moisture”);
}
delay(1000); //wait for a second, easier to read

}

Video

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s