Speaker
Explore with your favorite AI
Gemini & other AI
Copy this page’s context into your AI to explore how it works and what you can build.
Copy the prompt, then paste it into Gemini’s message box.
View prompt
Overview
Section titled “Overview”Use the piezoelectric loudspeaker in the SP&PIR Leaf to make the melody sound.
Leaf to use
Section titled “Leaf to use”Use the following leaves.
| Type | Name | Q’ty |
|---|---|---|
| AI02 | SP&PIR | 1 |
| AP03 | STM32 MCU | 1 |
| AV01 | CR2032 | 1 |
| AZ01 | USB | 1 |
| AZ62 | Connector Cover | 1 |
| CR2032 coin cell battery | 1 | |
| M2*15mm screw | 2 |
Assembly
Section titled “Assembly”Let’s assemble leaves as shown in the figure below.
Source code
Section titled “Source code”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.1
- Change the
8toPB4in line 37.
tone(PB4, melody[thisNote], noteDuration);- Change
8toPB4in line 44.
noTone(PB4);Execution Results
Section titled “Execution Results”The melody sounds only once from the speakers.