adding a button

im having a issue adding a button to my sketch. i can build a sketch off examples and everything will work correctly. when i try to insert it into my sketch ive been working with i cant get it to work. is there any certain way to insert it? i can share the code but i know its to long to put on here.

It is impossible to provide help without seeing your current program and having an explanation as to what the button is required to do.

If your program exceeds the limit for posting here then please attach it using the "Attachments and other options" link in the Reply editor.

I am a but confused with your explination. Could you maybe do like UKHeliBob said and try to upload the program.

Try it sideways and don't forget the lubrication.

KenF:
Try it sideways and don't forget the lubrication.

Something vexes thee sire?

ChilliTronix:
Something vexes thee sire?

Not really. It's about as useful as I can get without any source code to tamper with. Idle hands and all that.. :slight_smile:

KenF:
Not really. It's about as useful as I can get without any source code to tamper with. Idle hands and all that.. :slight_smile:

Yes not really helpful... There is also a button example in the IDE which shows a way to add it that works. If that doesn't work the code would have to be looked at.

There is also a button example in the IDE which shows a way to add it that works.

Add it to what to do what, where, when and how though ?

UKHeliBob:
Add it to what to do what, where, when and how though ?

I may still be right about the lubrication :slight_smile:

UKHeliBob:
Add it to what to do what, where, when and how though ?

Quite... for that we need the code, and I hasn't to add, no lubrication! :wink:

i can share the code but i know its to long to put on here.

Then post a smaller working section for evaluation.

heres the sketch. your see where i added the button. all i want it to do is to turn a led on and off and switch a few relays, then after that the sketch would return to its normal loop.

complete_house_code_adding_button.ino (16 KB)

OK, what exactly goes wrong when you insert your button?

I notice you use "if (buttonState == LOW)" So you're using the button as active LOW. So unless you have an external pullup resistor in your circuit, I suggest you change
pinMode(buttonPin, INPUT); TO pinMode(buttonPin, INPUT_PULLUP);

im jumping it to ground and pin 2. the issue im having is that the button doesnt work. no lights change or anything. the rest of the code keeps running fine but when i push the button nothing happens. just changed it with no change to operation.

metallica21156:
i have it set low because i was told inside the chip theres a built in resistor. im jumping it to ground and pin 3. the issue im having is that the button doesnt work. no lights change or anything. the rest of the code keeps running fine but when i push the button nothing happens.

It does have an internal resistor but only uses it if it's told to. Did you make the change I suggested?

yes i did and nothing happened

Your sketch waits for a card to be read (in setup). It doesn't go any further until a card is read.

THEN it will start the loop function, for a brief moment it will check button 2, then, once again it will wait for a card to be read, then for a very brief moment again, it will check button 2. etc..

I think you're just not holding down button 2 at the times it is actually looking at it as you're too busy fumbling with the card.

i just tried grounding the button while using the card and it does work as it should but i want it to run that part of the sketch anytime i press the button. not just when a card is read.

the button doesnt work.

I'm sure you'd have much better luck using a switch. You don't use switches to keep your shirts closed do you? Don't use buttons for switches, then.