Weather station blynk 2.0

hi again I followed the advice he gave me and now everything seems to work: at least the sensors but the voltage dividers do not seem to work well in short they do not give very accurate values ​​and I have already calibrated them I do not know if it is for the ADC of the esp 8266 from the last time I added another voltage divider for the solar panel and built a pcb so it can’t be for the bradboard any advice?

P.S. how to i put code here i forgot

What does this mean?

Triple backticks…
```

Pete.

Sorry if i wasn’t clear… so basically Frome the last time I had only one resistor devider for the battery voltage but now i have 2 one for the battery and one for the solar panel (so i can truck the voltage of the solar panel and the battery) i still have the same multiplexer setup i only added one control pin so i can switch 4 lines (I’m using 3 battery solar and lidar) the code has been working quite well I’m getting all the readings but… When I calibrated the resistors in the code 3/10 I’m getting correct values but the 7/10 are values a bit or a lot off by what i measure from my multimeter and for the voltage source I’m using a battery so… No voltage swings Yeah that’s my question: do you know why are my values shifting?

Maybe you should post your latest sketch, a schematic, details of what you are seeing in your serial monitor or Blynk, and what your multimeter shows.

Pete.

so here is my letest code; unfortunatly i can’t put a wiring diagram but i can explain it and put some photos

if you take a look the cd4051 datasheet or search for pin out … i got INH, Vee, Vss, C to ground of the board; A to pin D5 on the mcu and B to D6; Vdd is coneccted to vin on the mcu which is at 4.2 volt of the battery
the inputs i am using are the 0,1,2: 0 is for the ldr which i am not very interested in accuracy, 1 is used for the battery voltage is a voltage divider 100k and 100k so i get half the voltage, 2 is the same thing except that I use it to monitor the voltage of the solar panel which keeps the battery charged. it’s nothing special but when I see the values ​​in the serial monitor they keep changing and fluctuating quite a bit sometimes they have the right value,

i put the: for (int x = 0; x <10; x ++)
{

function to get better accuracy but it doesn’t seem to work I don’t know if the problem is the same ground

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

#define MUX_A D5
#define MUX_B D6
#define MUX_C D7

int analogInPin  = A0;    // Analog input pin
int sensorValue;
int sensor;
float calibration1 = 0.43;
float calibration2 = 0.28 ;

float light; 
float voltage;
float solar;

Adafruit_BMP085 bmp;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";


void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
                                                                   // You can also specify server:
                                                                   //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
                                                                   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  dht.begin();
  bmp.begin();
  
  pinMode(MUX_A, OUTPUT);
  pinMode(MUX_B, OUTPUT);     
  pinMode(MUX_C, OUTPUT);     
  }
  
  void changeMux(int c, int b, int a){
  digitalWrite(MUX_A, a);
  digitalWrite(MUX_B, b);
  digitalWrite(MUX_C, c);
  }
  


void loop(){
  Blynk.run();
  send();
}


void send(){
  delay(1000);
  
  changeMux(LOW, LOW, LOW);
  delay(2000);
  
  light = analogRead(analogInPin / 1023.0f);
  Serial.print("ligt = ");
  Serial.print(light);
  delay (1000);
  
  for (int x = 0; x < 10; x++)
  {

  changeMux(LOW, LOW, HIGH);
  delay(3000);
  
  sensorValue = analogRead(analogInPin);
  voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration1);//multiply by two as voltage divider network is 100K & 100K Resistor
  Serial.print("Analog Value = ");
  Serial.print(sensorValue);
  Serial.print("\t Output Voltage = ");
  Serial.print(voltage);
  delay(2000);
 
  changeMux(LOW, HIGH, LOW);
  delay(3000);
  sensor = analogRead(analogInPin);
  solar = (((sensor * 3.3) / 1024) * 2 + calibration2);//multiply by two as voltage divider network is 100K & 100K Resistor
  Serial.print("Analog Value = ");
  Serial.print(sensor);
  Serial.print("\t Output Voltage = ");
  Serial.print(solar);
  delay(2000);
  }

  float h = dht.readHumidity();
  
  float t = bmp.readTemperature();
   
  float p = bmp.readPressure();

 
  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);
  Blynk.virtualWrite(V3, p);
  Blynk.virtualWrite(V4, voltage);
  Blynk.virtualWrite(V5, light);
  Blynk.virtualWrite(V6, solar);


  delay(3000);
  ESP.deepSleep(9e+8);
}

P.S. the code works really well besides the accuracy error

this call a function with a lot off delay :scream:
Never use delay with blynk

1 Like

i’m not using blynk edgent so it shuld be fine

You can’t use any delay with blynk, with or without blynk egent !
You have to use timers instead.
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

void loop(){
  Blynk.run();
  Timer.run();
}
1 Like

oright but i do i make a 1 sec timer? i get it i take away that ilne of code and aff timer.run but then? still the accuracy problem

look @PeteKnight tutorial

1 Like

sorry i didn’t see the link before i will try correct the code but still the voltage accuracy idk why but how do i solve it? (read the cuple posts before if you haven’t) and for the multiplexer to work when i switch the signals there has to be a time for the mux to do it’s things

void setup() {
.
.

timer.setInterval(5000L, SensorRead);
.
.

}

void SensorRead() {
SensorValue = analogRead(analogInPin);
  voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration1);//multiply by two as voltage divider network is 100K & 100K Resistor
  Serial.print("Analog Value = ");
  Serial.print(sensorValue);
  Serial.print("\t Output Voltage = ");
  Serial.print(voltage);
}

void loop(){
  Blynk.run();
  Timer.run();
}

ok I have read the article and it is not very clear to me but in short I have to make sure that the void loop is as clean as possible but creating these timers does not help me because this code runs only once due to deep sleep and I need it just a little delay for the multiplexer and deep sleep again I don’t know where I would put Blynk.virtualWrite
and deep sleep but in reality the code worked on its own without problems only the accuracy of the detected voltages which does not depend on blynk I presume

timer.setInterval(30000L, Sleep); \\ adjust as you need



void(Sleep){
 ESP.deepSleep(9e+8);`
}

If you’re using deep sleep then you shouldn’t be using timers, and most of your code should probably be in void setup or BLYNK_CONNECTED, but it’s impossible to advise because you haven’t provided enough detail about what you are trying to achieve. You won’t get any real assistance from me until you do as I suggested…

Pete.

I think I have found the main problem the adc of the esp 8266 when the wifi si in use goes crazy and gives values ​​in a scale that increases so a possible solution is to take an external adc that would not only increase the analog ports but would go connected with i2c could this be a viable solution?
but in my country I can not find the ADS1115 and the ones I find are practically fake instead of being ADS1115 are ADS1015 so 12 bits instead of 16. does anyone know if the ADS1015 could be good?

I think you’re going down the wrong route.

Post a schematic of your exiting setup, plus the other info I asked for in post #14, along with a summary of what it is that this project is meant to do, and you could save yourself a lit of time and effort.

Pete.

2 Likes

If you are sure that the problem comes from the ESP8266, better buy an ESP32 for $6 or less

fair to say but here the cost 12 euros not so cheap btw from what i read the esp 32 is eaven worst when using wifi 6 analog in are disabled and the adc is less accurate if i remember

i found the problem i practically noticed that the humidity recorded by my dht 11 was 95% which is very strange as the measurement range is only up to 90% so i unsoldered it and tried it with in another node mcu and the test sketch dht and kept giving 95% so I think it is damaged so I bought one i2c the HDC1080 which from what I have seen is accurate enough this would also solve the voltage problem for me and I would no longer have to use the external adc we will see. …