#include <U8glib.h> // Version 1.19.1
# define font u8g.setFont(u8g_font_helvB08) // set font One for oled display
byte Scroll = 4 ; // Scroll Text x axis
int soilHumVal = 0 ; // for reading analog value from Soil Humidity Sensor's Analog output
const byte soilHumA = A1 ; // pin for Soil Humidity Sensor's ANALOG Output Signal Pin it gives raw voltage values
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
unsigned long secs = 0;
void setup()
{
Serial.begin(9600);
pinMode(soilHumA, INPUT) ;
analogReference(DEFAULT);
Start();
delay(2000);
soilHumCalc() ;
}
void Start()
{
u8g.firstPage(); // START SCREEN "Picture loop" for OLED
do
{
font;
u8g.drawFrame(10, 12, 108, 31); // Draw Frame and it's Size
u8g.drawFrame(0, 0, 128, 64); // Draw Frame and it's Size
u8g.drawStr(15, 25, "Soil Humidity"); // Draw a string
u8g.drawStr(85, 32, "V 1.0");
u8g.drawStr( 37, 40, "Meter");
u8g.drawStr(53, 60, "Made by:AMK");
}
while ( u8g.nextPage() );
}
//####################################
// Function for Reading Soil Humidity#
//####################################
void soilHumCalc()
{
soilHumVal = analogRead(soilHumA);
Serial.print("Raw 10-bit Number Value : ");
Serial.println(soilHumVal );
soilHumVal = map(soilHumVal, 1023, 0, 0, 100);
Serial.print("Percentage Value : " );
Serial.println(soilHumVal );
if(soilHumVal<3) soilHumVal=0;
}
//############
// Loop #####
//############
void loop()
{
delay(200);
soilHumCalc() ;
delay(200);
u8g.firstPage();
do
{
u8g.setColorIndex(1);
u8g.drawFrame(0, 0, 128, 20); // Draw frame
u8g.drawFrame(0, 22, 128, 42); // Draw fram
if(millis()- secs > 100)//Check Timer
{
Scroll = Scroll -1; // Minus 1
Scroll--;// Minus 1
secs=millis(); //Reset Timer
}
font;
u8g.setPrintPos(Scroll, 14);
u8g.print( "YouTube.com/CrazyGuy/Official");
u8g.setPrintPos(4, 34);
u8g.print( "Moisture");
if(soilHumVal>18)
{
u8g.setPrintPos(113, 34);
if(soilHumVal < 30)
{
u8g.print("M");
}
else
{
u8g.print("H");}
}
u8g.setFont(u8g_font_osr18); // set font for oled display
u8g.setPrintPos(102, 59);
u8g.print("%");
if(soilHumVal>30)
{
u8g.drawBox(52,36,49,25);
u8g.setColorIndex(0);
}
u8g.setPrintPos(51, 59);
u8g.print(soilHumVal);
}
while ( u8g.nextPage() );
}
Do-it-yourself,DIY,How-To,Electronics,Arduino,Esp,Raspberry-Pi,Programming,Hacking Stuff,Gardening,Photography,Hobby,Fun
DIY Use Soil Moisture Sensor,Oled,Arduino,Breadboard,Battery Part 01
Subscribe to:
Posts (Atom)