Micro:bit small experiments: music at the tip of a pen

29/09/2022
image
This time, let's do the classic little experiment of Micro:bit together: pencil music. Use a pencil to draw a thick graphite line on a piece of paper, and use an alligator clip to connect the Micro:bit board, the headphones, and the graphite line. After programming, the headphones can play changing tones when the alligator clips are moved on the graphite wire.
micro:bit
1. Component list

Micro:bit main board × 1, A4 paper × 1, pencil (HB, 2B \ 6B) × 1, alligator clip wire × 4, headphones × 1.

2. Test principle

Micro:bit pins P0, P1, P2, P3, P4, P10 are able to read the analog voltage of the pins. The return value of the analog voltage is Value (0-1023), and the voltage value (Volt) is calculated as Volt = 3.3 × (Value/1024). micro:bit needs to form a current path when reading the voltage. pins P0, P1, P2, P3, P4, and P10 are positive, and GND is shorthand for the ground terminal of the wire. It represents the ground or 0 line. This ground is not really ground, is assumed for the application of a ground, for the power supply, it is the negative side of the power supply.

Graphite is a conductor can conduct electricity but has a high resistance. Graphite wire drawn on paper by pencil can be used as a variable resistance, when the alligator clips move on the graphite wire changes the length of the graphite wire and also changes the resistance value. According to the formula when the current I is certain, the voltage U and resistance R are proportional: I=U/R. The change of resistance causes the voltage read by Micro:bit will also change, we read the analog voltage value of the pin as the frequency value of the output tone, and move the alligator clip can change the tone of the output sound. Figure 2

3. Hardware connection


Micro:bit pin connection diagram

1) First we need to use a pencil to draw a line on A4 paper, a section of the line should be on the edge of the paper, to draw a thicker and thicker.

2) Use one alligator clip wire (black) to connect the ground of the headphone to the GND pin, and one alligator clip wire (red) to connect the left channel to pin 0.


Headphone interface

3) Use 1 alligator clip wire (yellow) to connect one end of the graphite wire to the GND pin. Use 1 alligator clip wire (green) to clip one end to pin 1 and hold the remaining end in your hand to move along the graphite wire.

4. Program writing

1) First we need to create a variable "Tone" to record the change of voltage value collected on pin P1.

2) Set the "Tone" variable to: Advanced → Pin → Analog Read Pin P1.

3) In order to make the change in pronunciation more obvious, artificially increase the pitch frequency. Multiply the "Pitch" value by 4.

4) Measure the reading value of the pin on the white paper (my measurement value is 1200), as the base data when the circuit is broken, when the "tone" is higher than this base value, the line is not considered to be inoperative, and no sound is played. This display digital blocks only temporary use, after measuring to their own base value can be deleted this block.


Measuring the base value

5) Determine when the variable pitch is less than 1200 to play the sound, otherwise no sound will be played.

6) Infinite loop, play the tone at the frequency of the variable "tone" Hertz (HZ), the larger the value the higher the tone. Save the code and copy it into the Micro:bit board and you can start experimenting.


Programming Code

7) You can switch to drawing graphite lines of different thicknesses with HB, 2B, or 6B pencils to hear how the sound is different. Think about what we have already learned about physics and consider the relationship between the magnitude of the resistance value and the material, temperature, length, and cross section. Do these relationships with graphite wires of different materials, lengths, and thicknesses match what you already know.

PI-SUPPLY is a professional component supplier, providing everything you need for your component project. We also stock a huge selection of Raspberry piArduinomicro:bitrock pi and nvidia manufacturer accessories from your favorite brands.