Analog To VPin - Moisture Sensor


int SensorvalueA=0; 
int sensorpin=A1; 

void moistureSensor()
{
 SensorvalueA = analogRead(sensorpin); // Bloom
 SensorvalueA = map(SensorvalueA, 220, 640, 0, 1034);
 Blynk.virtualWrite(V5, SensorvalueA);
 terminal.print("Bloom ProMix % - ");
 terminal.println(SensorvalueA);
 
 terminal.flush();
}

void setup()
{
 Serial.begin(9600);
 dhtA.begin();
 dhtB.begin();
 pinMode(A0, INPUT_PULLUP);    // DHT22 use internal 20k pullup resistors
 pinMode(A2, INPUT_PULLUP);
 pinMode(sensorpin,INPUT);
 RTC.begin();
 

 for (int allRelays = lightA; allRelays <= VentB; allRelays++)
 {
   pinMode(allRelays, OUTPUT);
   digitalWrite(allRelays, TURN_OFF);
 }

 for (int p = 0; p <= 7; p++)
 {
   pinMode(pumpPin[p], OUTPUT);
 }

 timer.setInterval(1000L, moistureSensor); 
 timer.setInterval(3600000L, syncRTCHardware);   // synchronize the RTC device with the server time every hour
 timer.setInterval(1000L, displayDateTime);   // update the LCD Widget every 5 seconds
 timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval

 Ethernet.begin(arduino_mac, arduino_ip, dns_ip, gateway_ip, subnet_mask );
 Blynk.config(auth, server, port);  // this is OK
 Blynk.connect();             // this is OK

 Serial.println("setup complete.");
}

void loop()
{
 // only attempt Blynk-related functions when connected to Blynk
 if (Blynk.connected())
 {
   Blynk.run();
 }
 timer.run();
}

Think I pasted code properly.

Looking for assistance.

I have a DFrobotics Capactitive Moisture Sensor and I just cant get the value to read on v5.

Looking for some assistance.

Fairly new to code so I only uploaded what appeared to be important in relation to this.

Yes I have read for 5 days on Read/Write and just cant get this figured.

Thanks

You didn’t mention what, if anything, does show up on whatever type of Display Widget you have on V5.

Are you getting the correct data on your terminal?

I think you have your map() backwards??.. the Analog pin will output a range from 0-1023 (assuming Arduino) and it seems you want it to “map” that to 220-640… so what you would want is:

SensorvalueA = map(SensorvalueA, 0, 1023, 220, 640);

I am sorry.

I am using Arduino Mega, and the data is sent to labeled value display on my Blynk App.

It currently shows 1944 but I will update code and see what the updated mapping does.

Thanks

I get a value of 634/635 with your mapping

That should meen that your sensor is outputting near the highest range of the Analog input.

I have no idea what that means as far as your sensor is concerned, but assuming it is wired correctly, then it seems it is all working as expected and telling you your moisture level is near the max range of that sensor.

It isnt though.

It is in the air so should show around 220-240

I moved it to A5 pin and it is fine.

For some reason I had issues with A0 before as well.

Now I will just map the values accordingly.

Thanks

also, for accurate analog reads on arduino, read this article:

https://www.quora.com/Why-is-a-little-delay-needed-after-analogRead-in-Arduino

Thanks wanek.

Article was over my head but it allowed me to do more reading an implement the code.

Thanks