[Solved] unwanted activation or deactivation

I have a program where certain OUTPUTS get HIGH when certain INPUTS get HIGH. My arduino is connected to 220V and everything works perfectly. But sometimes when I press the light switch in same room one of my outputs would turn on/off. Why is that happening, why does a light switch activates my program? I also noticed when i slowly press the light switch it would happen. is it because of High Voltage parasite? How do I fix this?

Spikes.

Try inverting the switch logic.

Try posting details, not vague hand-waving.

Hi,
How have you got your inputs wired and are you using pullup or pull down resistors on your digital inputs?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Please include the 220Vac power supply you are using.

Thanks.. Tom.. :slight_smile:

TheMemberFormerlyKnownAsAWOL:
Spikes.

Try inverting the switch logic.

Try posting details, not vague hand-waving.

I have a program where output (led) gets High if input gets high, and led stays high until it's reactivated (input -taster gets high again) but it can't be reactivated in first 10 seconds, same happens when led is reactivated and gets low, it can't become high again until 10 seconds passed. Now there is just arduino connected to 220V and ordinary light switch in room activates it for no reason, it is not connected to arduino or something. if its because of spikes then how do i fix it? seems like your answer is vague hand-waving.

OK, it seems like we need to work on your personal definition of "detail"

if its because of spikes then how do i fix it?

See reply #1

TheMemberFormerlyKnownAsAWOL:
OK, it seems like we need to work on your personal definition of "detail"

Can you imagine one led and one taster connected to arduino nano (ofc with resistor), arduino connected to 220V with its original cable pluged in a phone charger which is in 220v? Now you have serious problems if you can't imagine that. When I turn on the light switch in that room to be able to see because i can't see in dark obviously(but you need details and i need to explain it to you), turning lights on or off would turn the led on/off sometimes.

Code:

const int  buttonPin = 3;
const int ledPin = 6;
int buttonPushCounter = 1;
int buttonState = 0;
int lastButtonState = 0;
bool flashState = false;


void setup()
{
  Serial.begin(115200);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.println(" == Button Press - Three Flash V1.0 == ");
}


void loop()
{
  buttonState = digitalRead(buttonPin);
  Serial.print("buttonState = ");
  Serial.print(buttonState);
  if (buttonState != lastButtonState)
  {
    if (buttonState == HIGH)
    {
      flashState = true;
    }
    delay(50); //bouncing
  }
  Serial.print("\t flashState = ");
  Serial.print(flashState);
  lastButtonState = buttonState;
  


  if (flashState == true)
  {

    
    digitalWrite(ledPin, HIGH);
    delay(10000);
    flashState = false;
    while(digitalRead(buttonPin) == LOW)
      {
        digitalWrite(ledPin, HIGH);
      }
  delay(50); //bouncing
  }
  else
  {
    digitalWrite(ledPin, LOW);
    
  }



  if (flashState == false)
  {

    
    digitalWrite(ledPin, LOW);
    delay(10000);
    flashState = true;
    while(digitalRead(buttonPin) == LOW)
      {
        digitalWrite(ledPin, LOW);
      }
  delay(50); //bounce
  }
  else
  {
    digitalWrite(ledPin, HIGH);
    
  }

  Serial.println(" ");
}

Ok,.I imagine that you've got a pulldown resistor on pin 3.
That wasn't so hard, because you've got a serious problem if you haven't.
So, invert the logic of the switch, and use the built-in pullup instead.

(You still need to work on the whole "detail" thing)

What exactly is a "taster"?

Most of the information was in OP.s other thread.
Leo..

Wawa:
Most of the information was in OP.s other thread.
Leo..

Oh great.
Another time-waster.

TheMemberFormerlyKnownAsAWOL:
Ok,.I imagine that you've got a pulldown resistor on pin 3.
That wasn't so hard, because you've got a serious problem if you haven't.
So, invert the logic of the switch, and use the built-in pullup instead.

(You still need to work on the whole "detail" thing)

What exactly is a "taster"?

I think you don't understand what my problem is. Read my posts again carefully, then answer if you know how to, if not, then please don't.

I fixed problem now with capacitor, but i would still like to know other possible fixes.

I know exactly what at least one of your problems is.

Read my replies again, carefully.

