Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino 101 Based Simon Says Game with Multi-Color LEDs and Buzzer

View and Edit Project In Cirkit DesignerImage of Arduino 101 Based Simon Says Game with Multi-Color LEDs and Buzzer

Circuit Documentation

Summary

This circuit is designed to create an interactive game using an Arduino 101 microcontroller. The game involves LEDs that light up in a random sequence, which the player must replicate using pushbuttons. A buzzer provides audio feedback for correct or incorrect sequences, as well as signaling game events. The circuit includes multiple LEDs of different colors, pushbuttons, resistors to limit current to the LEDs, and a buzzer for audio output.

Component List

LEDs

Pushbuttons

Resistors

Buzzer

Microcontroller

Wiring Details

LEDs

Pushbuttons

Resistors

Buzzer

Microcontroller

Documented Code

#include <Arduino.h>

// Pin definitions
const int ledPins[] = {2, 3, 4, 5};
const int buttonPins[] = {6, 7, 8, 9};
const int buzzerPin = 10;
const int startButtonPin = 11;

// Game variables
String led[] = {"a", "b", "c", "d"};
String sequence[10];  // Maximum level is 10, so sequence size is 10
int level = 1;
bool correct;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  
  // Set pins mode
  for (int i = 0; i < 4; ++i) {
    pinMode(ledPins[i], OUTPUT);
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(buzzerPin, OUTPUT);
  pinMode(startButtonPin, INPUT_PULLUP);

  // Seed the random number generator
  randomSeed(analogRead(0));

  // Print initial message
  Serial.println("Press the start button to begin.");
}

void loop() {
  // Wait for the start button press
  if (digitalRead(startButtonPin) == LOW) {
    debounce(); // Debounce function

    correct = true;

    while (correct && level <= 10) {
      // Generate a random sequence for the current level
      generateSequence();

      // Display the sequence to the player
      displaySequence();

      // Ask the player to input the sequence
      if (!waitForInput()) {
        correct = false;
        break; // Break out of the loop if input is incorrect
      }

      // Player wins, increase level
      level++;
      if (level > 10) {
        break; // Limit level to 10
      }
      playWinningSound();
    }

    // Play Nokia ringtone sound when game ends
    playNokiaRingtone();

    // Blink LEDs and keep them on
    blinkLeds();

    // Reset level
    level = 1;

    // Prompt to start again
    Serial.println("Press the start button to begin again.");
    waitForStartButtonRelease(); // Wait for start button release

    // Turn off LEDs after the game restarts
    turnOffLeds();
  }
}

// Additional functions such as debounce(), generateSequence(), displaySequence(),
// waitForInput(), waitForButtonPress(), playBuzzerSound(), playWinningSound(),
// playLosingSound(), playNokiaRingtone(), waitForStartButtonRelease(),
// blinkLeds(), keepLedsOn(), and turnOffLeds() are defined here.

This code is responsible for controlling the game logic, including initializing the game, generating and displaying the LED sequence, reading user input, and providing audio and visual feedback. The Arduino 101 microcontroller is programmed to interact with the connected components according to the game rules.