My Soil Moisture Sensor analog reading are low

Hello, I'm new in Arduino. The project that I doing now is soil moisture sensor that use Arduino Uno board and ESP8266-01 module to send data into database (Using XAMPP). The code that I upload was fine and I'm using Generic ESP8266 Module 3.0 board. The problem that I encounter is the analog reading is too low and not accurate. The normal reading for the dry soil is 1023 , and I get average after 10 reading is 195.6. And when the soil is wet until the red led bright up, the reading remains 130-150. I try to find a solution but did not bumped into one. So I try to ask in this forum for answer and if possible to get some advice.

This is my connection for Arduino Uno and ESP8266-01 Module:

This is my conecction for Soil Moisture Sensor and Arduino Uno.
VCC – 5V
A0 – A0

This is my code :

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266mDNS.h>

const char *ssid = "x";  //ENTER YOUR WIFI SETTINGS
const char *password = "x";
char server[] = "x";
  int j=0;
  float prev=0;
  float percentage = 0.0;

WiFiClient client;
//                    Power on setup

void setup() {
  // Connect to WiFi network
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  // Start the server
//  server.begin();
  Serial.println("Server started");

//                    Main Program Loop
void loop() {
  Serial.println("Attempt 1");
  j=analogRead(A0); //read from pin a0
  Serial.print("analog read:");

  percentage = map(j,1023,368,0,100); //map(analogvalue,drysoilanalogreading,wetsoilanalogreading,0,100);

  else if(percentage<0){
  Serial.print("Value prev: ");
  delay(60 * 1000);  //GET Data at every 1 minutes

// Sending data into database
void Sending_To_phpmyadmindatabase()   //CONNECTING WITH MYSQL
    if (client.connect(server, 80)) {
    // Make a HTTP request:
    Serial.print("GET x");
    client.print("GET x");     //YOUR URL
    client.print(" ");      //SPACE BEFORE HTTP/1.1
    client.println("Host: x");
    client.println("Connection: close");
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");

If there's any information that you want just comment, Thank You very much for your help.

In the long term this will fry your ESP module as it isn't 5V tolerant (it runs on 3.3V).

You must edit your post and enclose your code with code tags. You can see yourself what happens otherwise.

Depending on the type of sensor you have (you failed to post a link to it!) this may be a correct value.

That may be a bad sensor, a already broken sensor (cheap soil moisture sensors corrode extremely fast, often within days) or a bad wiring. With have no clue about any of these conditions and so we cannot help you further without much more information from your side.

1 Like

Hello pylon,I run my ESP module using 3.3V , sorry for the wrong information. This is my first time using this forum, thank you for the advice and yes I using the common soil moisture sensor (cheap one). If I upload the code into Arduino Uno board, the soil sensor are working fine, but if I using the Generic ESP8266 Module board (the first problem that I encounter is cannot upload the code but after that I follow this video : Easy way to program an ESP8266 - YouTube). Even after successfully upload the code, the analog reading start to have problem like I mentioned previously. Thank you!

I know but you connect RX/TX directly. Arduino has 5V on them but ESP will be damaged if you put 5V on any input pin.

The posted code should not compile for the Arduino UNO.

Sure, because that code reads the A0 input of the ESP8266 and not the one of the Arduino UNO. So it's reading a floating pin which will return a more or less random value.

1 Like

hello again pylon, sorry for the late reply. Thank you for the further explanation. Do you have any solution for this matter? or some source that I can read and help me to solve this problem. I just need to send the data from the sensor into database. Thank you very much!

Tell me why you need the UNO. Why don't you just put the sensor to the ESP and send the value directly from there. You must check the input voltages (voltage divider if needed) but it would remove the complexity.

1 Like

Thank you for your help, I think I gonna buy nodemcu for this project. Its to complicated using ESP9266-01 module for me. Thank you for you help pylon

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.