If you don't want to implement my suggestions, I really couldn't give a toss.

TheMemberFormerlyKnownAsAWOL:
I know exactly what at least one of your problems is.

Read my replies again, carefully.

If you don't want to implement my suggestions, I really couldn't give a toss.

Tried, nothing works except adding capacitor on the input.

Wawa:
Most of the information was in OP.s other thread.
Leo..

So what is wrong with that thread? I am new to programming, someone helped me and i said thanks

Detail.

Can you imagine one led and one taster connected to arduino nano (ofc with resistor)

Your imaginary circuit should have at least two resistors, not a singular resistor.

Elaz1234:
nothing works except adding capacitor on the input.

I'm truly delighted for you.

Now please mark the the thread "solved" and we can all move on.

(I still have no idea what a "taster" is)

TheMemberFormerlyKnownAsAWOL:
Detail. your imaginary circuit should have at least two resistors, not a singular resistor. I'm truly delighted for you.

Now please mark the the thread "solved" and we can all move on.

I still need to know if it can be fixed with code. You see I'm newbie and i appreciate help from experienced members, i'm thankful for it, instead of mocking whats wrong in comments, why don't you show me what's right (without mocking), since your first post, you are insulting me in a way ''vague hand-waving'' things like that, I see you older members as motivation and when you act like that it really demotivates me, but people like you will not stop me i will go on with learning.

What is demotivating is your lack of detail.
I think I may have already mentioned this.

Show a schematic - don't make us imagine it.
What we imagine, and what is reality can make a huge difference.

You're a noob.
Noobs make assumptions and mistakes.

I assume you have a pulldown resistor on the switch (you told us you have a resistor, but that could just be the LED's current limiter), and you may have a resistor on the switch, but it's a series resistor or something else as inappropriate.

Until you show us, we simply don't know.

I still don't know what a "taster" is.
I suspect I've also mentioned that before.

I'm going to bed now.

TheMemberFormerlyKnownAsAWOL:
What is demotivating is your lack of detail.
I think I may have already mentioned this.

Show a schematic - don't make us imagine it.
What we imagine, and what is reality can make a huge difference.

You're a noob.
Noobs make assumptions and mistakes.

I assume you have a pulldown resistor on the switch (you told us you have a resistor, but that could just be the LED's current limiter), and you may have a resistor on the switch, but it's a series resistor or something else as inappropriate.

Until you show us, we simply don't know.

I still don't know what a "taster" is.
I suspect I've also mentioned that before.

I'm going to bed now.

I don't have switch connected to arduino, there is no switch, spikes of Voltage are activating my outputs when i turn the light in my house. There are 2 resistors and taster is push button (input). Now if you were nice and didn't insult me since beginning, maybe we would've solved this problem till now. I'm going to bed too now, you don't understand me and i don't need your help anymore since you're insulting. Bye

Elaz1234:
I don't have switch connected to arduino, there is no switch...

There are 2 resistors and taster is push button (input).

A 'taster' (momentary push button) IS a switch.

You failed to give us the resistor values.
A circuit diagram IS important.
As is a clear picture if the setup/breadboard.

With the limited real information given I see two possibilities for your problem.

  1. wrong resistor value on the button and/or bad breadboad/wiring.
  2. poor quality USB charger (that lets mains power spikes through).

Did you try powering the Nano from the PC/laptop?
Leo..

Wawa:
A 'taster' (momentary push button) IS a switch.

You failed to give us the resistor values.
A circuit diagram IS important.
As is a clear picture if the setup/breadboard.

With the limited real information given I see two possibilities for your problem.

  1. wrong resistor value on the button and/or bad breadboad/wiring.
  2. poor quality USB charger (that lets mains power spikes through).

Did you try powering the Nano from the PC/laptop?
Leo..

But it is working with capacitor. I posted my code, is everything right with it? Should input be defined as input_pullup ?

Hi,
I know you are a noob, but back in post#2 I asked politely for a circuit diagram.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a picture of your project please?

Please read my side bar.
<<<<================
Troubleshooting electronic devices is my profession, but even I need some basic information.
You have the project in front of you, not me.

Thanks.. Tom... :slight_smile:
PS. Please do not refer to the other thread, if you have info in it that is relevant, place it in this thread.