Soil moisture nodemcu


#1

Hello,

I just tested my hygrotrie project in the ground but I do not understand my values ​​returned by the sensor.

MY CODE

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial

#define Pin A0
#define VIRTUAL_PIN V1

#include <CayenneMQTTESP8266.h>

//// WiFi network info.
char ssid[] = “”;
char wifiPassword[] = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “”;
char password[] = “”;
char clientID[] = “”;

void setup() {
Serial.begin(9600);
Serial.println(“Setup”);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

}

void loop(){
{

//Run Cayenne Functions
Cayenne.loop();

//Cayenne.run();
}
int x = analogRead(A0);
int y = map(x, 945, 380 , 0, 100);

Cayenne.virtualWrite(V1,y);
Serial.print(“umidade”);
Serial.println(y);
}

MY SERIAL CONSOLE SENSOR INTO THE GLASS WITH WATER

eau

MY SERIAL CONSOLE SENSOR INTO THE GLASS WITHOUT WATER

NO%20eau


#2

First, try to understand your sensor without cayenne code. this gives you a better idea of the sensor and its value.


#3

It is a resistive type sensor: the electrical resistance of the dry ground is higher than that of the wet ground


#4

sorry, i meant try to understand your sensor by looking at the output in the serial monitor without the cayenne code.


#5

Now all my values ​​are OK but I still have two problems

1 °) I am obliged to double my code

int x = analogRead (A0);
int y = map (x, 1023, 0, 0, 100);

for this to appear in the console and in the cayenne interface.

2 °) The data go back in cayenne I see them in data but I have no creation of Widjet.

Finally, how to mount 2 other soil moisture sensors on the one hand mounting but also in the code?

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define DHTTYPE DHT22
#define DHTPIN  4
#define Pin A0
#define VIRTUAL_PIN V1

#include <CayenneMQTTESP8266.h>
#include <DHT.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

//Variables for DHT11 values
float h, t, hif;
//Time to sleep - 10 minutes - delete a zero to set to 1 minute
int SleepTime = 60000000;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Setup");
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

  CayenneSent = false;
  ReadError = true;
}

void loop() {
  //Run Cayenne Functions
  Cayenne.loop();

 //Only check values if there is a ReadError 
  if (ReadError){
    ReadError = false;
    //Check if read failed and try until success
    int WhileLoops = 0;
    do {
      WhileLoops++;
      //We can't go too long without calling Cayenne.loop() so exit this loop after 2 seconds and set an error flag
      if (WhileLoops >= 4){
        Serial.println("Sensor Read Error");
        ReadError = true;
        break;
      }
      
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Read humidity (percent)
      h = dht.readHumidity();
      //Read temperature as Celsius
      t = dht.readTemperature();
      //Calculate Heat Index as Celsius
      hif = dht.computeHeatIndex(t, h);
  
      delay(500);
    } while  (isnan(t) || isnan(h));

    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature (c): ");
    Serial.println(t);
    Serial.print("Heat Index (c): ");
    Serial.println(hif);
    //Read soil moisture  
    int x = analogRead(A0);
    int y = map(x, 1023, 0 , 0, 100);
    Serial.println(x);
    Serial.print("Hygrométrie "); 
    Serial.println(y);
    
  }
  else {
    //Check if we sent all values and sleep for 10 minutes if we did
    if (CayenneSent){
      Serial.println("Sent all values - sleeping");
      delay(100);
      ESP.deepSleep(SleepTime, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
}
    
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  //Check if there was a read error and skip sending values if there is
  if (!ReadError){
    //Send Values
    Cayenne.virtualWrite(0, h, "rel_hum", "p");
    Cayenne.virtualWrite(1, t, "temp", "c");
    Cayenne.virtualWrite(2, hif, "temp", "c");
    int x = analogRead(A0);
    int y = map(x, 1023, 0 , 0, 100); 
    Cayenne.virtualWrite(V1,y);
   
    delay(60000);

    //Set CayenneSent to true so we know when to sleep
    CayenneSent = true;
  }
}

#6

sorry but i dint understand what you trying to do. can you provide more details?

this code looks like from other topic you created and you have not answered my question.

so let’s start a fresh and keep both topic separate.
what is the problem you are facing using soil moisture?