SOIL MOISTURE MONITOR USING ARDUINO

COMPONENTS NEEDED

1. Arduino NANO
2. Soil moisture sensor module
3. OLED display module
4. Jumper wires
5. Breadboard (optional)

CIRCUIT DIAGRAM

Connections

Connect the VCC pin of the soil moisture sensor to the 5V pin on the Arduino.
Connect the GND pin of the soil moisture sensor to the GND pin on the Arduino.
Connect the A0 pin of the soil moisture sensor to the A0 pin on the Arduino.
Connect the SDA and SCL pins of the OLED display to the corresponding SDA and SCL pins on the Arduino NANO (A4 and A5 on Arduino NANO).

ARDUINO CODE


#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
int soil;
int percentage;
void setup() {
  u8g2.begin();
  u8g2.setFont(u8g2_font_t0_12b_mr );
  u8g2.setCursor(30, 16);
  u8g2.print("SOIL");
  u8g2.setCursor(37, 32);
  u8g2.print("METER");
  u8g2.sendBuffer();
  delay(6000);
}
void loop() {
  soil=analogRead(A0); //connect sensor to A0 pin of Arduino
  percentage= map(soil,1023,0,0,100);
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_maniac_tr);
  u8g2.setCursor(1, 30);
  u8g2.print(" ");
  u8g2.println(percentage);
  u8g2.setFont(u8g2_font_maniac_tr);
  u8g2.setCursor(60, 30);
  u8g2.print(" % ");
  u8g2.sendBuffer();
  delay(1000);
}
  

Leave a comment