Help with multiple buttons controlling LEDS

I need help figuring out how to control three LEDS with three buttons. What I need is for when the buttons are pushed the light to go on. This is what I have so far (sorry I know this is probably stupid for y'all). Also this might be in the wrong forum section? I couldn't really tell so if it is please tell me.

int LEDG = 5;
int LEDY = 7;
int LEDR = 8;

int BONE = 9;
int BTWO= 10;
int BTHREE = 11;
void setup() {
//set the button pins as inputs
pinMode(LEDG, OUTPUT);
pinMode(LEDY, OUTPUT);
pinMode(LEDR, OUTPUT);

//set the buzzer pin as an output
pinMode(BONE, INPUT);
pinMode(BTWO, INPUT);

void loop() {
int StateBONE = digitalRead(BONE);
int StateBTWO = digitalRead(BTWO);
int StateBTHREE = digitalRead(BTHREE);

if(StateBONE == 1) {
digitalWrite(LEDG, HIGH);
} else if(StateBTWO == 1) {
digitalWrite(LEDY, HIGH);
else if (StateBTHREE == 1) {
digitalWrite(LEDR, HIGH);
else {
digitalWrite(LEDG, LOW);
digitalWrite(LEDY, LOW);
digitalWrite(LEDR, LOW);

What’s not working ?


Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags [code]Paste your sketch here[/code]

You need to use a pull-up or pull-down resister for buttons to avoid the floating input problem. See Arduino button tutorial for detail. The simplest way is to use internal INPUT_PULLUP.
You also can refer to Arduino Button controls LED tutorial.

Thanks Guys! With a little help from a friend and your suggestions i managed to get it to work. thanks for your help

It is good news that you got it working. I assume that you have made changes to your code because in the original if button ONE was pressed then the others would be ignored, unless that was what was intended to happen

Please post your working code and explain the changes. It might help someone else in the future