Micro-Weatherstation help

Hi,

I’m building a weather station for my plants and trees.

I’ve started from this Blynk example for bringing in analog sensors. (My case Rain sensor and soil sensor.)

Then I switched to (bare with me) putting in the DHT11 sensor to send temp & humidity to my blynk app. I did this from Blynk example.

And the DHT example worked of course, I throwed some stuff out (Relay & LED) and started to join the Analog in example in the sketch.

The first problem then was that I lost my humidity in the app, better it became a 1 or a 0. Though Temp remained correct and the first analog in (moist sensor) gave me a analog voltage. (How to convert this to a correct mapping I still need to figure out!)
Being me, I headed on thru with adding sensors instead off fixing the problems first. Thus second analog sensor attached (Soil sensor, again don’t know how to correctly convert that data on the gauge)

Then I though I have I2C working (analogs) why not add a lux sensors, which I did and like all all the sensors separately throughout the build they worked in the serial monitor (BLYNK Lesson 1 :wink: ) as did the lux sensor. Strange quick data with lot’s of overloads. ( third time need to figure out how to convert the data in to something in the app to be more understandable)

But when adding the lux sensor the data gets weird on the app. The temp drops to 0 when the lux sensor gets lots of light. Humidity keeps being 1 and jumps very fast to 0 and back.
The lux sensor gives me correct data being mostly 26.00 too 4000.00

Without the drops (which I do want to get fixed), only the humidity doesn’t come back correctly.
And I need to map the value for the soil and lux and rain.

So the main question would be, how to fix the humidity and the mapping for the app.

code:

#include <Adafruit_TSL2561_U.h>
#include <pgmspace.h>
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include "DHT.h"
#include "SimpleTimer.h"   //Good timer library
#include <Adafruit_ADS1015.h>

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);


#define BLYNK_PRINT Serial  
#define DHTPIN D4     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);
int temp;
int humidity;
int moisture_val; // SoilMoisture Value

char auth[] = ""; //Auth Token for project 
char ssid[] = ""; //Wifi
char pass[] = "";//Pass


SimpleTimer timer;

Adafruit_ADS1115 ads;

float Voltage0 = 0.0;
float Voltage1 = 0.0; 
float Voltage2 = 0.0;
float Voltage3 = 0.0;


void setup()
{
  Serial.begin(115200);
  dht.begin();
  Blynk.begin(auth, ssid, pass);
  int mytimeout = millis() /1000;
  while (Blynk.connect() == false) {
    if((millis() / 1000) > mytimeout + 8){
    if(!tsl.begin())
  {
    Serial.print("No TSL2561 detected");
    while(1);
  }
 
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
 
  Serial.println("");

     break;
    }
  }
 


// Setup function to be called every 2 seconds
timer.setInterval(200L, sendData);
timer.setInterval(350L, ReadANALOGS);
timer.setInterval(350L, Lux);


ads.setGain(GAIN_TWO); //https://community.blynk.cc/t/ads1115-with-wemos-mini-d1/12215
ads.begin();

} 
//--(end setup )---
  
void ReadANALOGS()
{
  int16_t adc0, adc1, adc2, adc3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  
  Voltage0 = (adc0 * 0.125)/1000;
  Voltage1 = (adc1 * 0.125)/1000; 
  Voltage2 = (adc2 * 0.125)/1000;
  Voltage3 = (adc3 * 0.125)/1000;
  
//Serial.print("AIN0: "); Serial.println(Voltage0);
// Serial.print("AIN1: "); Serial.println(Voltage1);
// Serial.print("AIN2: "); Serial.println(Voltage2);
// Serial.print("AIN3: "); Serial.println(Voltage3);
// Serial.println(" ");
  

  Blynk.virtualWrite(V0, Voltage0); **//Conversion or mapping here? SOIL**
  Blynk.virtualWrite(V1, Voltage1); **//Conversion or mapping here? MOIST**
  Blynk.virtualWrite(V4, Voltage2);
  Blynk.virtualWrite(V5, Voltage3);  
}
void sendData()
{
 
  
 float t = dht.readTemperature();
 float h = dht.readHumidity();
 moisture_val = digitalRead(D4); // read the value from the moisture sensor
  
  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V3, moisture_val); **//This does not work**
  
} 

