Hello i got problem with my project with esp32 ,bh1750 ,bme280 , and rain sensor, especially with rain sensor FC-37. Before I entered the blynk iot code, and put the function of the rain sensor (rain_get) in the void loop, the analog value could be read, but after I entered the blynk iot code the rain sensor analog value immediately read 0, there is no problem with value from bh1750 and bme 280 the value can be read , what should I do?
#define BLYNK_TEMPLATE_ID "TMPL6D7uYM_Kw"
#define BLYNK_TEMPLATE_NAME "App Kanopy"
#define BLYNK_AUTH_TOKEN ""
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "";
char pass[] = "";
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <BH1750.h>
#define SDA_1 19
#define SCL_1 18
#define SDA_2 17
#define SCL_2 16
#define POWER_PIN 25
#define AO_PIN 12
Adafruit_BME280 bme; // I2C
BH1750 bh;
TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);
BlynkTimer timer;
int rainAnalog;
float rainVoltage;
unsigned long delayTime;
void sendSensor()
{
bme_get();
bh_get();
rain_get();
}
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(POWER_PIN, OUTPUT); // configure the power pin pin as an OUTPUT
cek_i2c();
delayTime = 1000;
Serial.println();
timer.setInterval(1000L, sendSensor);
}
void loop() {
Blynk.run();
timer.run();
rain_get();
delay(delayTime);
}
void cek_i2c() {
Serial.println(F("Sensor test"));
I2Cone.begin(SDA_1, SCL_1, 100000);
if (!bme.begin(0x76, &I2Cone)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
I2Ctwo.begin(SDA_2, SCL_2, 100000);
if (!bh.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23, &I2Ctwo)) {
Serial.println("Could not find a valid BH1750 sensor, check wiring!");
while (1);
}
}
void rain_get(){
digitalWrite(POWER_PIN, HIGH);
delay(10);
rainAnalog = analogRead(AO_PIN);
pinMode(AO_PIN, INPUT);
digitalWrite(POWER_PIN, LOW);
rainVoltage = rainAnalog * (5.0 / 1023.0);
Serial.println(rainAnalog);
Serial.println(rainVoltage);
Blynk.virtualWrite(V9, rainAnalog);
}
void bh_get() {
float light_level = bh.readLightLevel();
float raw_level = bh.readRawLevel();
Serial.print("Cahaya: ");
Serial.println((light_level < 20) ? "Gelap" : "Terang");
Serial.println((String)"Lux: "+light_level+" lx");
Blynk.virtualWrite(V1, light_level);
}
void bme_get() {
float temperature = bme.readTemperature();
Serial.println((String)"Temperature = "+temperature+" *C");
Blynk.virtualWrite(V0, temperature);
}