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?
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. 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;
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);
}
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.
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.
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?