Buttons Triggering unexpectedly

I have designed a very simple tactile button pcb that when pressed triggers a cycle and then turns on an LED to know which cycle is running and turns off when it stops.

My issue is that sometimes the cycle will start and the led will go off even when I don’t press the button. When I had this on my breadboard I didn’t notice this once I had the resistors in the right place.

I do notice there are a couple of ways to wire the buttons. I had the configuration in this link: https://www.arduino.cc/en/tutorial/button

I am using these buttons: https://www.amazon.com/gp/product/B06VY1WJ8Z/ref=ppx_yo_dt_b_asin_title_o00_s02?ie=UTF8&psc=1

Then a 220Ohm resistor between the signal from Arduino and the led.

Attached is my Eagle schematic.

Does anyone have an why I am getting cycle triggering when I don’t press the buttons? It particularly happens if I pass my hands close to the board.

Code:
// Button_test

const int Wash_button = 9;
const int Hygiene_button = 10;
const int Wash_LED = 7;
const int Hygiene_LED = 8;
int wash = 0;
int hygiene = 0;
float Celcius = 0;
double WL = 0;
//const int wTape = A0;
int t = 0;

void setup() {
// put your setup code here, to run once:
pinMode(Wash_button, INPUT);
pinMode(Hygiene_button, INPUT);
pinMode(Wash_LED, OUTPUT);
pinMode(Hygiene_LED, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

wash = digitalRead(Wash_button);

Serial.print(“Washbutton:”);
Serial.println(wash);

if(wash != 0){
// 31 min
digitalWrite(Wash_LED, HIGH);
delay(3000);
}

hygiene = digitalRead(Hygiene_button);
Serial.print(“Hygienebutton:”);
Serial.println(hygiene);

if (hygiene != 0){
digitalWrite(Hygiene_LED, HIGH);
delay(3000);
}

delay(500);
wash = 0;
hygiene = 0;
digitalWrite(Hygiene_LED, LOW);
digitalWrite(Wash_LED, LOW);
}

SimpleUI.PNG

You're not wired like the example. Your pull-down resistors should be wired to pins 3 & 5 of the connector so the signal is low when the switch is open. Then when you press the button to close the switch, the signal is forced high '"overpowering" the pull-down resistor.

OP’s image:

SimpleUI.PNG


FYI

In the tutorial, the resistor is between the switch pin and GND. Are you saying that it needs to be in line with the output pin and GND? So S4 pin 3 should be to the ground and S4 pin 1 should have a resistor connecting it to GND and then go to pin5?

See the modified diagram

Now you've made 2 short circuits.
3V to pin 3 on S4, pin 1 on S4 to R5, other end of R5 to GND, pin 2 on S4 to J1,5.
3V to pin 3 on S3, pin 1 on S3 to R1, other end of R1 to GND, pin 2 on S3 to J1,3.

Hi,
I think you need to rearrange your schematic.
This I think is what you are trying for with pull-down resistors.


If you are a learner with drawing schematics, practice will teach you how to get your layout easy to read.
Draw your diagrams on paper first, before committing to CAD, that way you can free style your layout so they look legible.
Note: The use of a GND symbol and less crossing wires.
Tom... :slight_smile:
PS. I love ExpressPCB/Schematic for drawing CLEAR and CLEAN schematics.
Everybody should learn with it before going to massively topheavy CAD packages.

Ok. I think I understand. Basically I had my pull-down resistor on the Input Voltage input side which would not help with returning the output side to 0V after the button is pressed. The pull-down resistor needs to be on the output end so that it can maintain the logic level LOW when the switch is not closed.

Attached is my updated circuit. I hope this is right! :slight_smile:

Thanks for your help!

It's hard not to be blunt here. This schematic is so disorganized that it's painful to read. But if 3-6 are MCU pins, 3 and 5 have switches with pull down resistors, 4 and 6 are active-high LEDs. That much is correct if it's what you are looking for.

You should always vet a schematic after you complete it, to see if you have made any errors, and to make it clear and readable. Your use of dot connectors follows two opposing conventions, and in any case there is a random dot thrown into the mix just to add to the confusion.

One universal convention that would help you, is to put power "on top", ground "at the bottom", and everything else "in between". You will be amazed at how easy the LED and switch routing then becomes.

You can think of a switch as a resistor that changes in value between about 1 ohm and "about 100000000000" ohms. (!)

You make a resistor-divider with the switch and a 10k resistor, and connect the middle to a input pin.

Then the divider looks like 1 : 10000 when the switch is closed
and it looks like 100000000000 : 10000 when the switch is open.

In each case the voltage at the centre of the divider will be very well defined, either very close to 0V or
very close to 5V.

The divider can be either way up, that just changes the sense of the result, and if the 10k is towards the 5V
pin, you can lose it and substitute the built-in pull-up resistor using pinMode (..., INPUT_PULLUP)

This also explains why the value of the pullup or pulldown resistor is not in any way critical. Anything from 100 ohms to >1M would work, but higher values increase the susceptibility to noise and interference, especially for long wire runs, so 10k is a good general value, down to 1k for long cable runs.