What's new

Help Arduino code for 10 player quiz game

nbtesara

Honorary Poster
Established
Hi Guys baka may magaling dyan sa arduino coding gusto ko sana magpalaro for 10 players na quiz game ano po kaya code para makaset-up po ako na may tunog at ilaw na pwede paganahin lang ng 12 volts at kapag pinindot yung isang buzzer tutunog at iilaw siya ng 5 seconds at the rest di na gagana ng 5 seconds. Salamat
 
Hello! I can definitely assist you with your project.

To start, you will need to have the following components:
  • Arduino Uno board
  • 10 push buttons
  • 10 LEDs
  • 10 buzzers
  • Jumper wires
  • Breadboard
  • Power supply (12V DC)

Here's a sample code that you can use as a basis for your project:

Code:
// Define variables
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the LED pins
int buzzerPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // An array to hold the buzzer pins
int buttonPins[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // An array to hold the button pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button

void setup() {
  // Set the LED pins as outputs
  for (int i = 0; i < 10; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  
  // Set the buzzer pins as outputs
  for (int i = 0; i < 10; i++) {
    pinMode(buzzerPins[i], OUTPUT);
  }
  
  // Set the button pins as inputs
  for (int i = 0; i < 10; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  
  // Set up Serial communication
  Serial.begin(9600);
}

void loop() {
  // Check if any button has been pressed
  for (int i = 0; i < 10; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      buttonPressed = true;
      buttonPressedIndex = i;
      break;
    } else {
      buttonPressed = false;
    }
  }
  
  // If a button has been pressed, light up the corresponding LED and sound the buzzer
  if (buttonPressed) {
    digitalWrite(ledPins[buttonPressedIndex], HIGH);
    tone(buzzerPins[buttonPressedIndex], 1000, 5000); // Sound the buzzer for 5 seconds
    delay(5000); // Wait for 5 seconds
    digitalWrite(ledPins[buttonPressedIndex], LOW);
  }
}

This code sets up the 10 LEDs, 10 buzzers, and 10 push buttons. Once a button is pressed, the corresponding LED will light up and the corresponding buzzer will sound for 5 seconds. After the 5 seconds, the LED will turn off and the buzzer will stop.

You will need to modify the code to include your own questions and logic for keeping track of the score, but this should give you a good starting point.

I hope this helps! Let me know if you have any questions or need further assistance.
 
Hello! I can definitely assist you with your project.

To start, you will need to have the following components:
  • Arduino Uno board
  • 10 push buttons
  • 10 LEDs
  • 10 buzzers
  • Jumper wires
  • Breadboard
  • Power supply (12V DC)

Here's a sample code that you can use as a basis for your project:

Code:
// Define variables
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the LED pins
int buzzerPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // An array to hold the buzzer pins
int buttonPins[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // An array to hold the button pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button

void setup() {
  // Set the LED pins as outputs
  for (int i = 0; i < 10; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
 
  // Set the buzzer pins as outputs
  for (int i = 0; i < 10; i++) {
    pinMode(buzzerPins[i], OUTPUT);
  }
 
  // Set the button pins as inputs
  for (int i = 0; i < 10; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
 
  // Set up Serial communication
  Serial.begin(9600);
}

void loop() {
  // Check if any button has been pressed
  for (int i = 0; i < 10; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      buttonPressed = true;
      buttonPressedIndex = i;
      break;
    } else {
      buttonPressed = false;
    }
  }
 
  // If a button has been pressed, light up the corresponding LED and sound the buzzer
  if (buttonPressed) {
    digitalWrite(ledPins[buttonPressedIndex], HIGH);
    tone(buzzerPins[buttonPressedIndex], 1000, 5000); // Sound the buzzer for 5 seconds
    delay(5000); // Wait for 5 seconds
    digitalWrite(ledPins[buttonPressedIndex], LOW);
  }
}

This code sets up the 10 LEDs, 10 buzzers, and 10 push buttons. Once a button is pressed, the corresponding LED will light up and the corresponding buzzer will sound for 5 seconds. After the 5 seconds, the LED will turn off and the buzzer will stop.

You will need to modify the code to include your own questions and logic for keeping track of the score, but this should give you a good starting point.

I hope this helps! Let me know if you have any questions or need further assistance.
// Define variables
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the LED pins
int buzzerPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // An array to hold the buzzer pins
int buttonPins[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // An array to hold the button pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button

void setup() {
// Set the LED pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(ledPins, OUTPUT);
}

// Set the buzzer pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(buzzerPins, OUTPUT);
}

// Set the button pins as inputs
for (int i = 0; i < 10; i++) {
pinMode(buttonPins, INPUT_PULLUP);
}

// Set up Serial communication
Serial.begin(9600);
}

void loop() {
// Check if any button has been pressed
for (int i = 0; i < 10; i++) {
if (digitalRead(buttonPins) == LOW) {
buttonPressed = true;
buttonPressedIndex = i;
break;
} else {
buttonPressed = false;
}
}

// If a button has been pressed, light up the corresponding LED and sound the buzzer
if (buttonPressed) {
digitalWrite(ledPins[buttonPressedIndex], HIGH);
tone(buzzerPins[buttonPressedIndex], 1000, 5000); // Sound the buzzer for 5 seconds
delay(5000); // Wait for 5 seconds
digitalWrite(ledPins[buttonPressedIndex], LOW);
}
}
Hi BOT can you revised the code using 10pcs 5 volt relays and also the led and buzzer should have same pins thanks
 
// Define variables
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the LED pins
int buzzerPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // An array to hold the buzzer pins
int buttonPins[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // An array to hold the button pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button

void setup() {
// Set the LED pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(ledPins, OUTPUT);
}

// Set the buzzer pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(buzzerPins, OUTPUT);
}

// Set the button pins as inputs
for (int i = 0; i < 10; i++) {
pinMode(buttonPins, INPUT_PULLUP);
}

// Set up Serial communication
Serial.begin(9600);
}

void loop() {
// Check if any button has been pressed
for (int i = 0; i < 10; i++) {
if (digitalRead(buttonPins) == LOW) {
buttonPressed = true;
buttonPressedIndex = i;
break;
} else {
buttonPressed = false;
}
}

// If a button has been pressed, light up the corresponding LED and sound the buzzer
if (buttonPressed) {
digitalWrite(ledPins[buttonPressedIndex], HIGH);
tone(buzzerPins[buttonPressedIndex], 1000, 5000); // Sound the buzzer for 5 seconds
delay(5000); // Wait for 5 seconds
digitalWrite(ledPins[buttonPressedIndex], LOW);
}
}
Hi BOT can you revised the code using 10pcs 5 volt relays and also the led and buzzer should have same pins thanks
Sure, here's a revised code that uses 10 5V relays and the LEDs and buzzers share the same pins:

Code:
// Define variables
int relayPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the relay pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button

void setup() {
  // Set the relay pins as outputs
  for (int i = 0; i < 10; i++) {
    pinMode(relayPins[i], OUTPUT);
  }
 
  // Set the button pins as inputs
  for (int i = 12; i < 22; i++) {
    pinMode(i, INPUT_PULLUP);
  }
 
  // Set up Serial communication
  Serial.begin(9600);
}

void loop() {
  // Check if any button has been pressed
  for (int i = 0; i < 10; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      buttonPressed = true;
      buttonPressedIndex = i;
      break;
    } else {
      buttonPressed = false;
    }
  }
 
  // If a button has been pressed, activate the corresponding relay
  if (buttonPressed) {
    digitalWrite(relayPins[buttonPressedIndex], HIGH);
    delay(5000); // Wait for 5 seconds
    digitalWrite(relayPins[buttonPressedIndex], LOW);
  }
}

In this code, the LED and buzzer pins were removed since the relays will be used instead. The 10 relay pins are defined in the relayPins array, and the button pins are defined from 12 to 21.

When a button is pressed, the corresponding relay will be activated for 5 seconds, lighting up an LED or sounding a buzzer that is connected to the relay.

I hope this helps! Let me know if you have any questions or need further assistance.
 
Back
Top