Capacitive Soil Moisture Sensor with OLED Display & Arduino
In this tutorial, we are about to interface Capacitive Soil Moisture Sensor with OLED & Arduino to display the soil moisture value in percentage (%). Here we will display the value in both Serial Monitor and 0.96″ OLED Display. We will also teach you the calibration method for displaying the correct value.
Components :
1)SSD1306 Display :https://roboman.in/qcjs
2) TP-4056 Module : https://roboman.in/oa0m
3) Capacitive Soil moisture sensor: https://roboman.in/diLp
4) MT 3608 Boost converter : https://roboman.in/xdcw
5) Arduino Nano: https://roboman.in/59h4
6) Arduino Nano Type C : https://roboman.in/xkfu
Diagram:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_WIDTH 128 #define OLED_HEIGHT 64 #define OLED_ADDR 0x3C #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT); //Adafruit_SSD1306 display(OLED_RESET); const int AirValue = 620; //you need to replace this value with Value_1 const int WaterValue = 310; //you need to replace this value with Value_2 int soilMoistureValue = 0; int soilmoisturepercent=0; void setup() { Serial.begin(9600); // open serial port, set the baud rate to 9600 bps display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) display.clearDisplay(); } void loop() { soilMoistureValue = analogRead(A0); //put Sensor insert into soil Serial.println(soilMoistureValue); soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100); if(soilmoisturepercent > 100) { Serial.println("100 %"); display.setCursor(45,0); //oled display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //oled display display.setTextSize(3); display.setTextColor(WHITE); display.println("100 %"); display.display(); delay(250); display.clearDisplay(); } else if(soilmoisturepercent <0) { Serial.println("0 %"); display.setCursor(45,0); //oled display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //oled display display.setTextSize(3); display.setTextColor(WHITE); display.println("0 %"); display.display(); delay(250); display.clearDisplay(); } else if(soilmoisturepercent >0 && soilmoisturepercent < 100) { Serial.print(soilmoisturepercent); Serial.println("%"); display.setCursor(45,0); //oled display display.setTextSize(2); display.setTextColor(WHITE); display.println("Soil"); display.setCursor(20,15); display.setTextSize(2); display.setTextColor(WHITE); display.println("Moisture"); display.setCursor(30,40); //oled display display.setTextSize(3); display.setTextColor(WHITE); display.println(soilmoisturepercent); display.setCursor(70,40); display.setTextSize(3); display.println(" %"); display.display(); delay(250); display.clearDisplay(); } } |
Good day! I just wish to give you a huge thumbs up for your excellent information you have got here on this post. I am coming back to your blog for more soon. Good day! I just wish to give you a huge thumbs up for your excellent information you have got here on this post. I am coming back to your blog for more soon. נערות ליווי בהרצליה