light + tone – hw-w2


This is a simple sound instrument using two light sensors (one for tone and one for rhythm)  + a speaker + RGB LED connected to the whole circuit that shows the behavior of sound by changing color and pace.

this video shows the change in tone using the light dimmer at home

this one shows the change in beat using the iPhone flashlight (not perfect)

Click below to see the code

int ledPin = 9;
int lightSensor1 = A0;
int lightSensor2 = A1;
int speaker = 3;
int sensorValue1;
int sensorValue2;

void setup (){
// first set led and speaker as output
pinMode (speaker, OUTPUT);
pinMode (ledPin, OUTPUT);

//start serial connection
Serial.begin (9600);


void loop () {

//put the sensorValue into a variable
sensorValue1 = analogRead(lightSensor1);
sensorValue2 = analogRead(lightSensor2);

//show on Serial Monitor
// use the comma to make a space
Serial.print(“, “);
//use the ln to make a new line for the next reading

//a tone is between 20 and 20000 but for arduino is better from 200 to 2000
//tone(speaker, 1500);

//connect the lightSensor with the speaker
//change the lightsensor value into the speaker value

tone(speaker, map (sensorValue1, 0, 1000, 200,3000));

int mappedSensor2 = map (sensorValue2, 0, 1000, 3000, 20);
// change the sensorlight value to a brightness value
int brightness = map (sensorValue1, 0, 1000, 10, 255);
//  digitalWrite(ledPin, HIGH);

//use analogWrite to have a range
analogWrite (ledPin, brightness);


analogWrite(ledPin, 0);




Leave a Reply

Your email address will not be published. Required fields are marked *