Hello everyone. I am running several sensors and the attached code has worked great, with minor edits, for ESP8266 using wifi. I want to have this run on Bluetooth and I’m afraid it is not working. I understand ESP32 may need different coding than ESP8266. I would be grateful for help with this. Thank you for reviewing my code. Please disregard the “buzzers.” I will not be using them. I removed the auth code for this posting.
#include <BlynkSimpleEsp32_BLE.h>
#include <DHT.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
char auth[] ="";
/************************* Pin Definition *********************************/
#define Relay1 D6
#define Relay2 D2
#define Relay3 D1
#define Relay4 D5
#define DHTPIN 23
#define buzzer 02
#define Multiplexer_Pin1 03
#define Multiplexer_Pin2 01
.
#define Multiplexer_DataPin 34
#define Multiplexer_Gas1 LOW
#define Multiplexer_Gas2 LOW
#define Multiplexer_Motion1 HIGH
#define Multiplexer_Motion2 LOW
int proximity;
int light;
int gas;
int motion;
int Readmotion;
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor() {
float h = dht.readHumidity();
float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V10, t);
Blynk.virtualWrite(V11, h);
Blynk.virtualWrite(V2, proximity);
Blynk.virtualWrite(V12, gas);
Blynk.virtualWrite(V14, motion);
Blynk.virtualWrite(V5, light);
}
void setup() {
Serial.begin(9600);
Blynk.setDeviceName("Blynk");
Blynk.begin(auth);
dht.begin();
pinMode(Multiplexer_Pin1, OUTPUT);
pinMode(Multiplexer_Pin2, OUTPUT);
pinMode(Multiplexer_DataPin, INPUT);
pinMode(buzzer, OUTPUT);
timer.setInterval(1000L, sendSensor);
}
void loop() {
digitalWrite(Multiplexer_Pin1, Multiplexer_Gas1);
digitalWrite(Multiplexer_Pin2, Multiplexer_Gas2);
gas = analogRead(Multiplexer_DataPin);
Serial.print("Gas - ");
Serial.println(gas);
// Address 10
digitalWrite(Multiplexer_Pin1, Multiplexer_Motion1);
digitalWrite(Multiplexer_Pin2, Multiplexer_Motion2);
motion = analogRead(Multiplexer_DataPin);
if (motion > 512) {
motion = 1;
} else {
motion = 0;
}
// Address 01
digitalWrite(Multiplexer_Pin1, Multiplexer_Motion2);
digitalWrite(Multiplexer_Pin2, Multiplexer_Motion1);
proximity = analogRead(Multiplexer_DataPin);
Serial.print("Proximity - ");
Serial.println(proximity);
if (proximity < 512) {
proximity = 1;
digitalWrite(buzzer, Multiplexer_Motion1);
} else {
proximity = 0;
digitalWrite(buzzer, LOW);
}
// Address 11
digitalWrite(Multiplexer_Pin1, HIGH);
digitalWrite(Multiplexer_Pin2, HIGH);
int raw_light = analogRead(Multiplexer_DataPin);
light = map(raw_light, 1024, 0, 0, 100);
Serial.print("Light - ");
Serial.println(light);
Blynk.run();
timer.run();
}