hillac1993
Published © GPL3+

Output Capacitive Moisture as percentage on Serial and LCD

Using a capacitive moisture sensor (v1.2), output analogue data to Serial and LCD as a percentage using Hello World example as a base.

BeginnerFull instructions provided215
Output Capacitive Moisture as percentage on Serial and LCD

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
SparkFun Serial Enabled 16x2 LCD - White on Black 3.3V
SparkFun Serial Enabled 16x2 LCD - White on Black 3.3V
Came with Arduino starter kit; unsure if this is the same brand or what but from what I can tell, they're all mostly the same
×1
Capacitive Moisture Sensor (v1.2)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing file

Fritzing compatible file containing breadboard design, schematic and code.

Breadboard design

Schematic

Code

Code

Arduino
// include LCD library
#include <LiquidCrystal.h>

// define constants for wet and dry sensor
const int dry = 595; // value for dry sensor
const int wet = 239; // value for wet sensor
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // define pins corresponding with the above setup
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // define which pins on the LCD are being used
  

void setup()
{
  Serial.begin(9600); // set serial monitor so values can be monitored via IDE
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.print("Soil Moisture: "); // Print a message to the LCD.
  
  // set up LCD pins as follows (also see: https://www.arduino.cc/en/Tutorial/LibraryExamples/HelloWorld for setup of LCD):
  // LCD RS pin to digital pin 12
  // LCD Enable pin to digital pin 11
  // LCD D4 pin to digital pin 5
  // LCD D5 pin to digital pin 4
  // LCD D6 pin to digital pin 3
  // LCD D7 pin to digital pin 2
  // LCD R/W pin to GND
  // LCD VSS pin to GND
  // LCD VCC pin to 5V
  // LCD LED+ to 5V through a 220 ohm resistor
  // LCD LED- to GND

}

void loop()
{
  lcd.setCursor(0, 1); // set the LCD cursor to column 0, line 1

  int sensorVal = analogRead(A0); // output analogue value as integer
  int percentageHumididy = map(sensorVal, wet, dry, 100, 0); // set analogue value as percentage between 0% and 100%
  Serial.print(percentageHumididy); // print output
  Serial.println('%'); // add "%" sign after output to display as percentage

  // SO FAR, THIS PRINTS VALUES IN THE SERIAL MONITOR. NOW WE HAVE TO PRINT TO THE LCD. Above, LCD library should be included in program.

  lcd.print(percentageHumididy); // print the sensor value on LCD:
  lcd.print('%'); // add "%" sign after output to display as percentage

  delay(100); // restart loop after 1 second
}

Credits

hillac1993

hillac1993

0 projects • 0 followers

Comments