//1. Range of the analog input void setup() { Serial.begin(9600); // initialize serial communications } void loop() { int analogValue = analogRead(A0); // read the analog input Serial.println(analogValue); // print it }
SOLDERING
I tried to figure out why circuit was not working. Since Arduino read and printed analog input fine, I could know there was a problem with speaker circuit. I found out that the ‘+’ wire from the speaker was not connected right. It should’ve connected to D8 not ‘+’ of a breadboard. Finally, I made a sound come off from the speaker.
//2. Play Tones void setup() { } void loop() { // get a sensor reading int sensorReading = analogRead(A0); // map the results from the sensor reading's range // to the desired pitch range: float frequency = map(sensorReading, 0, 1000, 100, 1000); // change target range will change pitch // change the pitch, play for 10 ms: tone(8, frequency, 10); }
P5 reference
Arduino Reference
Idea sketch