Kang DongJunSung Yong Ahn
Published

Simple Arduino Game using SoundDetector

This is very easy Arduino game.

BeginnerShowcase (no instructions)2 hours1,406
Simple Arduino Game using SoundDetector

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
LED5MM-GREEN (and RED, BLUE)
×10
SparkFun Sound Detector
×1

Software apps and online services

Arduino IDE

Story

Read more

Schematics

Simple Arduino Game using SoundDetector

Code

Simple Arduino Game using SoundDetector

Arduino
This is very simple Arduino Game which use SoundDetecter Module.
1. Click Start button
2. Speak at module as long as possible.
3. The time is displayed as LED
#define button 11 //Start button
#define _signal 12 //Signal from Sound Sensor
#define notifyLED 13  // When starting, notification LED is ON

const int LED[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; //Using nine LEDs

void setup() {

  int i;
    
  pinMode(_signal, INPUT);
  pinMode(button, INPUT);
  pinMode(notifyLED, OUTPUT);
  for(i = 0; i < 9; i++) pinMode(LED[i], OUTPUT);

  digitalWrite(notifyLED, HIGH);
  for(i = 0; i < 9; i++) digitalWrite(LED[i], HIGH); // HIGH is off
    
  Serial.begin(9600); //Moniter Serial initialization
  
}

void loop() {

  int check, t, i;
  
  t = 10, check = 0;
    
  digitalWrite(notifyLED, HIGH);
    
  if(digitalRead(button))
  {
    while(digitalRead(button));
    
    for(i = 0; i < 9; i++) digitalWrite(LED[i], HIGH); //LED initialization

    Serial.println("Initialized!");
      
    digitalWrite(notifyLED, LOW);

    // checking
    do
    {
      if(digitalRead(_signal) == HIGH) check++;
      else check = 0; 
  
      delay(500);
    }while(check != 2);
  
    while(check)
    {
      t++; 
      delay(100);
           
      digitalWrite(LED[(t/20) - 1], LOW); //LED is ON every 2sec(100 * 20 = 2000ms)
           
      if(digitalRead(_signal) == LOW) check = 0;
    }
  
    Serial.println(t/10); //Measurement time
    
  }
  
  
}

Credits

Kang DongJun
0 projects • 1 follower
Hello, I'm student at KOTHS(in S.kroea). Mainly upload about IOT, MCU(like arduino, atmega), electronic circuit, 3D print.
Contact
Sung Yong Ahn
0 projects • 2 followers
Teacher_Technical high school
Contact

Comments

Please log in or sign up to comment.