Game show buzzers

I'm trying to build a set of reach for the top buzzers. There will be eight buttons and each button will also correspond with two LEDs. One on the buttons and one on the actual box. Once someone presses a button, the corresponding LEDs will light up and every other person's push will be blocked out. What I am having trouble with is I am not sure if there are enough pins on the Arduino Uno I have. I will need 16 pins and the Arduino only has 14 input/output pins. Anyone got any suggestion?

Alex

I will need 16 pins and the Arduino only has 14 input/output pins. Anyone got any suggestion?

Use the analogue pins as digital pins.

The Arduino Uno has 20 I/O pins, although it's best to keep pins 0 and 1 free for debugging using the serial port. So you've 18 pins left. This includes the analog ports, which you can use as digital ports too.

OK thanks. What's the difference between analog and digital ports?

Alex

Analog ports on the Arduino can do that same things that digital ports can, and they can be used to read voltages as well.

Thanks for the help. I should be fine for now.

How do I declare that a button is connected to the analog pin? Putting "int Button5 = A5;" works but I don't know if it is the right way.

Alex

Putting "int Button5 = A5;" works but I don't know if it is the right way.

It is.

Unless there is some reason to be able to change pins while the sketch is running (not likely) you should use const in front of that statement.

OK Thanks. I've been working on the code and I am having a bit of trouble making the LED light up based on the button's state.

Here is my code so far. What am I doing wrong?

int led1 = 2; int led2 = 3; int led3 = 4; int led4 = 5; int led5 = 6; int led6 = 7; int led7 = 8; int led8 = 9; int Button1 = 10; int Button2 = 11; int Button3 = 12; int Button4 = 13; int Button5 = A5; int Button6 = A4; int Button7 = A3; int Button8 = A2;

void setup() { Serial.begin(9600); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(Button1, INPUT); pinMode(Button2, INPUT); pinMode(Button3, INPUT); pinMode(Button4, INPUT); pinMode(Button5, INPUT); pinMode(Button6, INPUT); pinMode(Button7, INPUT); pinMode(Button8, INPUT); }

void loop() { int buttonState = digitalRead(Button1); Serial.println(buttonState); delay(1); if (buttonState == LOW) { digitalWrite(led1, HIGH); delay(1000); digitalWrite(led1, LOW); }

I combined two of their basic examples. Any idea?

I would like to see more code tags. Pull ups on the switches. You're not using the built in ones, so have you got external ones?

Sorry about that. I am using external Momentary Switches. The loop is only made for the first button. I am not sure how to get it to read the button and then make it turn the LED on

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 = 9;
int Button1 = 10;
int Button2 = 11;
int Button3 = 12;
int Button4 = 13;
int Button5 = A5;
int Button6 = A4;
int Button7 = A3;
int Button8 = A2;

void setup() {                
  Serial.begin(9600);
  pinMode(led1, OUTPUT);     
  pinMode(led2, OUTPUT);    
  pinMode(led3, OUTPUT);    
  pinMode(led4, OUTPUT);    
  pinMode(led5, OUTPUT);    
  pinMode(led6, OUTPUT);    
  pinMode(led7, OUTPUT);    
  pinMode(led8, OUTPUT);
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);    
  pinMode(Button3, INPUT);    
  pinMode(Button4, INPUT);    
  pinMode(Button5, INPUT);    
  pinMode(Button6, INPUT);    
  pinMode(Button7, INPUT);    
  pinMode(Button8, INPUT);          
}

void loop() {
  int buttonState = digitalRead(Button1);
  Serial.println(buttonState);
  delay(1);
  if (buttonState == LOW) 
  {
    digitalWrite(led1, HIGH); 
    delay(1000);              
    digitalWrite(led1, LOW);    
}

And the pull ups?

Sorry I'm new to this. What are pull ups?

If an input pin is unconnected, it is said to be floating, and could read a high or low depending on...well, a whole load of things. A pin connected only to an open switch is floating, so we connect it either the supply or ground via a fairly high value resistor. This is called a pull up or pull down. If you read the documentation for pinMode you'll see that the processor is thoughtfully provided with pull ups, which you're not currently using.

Oh ok. I did some reading. How do I use the pullup resistors? On the page about digital pins, it gives this line of code:

pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors

Is that what I need to do for every button?

Yes, you have to do it for all your inputs. If you're using the latest IDE, you can set input and pullup with a single pinMode per pin. I think this is mentioned in the documentation. Arrays and for loops would simplify things.

Is that what I need to do for every button?

That, and to connect the switches correctly, and interpret the value from digitalRead() correctly.

One side of the switch goes to the digital pin. The other side goes to ground.

The value will be HIGH until the switch is pressed. Then, it will be LOW (just like the top of the switch).

Without the pullups, the LED stays on the whole time and pressing the button briefly shuts it off. When I add the pullups in, it just doesn’t light anymore. Is there something wrong with my code where I read the button state?

OK here is a new version of the code. It still doesn't work though.

    int button1 = 0;
    void setup() {
    pinMode(2, OUTPUT);
    pinMode(10, INPUT);}

    void loop() {
    digitalWrite(10, HIGH);
    button1 = digitalRead(10);
    if (button1 == LOW) {
    digitalWrite(2, HIGH);
    }
    }

What does your serial output button test program show?