Rudy, thank you for your input also but I'm not quite sure what you meant. Do you mean that I should look at the ADC values in the code and possibly alter them?
Regards to both of you
Dermot
Explore... Chat... Share...
btidey wrote:Here is one suggestion for the loop codeCode: Select all#define ON_THRESHOLD 500
#define OFF_THRESHOLD 400
int adcVal;
int state = -1;
void loop() {
adcVal = analogRead(A0);
if(adcVal >= ON_THRESHOLD) {
setSwitchOn();
} else if(adcVal <= OFF_THRESHOLD) {
setSwitchOff();
}
delay(10);
}
void setSwitchOn() {
if(state != 1) {
mySwitch.send("100111101111101000001111");
state = 1;
}
}
void setSwitchOff() {
if(state != 0) {
mySwitch.send("100111101111101000001110");
state = 0;
}
}
ADC range is 0 - 1024 . I suggest having different thresholds for on and off otherwise if the value was near the middle then it could toggle on and off due to adc noise. These are put into #defines which are just a more readable way of setting their values. state was initialised to -1 so that the first call to switchOn or switchOff is always actioned to set the state accordingly.
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]