Chat freely about anything...

User avatar
By tbh726
#79512 All,
I am having an issue that i am not sure what to do next, i am not a electronic guy just read a bunch so please bear with me. I am using an esp8266 that is connected to a simple push switch that when the switch is pushed it turns on some LED strips via a FET board that i found on Amazon. Everything works great. I have this setup turning the lights on in my workshop. however it does toggle my lights (on or off based on the state when the button is pushed.) when it is getting some type of noise. like when my heater kicks on or i have an old fluorescent lamp sometimes when i turn it on it will toggle the lights. What i have tried to do is:
1 added a 10k pull up resistor
2. powered everything from batteries
3. powered by a stronger power supply plugged into a UPS on battery side.

things i wonder about...
1 button is about 30 feet away so is the wire being that long an issue?
2 do i need to add a capacitor between pin and ground (read about this)

my code is pretty standard

in setup
attachInterrupt(digitalPinToInterrupt(buttonPin), InterruptHandler, FALLING);

if(interruptFlag > 0)
{

senddata(1,"Shop Lights has been toggled"); //send reading to my web services
toggle();
delay(2000);
interruptFlag = 0;
}


Outside setup

void toggle()
{
bool x = relaystate;

relaystate = !relaystate;
digitalWrite(relayPin, relaystate);
server.send(200, "text/plain", "Lights toggled");
if(x == LOW)
{
sendnotification("Shop Lights Toggled Off"); //send notifications to my mobile app
}
else
{
sendnotification("Shop Lights Toggled On"); //send notifications to my mobile app
}
}

image of my setup...
Image

any ideas would be helpful
thanks tim
User avatar
By btidey
#79522 You could lower the value of the pull up resistor even more. Lower resistance will lower the voltage induced by any capacitively coupled interference. Maybe try 1K.

You can add a capacitance to help filter out any interference. The value needs to be high enough to effectively filter out the interference but without introducing too much time lag. Maybe a RC time constant around 50mSec.

You could also do the effect of the filter in the software by modifying it to only toggle if the button is held down for a decent length of time (e.g 50mSec). This will also help deal with any switch bounce. You can do this by noting the time (in milliseconds) in the interrupt routine.