Lesson 8 – Who’s Singing
Introduction
In the previous lesson, we have learned how to make a sound. In this lesson, we will use another type of buzzer to code the melody of a song. It’s called a passive buzzer. Using the codes we gave you, this lesson is also quite simple.
Hardware Required
- EASY plug controller Board *1
- USB cable *1
- EASY plug cable *1
- EASY plug Passive Buzzer Module *1
Connection Diagram
Now, connect the module to the D8 port of the controller board using the EASY plug cable.
Code
Arduino IDE – Open up the Arduino IDE and copy the code provided below. Then connect the board to your PC using the USB cable and click upload to upload it to your board.
#define D0 -1 #define D1 262 #define D2 293 #define D3 329 #define D4 349 #define D5 392 #define D6 440 #define D7 494 #define M1 523 #define M2 586 #define M3 658 #define M4 697 #define M5 783 #define M6 879 #define M7 987 #define H1 1045 #define H2 1171 #define H3 1316 #define H4 1393 #define H5 1563 #define H6 1755 #define H7 1971 // List all D tune frequency #define WHOLE 1 #define HALF 0.5 #define QUARTER 0.25 #define EIGHTH 0.25 #define SIXTEENTH 0.625 // list all tempos int tune[]= // List each frequency according to numbered musical notation { M3,M3,M4,M5, M5,M4,M3,M2, M1,M1,M2,M3, M3,M2,M2, M3,M3,M4,M5, M5,M4,M3,M2, M1,M1,M2,M3, M2,M1,M1, M2,M2,M3,M1, M2,M3,M4,M3,M1, M2,M3,M4,M3,M2, M1,M2,D5,D0, M3,M3,M4,M5, M5,M4,M3,M4,M2, M1,M1,M2,M3, M2,M1,M1 }; float durt[]= // list all tempo according to numbered musical notation { 1,1,1,1, 1,1,1,1, 1,1,1,1, 1+0.5,0.5,1+1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1+0.5,0.5,1+1, 1,1,1,1, 1,0.5,0.5,1,1, 1,0.5,0.5,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0.5,0.5, 1,1,1,1, 1+0.5,0.5,1+1, }; int length; int tonepin=8; // set module signal pin to D8 void setup() { pinMode(tonepin,OUTPUT); length=sizeof(tune)/sizeof(tune[0]); // calculate length } void loop() { for(int x=0;x<length;x++) { tone(tonepin,tune[x]); delay(500*durt[x]); // this is use to adjust tempo delay, you can change the number to your liking. noTone(tonepin); } delay(2000); }
Output
The buzzer will play Ode to Joy, and then pause for 2S.
Prerequisites
This development track requires an investment a bit of hardware. See below for details –
- You will need to download and install the Arduino development IDE or the mixly block based graphical programming interface. The approach to installation, configuration, setup of the Arduino IDE is covered in our tutorials.
- The mixly block based graphical programming interface will allow you to work through the tutorials in the learning track and write the code using a block based graphical programming interface.
- You will need to purchase the Easy Plug Starter Learning Kit for Arduino from OzToyLib. The Arduino Advent kit has all the sensors you need to perform the tutorials covered in this development track.
- This kit ships with an Arduino Uno. You should be able to perform each of the tutorials in this track using the Arduino board included in the package.
- You can also purchase additional Arduino boards i.e. Arduino Mega 2560 from OzToyLib.
The Easy Plug Starter Learning Kit for the Arduino kit has all the sensors you need to perform the tutorials covered in this development track.
About the Easy Plug Super Learning Kit for Arduino
The Easy Plug Starter Learning Kit for the Arduino comes packed with ~30+ different electronic bits (Sensors, LEDs, switches, LCD, servo, etc.) including tutorials to get started. The Easy Plug Starter Learning Kit comes with specially designed easy to use sensors including an easy to use Arduino board. Both the sensors and the Arduino board are design for eas of use eliminating the need to work out how to connect the sensors to the board and get the circuit right. The RJ11 connectors on board the sensors and the Arduino board are meant to simplify construction of the circuit, reducing the potential for connection errors allowing you to focus on design of the code. The Easy Plug Starter kit for the Arduino is especially suited to someone who is just starting out with electronics or the Arduino or even someone who doesn’t necessarily have the expertise available locally to help out with connections. We would recommend this kit to both kids and adults getting started with the STEM learning journey with a focus on electronics and Arduino.
The Arduino advanced study kit walks you through the basics of using the Arduino in a hands-on way. You’ll learn the fundamentals of electronics and working on the Arduino through building several creative projects. The kit includes a selection of the most common and useful electronic components with a book of 22 projects. Starting the basics of electronics, to more complex projects, the kit will get you interacting with the physical world using sensor and actuators. Along with the kit you get access to detailed tutorials and wiring diagrams.
You can purchase the Easy Plug Starter Learning Kit for Arduino from OzToyLib.
About the Arduino UNO
The Arduino UNO is the most used and documented board of the whole Arduino family and very easy to setup, play with. The Arduino UNO is a microcontroller board based on the ATmega328 . The Arduino UNO has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. Here’s a listing of the some of the features of the Arduino UNO –
- Microcontroller: ATmega328
- Operating Voltage: 5V
- Input Voltage (recommended): 7-12V
- Input Voltage (limits): 6-20V
- Digital I/O Pins: 14 (of which 6 provide PWM output)
- Analog Input Pins: 6
- DC Current per I/O Pin: 40 mA
- DC Current for 3.3V Pin: 50 mA
- Flash Memory: 32 KB of which 0.5 KB used by bootloader
- SRAM: 2 KB (ATmega328)
- EEPROM: 1 KB (ATmega328)
- Clock Speed: 16 MHz
Arduino is an open-source, prototyping platform and its simplicity makes it ideal for hobbyists to use as well as professionals. The Arduino UNO contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Arduino UNO differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega8U2 microcontroller chip programmed as a USB-to-serial converter. “Uno” means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Arduino Uno and version 1.0 will be the reference versions of Arduno, moving forward. The Uno is the latest in a series of USB Arduino boards, and the reference model for the Arduino platform.
You can read more about the Arduino here – www.arduino.cc.