Skip to content

Instantly share code, notes, and snippets.

@elktros
Created December 26, 2018 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/8a2ef231c99d4328e57e35077d368919 to your computer and use it in GitHub Desktop.
Save elktros/8a2ef231c99d4328e57e35077d368919 to your computer and use it in GitHub Desktop.
Code for Interfacing Soil Moisture Sensor with Arduino.
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int j=0;
int prev=0;
int pres=0;
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(" Soil Moisture ");
Serial.begin(9600);
}
void loop()
{
j=analogRead(A0);
j=map(j,0,982,148,0);
pres=j;
if(j>100)
j=100;
else if(j<0)
j=0;
lcd.setCursor(6,1);
lcd.print(j);
lcd.print("% ");
prev=j;
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment