Digital INPUT/OUTPUT - Tone output

//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

IMG_0077.jpg

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

Screen Shot 2019-10-01 at 11.21.20 PM.png
Screen Shot 2019-10-02 at 9.58.49 AM.png
 

Arduino Reference

Screen Shot 2019-10-02 at 9.41.43 AM.png
Screen+Shot+2019-10-02+at+9.48.48+AM.jpg
IMG_0073.jpg

Idea sketch