My problem is in the module composed of the esp01 and the temperature sensor. After a time correctly measuring the temperature, the sensor begins to send erroneous data (indicating -147 in temperature and 100 in humidity). I have modified the code so that after taking the measurement the sensor turns off and does not turn on again until the next loop, but the result is the same. Currently I don't know how I can solve this error.
I attach my code and the image of the connections I am using.
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <SPI.h>
#include <Adafruit_BME280.h>
#include "config.h"
#include "UDP.hpp"
#include "ESP8266_Utils.hpp"
#include "ESP8266_Utils_UDP.hpp"
#define pin_bme 3
Adafruit_BME280 bme;
int sensor[] = {0, 0};
void setup()
{
ConnectWiFi_STA();
ConnectUDP();
pinMode(pin_bme, OUTPUT);
digitalWrite(pin_bme, LOW);
}
void loop()
{
digitalWrite(pin_bme, HIGH);
delay(500);
Wire.begin(0, 2);
bme.begin(0x76);
delay(4000);
sensor[0] = bme.readTemperature();
sensor[1] = bme.readHumidity();
String packet = (String)sensor[0] + "." + (String)sensor[1];
SendUDP_Packet(packet);
digitalWrite(pin_bme, LOW);
delay(1000);
}
Thx.