Skip to content
ショップ

Speaker

Use the piezoelectric loudspeaker in the SP&PIR Leaf to make the melody sound.

Use the following leaves.

TypeNameQ’ty
AI02SP&PIR1
AP01AVR MCU1
AV01CR20321
AZ01USB1
AZ62Connector Cover1
CR2032 coin cell battery1
M2*15mm screw2

Let’s assemble leaves as shown in the figure below.

assemble1

Open the Arduino, go to File → Sketch Examples → 02.Digital → toneMelody.

In this sample code, the speaker is supposed to be connected to pin number 8.
But as the loudspeaker is connected to pin 5 in Leafony, you should fix the following part to make it correct.

  • Change the 8 to 5 in line 37.
tone(5, melody[thisNote], noteDuration);
  • Change 8 to 5 in line 44.
noTone(5);

The melody sounds only once from the speakers.