Hello again and a warm welcome to my series “12 Days of Arduino” Day 5. Today we use a photoresistor to alter the pitch of our tone, effectively enabling us to reach every single note, making this a truly practical instrument of 8 bit glory!
Project requires
–Arduino Uno
–Active buzzer
–3x button touch switch
-220 ohm resistor
-4x 10k ohm resistor
-2x 220 ohm resistor
-Jumper wires
-Tip120
-SN74HC595
-Photoresistor
I know it’s hard to see the circuitry in the video, things are starting to get crowded. Maybe I’ll upload a diagram if I get some time after the series is complete.
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
int number = 1;
int speakerPin = 6;
//Buttons
int button1Pin = 2;
int button2Pin = 3;
int button3Pin = 4;
int photoresistorPin = A0;
int sensorValue = 0;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
}
void loop() {
if(digitalRead(button1Pin) == HIGH){
sensorValue = analogRead(photoresistorPin);
tone(speakerPin, 790 +(sensorValue*2));//A5
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else if(digitalRead(button2Pin) == HIGH){
sensorValue = analogRead(photoresistorPin);
tone(speakerPin, 1750 +(sensorValue*2));//A6
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else if(digitalRead(button3Pin) == HIGH){
sensorValue = analogRead(photoresistorPin);
tone(speakerPin, 3510+(sensorValue*2));//A7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else{
number = 0;
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
}
}
If you aren’t a registered member of KevinGulling.com, and don’t want to register, feel free to comment on the YouTube video, I read those as well.
Visit ICStation.com for the best prices on sensors: