This project is to serve as a reminder to water my plant by turning on the green LED when water is need. Then, turning on the red LED when there is enough water. The code complies and uploads, but on my blynk dashboard, using the graph widget, it only shows single digits. These reading are also wrong, as it reflect the same value whether the moisture sensor is in water or out. Please help!! below is my code.
#define BLYNK_PRINT Serial
#include "blynk/BlynkSimpleParticle.h"
int greenLed = D4;
int redLed = D3;
int moisturePin = A0;
int thresHold = 0;
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
void setup() {
Serial.begin(9600); // See the connection status in Serial Monitor
delay(5000);
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(moisturePin, INPUT);
}
void loop() {
Blynk.run(); // All the Blynk Magic happens here...
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
int sensorValue = analogRead(moisturePin);
//Blynk.virtualWrite(1, moisturePin);
Serial.println(sensorValue);
if (sensorValue > thresHold){
digitalWrite(greenLed,HIGH);
digitalWrite(redLed, LOW);
}
else{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
}
}
My problem is that the reading from the moisture sensor is not accurate, and I don’t know why. I am getting the same reading whether the sensor is dry or wet. I am trying to turn on a green LED when the plant need water and the red LED when the plant has enough water. Thanks for your help.
Thanks for getting back to me. The sensor reads correct when i remove all of my variable from the body of the of the code. The only library i included is the #include “blynk/BlynkSimpleParticle.h”. Is there another one I should use? From what you have seen, does my code look correct?
It is a cheap, simple moisture sensor. I do not think it requires a library. I have tried the threshold at 0 and at 500. I used 0 because I wanted to see if one of my LED would turn on depending on which condition was met. I don’t understand what’s going on. I truly appreciate your help.
Can you please give me an example of how you would write this code i am trying to implement with Blynk? I am really want to learn how to work with Blynk.
Thanks for your input. I have attempted to the best of my ability to implement your suggestion. Below you will find my attempt. I keep getting an error. Can you please help me?
//#include "blynk/blynk.h"
//#define BLYNK_PRINT Serial
#define BLYNK_PRINT Serial
#include "blynk/BlynkSimpleParticle.h"
#include <SimpleTimer.h>
int greenLed = D4;
int redLed = D3;
int moisturePin = A0;
SimpleTimer timer;
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
void ledIndicator(){
int sensorValue = moisturePin;
if (sensorValue > thresHold){
digitalWrite(greenLed,HIGH);
digitalWrite(redLed, LOW);
}
else{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
}
}
void setup() {
Serial.begin(9600); // See the connection status in Serial Monitor
delay(5000);
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(moisturePin, INPUT);
timer.setInterval(60000, ledIndicator);
}
void loop() {
int thresHold = 1000;
//Blynk.virtualWrite(1, sensorValue);
// Serial.println(sensorValue);
Blynk.run(); // All the Blynk Magic happens here...
ledIndicator();
}
I appreciate the timely response. I have been searching the forum and found the example you sent me before. I don’t want to simply copy and paste someone else’s code. I want to understand my mistakes and learn from them. I could copied the example and make modifications, but I would learn anything. I just want to understand the mistakes I am making in my little project, so I can expand. I will fix the timer library mistake I made. Thanks again!