Switch problem

Ifollowed this schematic

with that switch and 10k resistor

but when i always turn on my switches for unknown reason my arduino restarts / turn off while i keep my switch ON

Your diagram and switch are correct.

What is not shown is where you have connected Pin X to ? sound like you have several switches.

If the Arduino turns off, then it must be wired incorrectly or an incorrect resistor value and its shorting things out. 10K means 10,000 ohms

Can you post a clear picture of the actual wiring ?

And let's see the code.

See pin D7

.

NONE of the switch terminals should be connected to 5V. Only the resistor should be connected to 5V. Your schematic is fine... The question is if you've really wired it that way...

Make sure that Pin-x is configured as an INPUT. If it's configured as an output and you ground it with the switch, you can damage the Arduino (or maybe cause it to reset).

That looks like a DPDT switch (6 terminals). You only need to use two switch terminals. If you are not sure which switch terminals to use, consult the datasheet for the switch or check it with your miltimeter. (Using the wrong pair of switch terminals won't cause the problem you're describing.)

BTW - If you enable the Arduino's [u]internal pull-up resistors[/u] you don't need the 10K resistor.

What is not shown is where you have connected Pin X to ? sound like you have several switches.

If the Arduino turns off, then it must be wired incorrectly or an incorrect resistor value and its shorting things out. 10K means 10,000 ohms

Can you post a clear picture of the actual wiring ?

I got 4 switches, they are connected at pin 5,6,7,8.
I use only 3.

And let's see the code.

const int SW1 = 5;
int s1 =0;
const int SW2 = 6;
int s2 =0;
const int SW3 = 7;
int s3 =0;

void setup{
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
pinMode(SW3, INPUT);
}

  s1 = digitalRead(SW1);
  if (s1 == HIGH) {         
    // LED HIGH          
  } 
  else {    
    // LED LOW
  }
  
s2 = digitalRead(SW2);
    if (s2 == HIGH) {         
    // LED HIGH
  } 
  else {    
    // LED LOW
  }

  s3 = digitalRead(SW3);  
    if (s3 == HIGH) {         
    // LED HIGH
  } 
  else {    
    // LED LOW
  }

Doesn't really mater which one I Turn ON/OFF they all affect my atmega making it turning off / restarting.

Note: I use as well a nRF module on this circuit.

At least post code that compiles please....

At least post code that compiles please....

Here:

const int SW1 = 5;
int s1 =0;
const int SW2 = 6;
int s2 =0;
const int SW3 = 7;
int s3 =0;

void setup(){
  
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
pinMode(SW3, INPUT);
}

void loop(){
  s1 = digitalRead(SW1);
  if (s1 == HIGH) {         
    // LED HIGH          
  } 
  else {    
    // LED LOW
  }
  
s2 = digitalRead(SW2);
    if (s2 == HIGH) {         
    // LED HIGH
  } 
  else {    
    // LED LOW
  }

  s3 = digitalRead(SW3);  
    if (s3 == HIGH) {         
    // LED HIGH
  } 
  else {    
    // LED LOW
  }
  
}

I cba to trace the copper on your pcb, so it will probably be better if you show the actual schematic of what the pcb does.

I cba to trace the copper on your pcb, so it will probably be better if you show the actual schematic of what the pcb does.

cba?
What's cba?

I cba to trace the copper on your pcb, so it will probably be better if you show the actual schematic of what the pcb does.

You are able to trace "wires"/lines on a schematic but not able to trace copper lines that are 100 times bigger than lines from schematic? I even wrote where is the switches, resistors and digital pins of the atmega. About the circuit It's my personal project I don't like to post all my circuit while I talk only about specific components which I'm working only with them right now and nothing more on the circuit.

I can create an exact schematic of the switches, resistors and atmega how exactly they are connected but I
think you already know how they are connected:

Domino60:
I can create an exact schematic of the switches, resistors and atmega how exactly they are connected but I
think you already know how they are connected:

If they are connected like that, then throwing the switch will not reset your Arduino. If you don't show
us the whole of your code and circuit, there is nothing else to say.

Domino60:
You are able to trace "wires"/lines on a schematic but not able to trace copper lines that are 100 times bigger than lines from schematic?

You're the one wanting help, not me. If you want help, give a schematic of how those switches (ie the actual on-off-on switch, not the push button) are connected. No-one here is obliged to help, we're all hobbyists like you.

As the great Dr Perry Cox in Scrubs was fond of ranting "Help me to help you, help me to help you...."

cba

Your schematic shows a momentary push button. Your photo is of a DPDT switch (not momentary).

Do the switches you are using look like the photo you posted ? If so, they are the wrong kind of switches.

You should be using these

The copper and the switch does look functionally the same as the schematic to me, but not expending any energy on checking it, with OP's attitude.

OP should check with a meter on the copper that the voltages (edit: and resistances, continuities) are as expected.

I think this one is simply that you have misidentified the lugs on the switch or otherwise wired it up wrong, simple as that.

Grumpy_Mike:
I think this one is simply that you have misidentified the lugs on the switch

Yep it may behoove OP, if he has a spare switch not soldered into a board, to get his meter and beep it out to see exactly what gets connected to what when the switch is in each of its 3 positions.

I got a 6 pin switch, i checked with my meter and beeped around :smiley: to find the exact pins while switching
ON/OFF, i soldered only 2 pins of the switch on my 2 pins on PCB.

I'd like to have switches and not buttons, one reason to have switches is to make a task for example
if i turn a switch on to do something if i turn it off to stop the function, with a button i can't do that, well
i probably can but i want to have a switch to make a "physical view friendly user interface" with simple logic (ON/OFF) switch.

Well on the face of it it looks to me like your switch and copper on the pcb do the same as your schematic, but only you know if that's true by testing the traces for voltage and continuity.

As pointed out, a switch wired ala your schematic will not cause the symptoms, which to me seem more like a 5V to Gnd short. Somehow, something along those lines is happening, it seems?

I would still like to see a schematic showing your actual switch, including what's actually switched to where inside it (ie the little "flap" thing one usually sees as a switch symbol.)

Well I think im gonna take the raschemmel advice, to use buttons, I can make in the code to take the button to light up a led and by the state of the led to make the task/ function being ON or OFF.

JimboZA I'm really sorry that I don't post full circuit but it's a personal project and the circuit got copy rights. It's not that i don't want to help but I can't :smiley: it's not about the circuit but the basic idea of the circuit. I think im gonna redesign the circuit with the buttons and leds. What do you think should i give a try?