void Lux()
{
   /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);

  Blynk.virtualWrite(V6, event.light); **//Conversion or mapping here?**
}
void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

If needed I’m making a fritzing for the wiring and can post that too and screenshots of the app if needed!!

Thanks! And big up to the ones I got the examples from!

Haven’t gone through the whole code, but this jumped out… First, @ around 200-350ms, this is like 3-5 times a second reading!! Do you need the data that fast?

Secondly, buth the Analog and LUX readings happen at the same time… so between the fast reads and the quasi simultaneous function calls (I say quasi becasue these are not multitasking MCU’s) I suspect that you are only getting the LUX data because it is the last function called… no time to read/display the prior one.

Give much more time between reads and stagger the timers sufficiently to allow each one time to poll, read and display.

so something like

timer.setInterval(200L, sendData);
timer.setInterval(600L, ReadANALOGS);
timer.setInterval(35000L, Lux);

Would be better?

maybe

or, are you afraid if the sensors are not read 5 times per second, the plants will die? :slight_smile:

more realistically, i think 10 readings / 24h would do for plants groving. you are not monitoring the cooling system of a nuclear reactor…

2 Likes

Hehe actually they are nuclear plants…

Changed it, now my temperature keeps at 0 and my humidity at 1

Also now I can’t check if the sensor data is accurate and correct.
How do I know my lux sensor gives the correct value? Likewise for the conversion of the moist and soil sensors?

well, there are some things to consider:

  • i see you are using dht11 sensors. those are pure junk, not good. replace them with dht21, dht22, bm280. they are much better

  • the maximum sampling rate for dht sensors is 0.5hz. (ie, they should not be read more than once every 2~2.5 seconds, otherwise you will receive junk data)

  • for debugging, of course you can use shorter read times, say 5000L (5 seconds), but not lower than 3000L, for the sake of the slow dht sensors

  • here i’m not sure what you’re trying to achieve:

void sendData()
{
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  moisture_val = digitalRead(D4); // read the value from the moisture sensor

  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V3, moisture_val); **//This does not work**
}

moisture_val = digitalRead(D4); you are reading a digital pin. the value of any digital pin can’t be anything else only 0 or 1. so here:
Blynk.virtualWrite(V3, moisture_val); **//This does not work** you will always receive 0 or 1.

to get the humidity, you should do like with the temperature:

float t = dht.readTemperature();
Blynk.virtualWrite(V2, t);

also

float h = dht.readHumidity();
Blynk.virtualWrite(V3, h);

and also make sure, that in the app the display widget is NOT set to mapping values, like in this picture (see the line shape between 0 and 1023):

you should have it like this:

Awesome!!

I’ve changed the DHT11 with the DHT22.
Changed the wrong variable with this

float h = dht.readHumidity(); Blynk.virtualWrite(V3, h);

And I uncommented the line with:

  moisture_val = digitalRead(D4); // read the value from the moisture sensor

Which gives me a steady 21.9 degrees and 66.800 ? something. Nothing is dropping anymore.

For the analog sensor I have the following sensors. These sensors have and amplifying chip with them. Do I connect the sensor with these boards to my ads1115 or do I connect them directly to the ads1115.
I think that’s what causing wrong analog data output in the app.

At last (for now! :stuck_out_tongue:) I want the soil sensor to be activated by a digital high low (I’ve read something that this stops corroding the pins and gives it a longer lifespan. Do I do this with the ads1115 or with the amplifier board that has a D0 and A0 pin-out.

66.8% Relative Humidity.

Apparently so does slathering your entire body with honey… but then I would be cautious of believing everything you hear on the web :stuck_out_tongue:

But honestly, while DC and moisture CAN cause corrosion, covering the connectors in honey… er… no… wait… dielectric grease (or even just simple vaseline) WILL help keep the connections from moisture ingress, and save you from the effort of the extra coding and switch circuitry involved (do NOT try to power sensors directly off of I/O pin power alone).

:joy: