Project 2 - Super Saiyan Hat
For my second project, I made a wearable hat with LEDS that should light up based off sound frequency with the mic amplifier. The hat consists of four LEDS that is stabbed through a breadboard and the other breadboard contains the microphone amplifier and the PCB mini speaker. The mic amplifier is really clunky and doesn’t stick to the board very well so it doesn’t take in sound very well. For some reason, the speaker doesn’t make any sound either once the LEDs light up.
CODE
/* Melody
Plays a melody
circuit: - 8 ohm speaker on digital pin 8
created 21 Jan 2010 modified 30 Aug 2011 by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone */
#include "pitches.h"
int led1 = 2; int led2 = 3; int led3 = 4; int led4 = 5;
int sensorPin = A0; // input pin for the sensor int sensorval = 0; // variable for the value coming from the sensor int SPEAKER = 8;
// notes in the melody: int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 };
// note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };
void setup() {
// initialize the digital pin as an output. pinMode(led1,OUTPUT); pinMode(led2,OUTPUT); pinMode(led3,OUTPUT); pinMode(led4,OUTPUT);
pinMode(sensorPin, INPUT); // initialize sensor as input Serial.begin(9600); // initialize serial communication with computer
}
void loop() { sensorval = analogRead(sensorPin); // read the value from the sensor Serial.println(sensorval); // send it to the computer's serial port screen
if (sensorval > 600) { digitalWrite(led1, HIGH); for(int i =0; i < 8; i++){ tone(SPEAKER, melody[i],noteDurations[i]); delay(noteDurations[i]); } } else { digitalWrite(led1,LOW); } if (sensorval > 600) { digitalWrite(led2, HIGH); }else { digitalWrite(led2,LOW); } if (sensorval > 600) { digitalWrite(led3, HIGH); } else { digitalWrite(led3,LOW); } if (sensorval > 600) { digitalWrite(led4, HIGH); } else{ digitalWrite(led4,LOW); }
delay(100);
}













