yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Roboduino V2📖
0.Instruction manual
  • Instruction manual
1.Get started quickly
  • 01.Assembly of the Car
  • 02.Remote Control Car
  • 03.Common Problem Analysis
  • 04. Lithium Battery Pack and Charger Usage Guidelines
  • 05. Important Notes (Read Before Starting)
2.Environment Construction
  • 01.Serial port driver installation
  • 02.Arduino IDE Installation
  • 03.Arduino IDE usage
  • 04.Using third-party libraries
  • 05.Program compilation and upload
3.Basic car course
  • 01.RGB Control
  • 02.Serial Print
  • 03.KEY Read
  • 04.Buzzer control
  • 05.Logo Breath
  • 06.Servos Control
  • 07.Motor Control
  • 08.Ultrasonic Ranging
  • 09.Track Print
  • 10.Infrared Remote Print
  • 11.WIFI Camera
4.Advanced car course
  • 01.RGB Breath
  • 02.Play Music
  • 03.KEY Control RGB
  • 04.KEY Control Buzzer
  • 05.Serial Parse Data
  • 06.Parse Data Control Motor
  • 07.Parse Data Control RGB
  • 08.Parse Data Control Buzzer
  • 09.Parse Data Control Servo
5.Car motion control
  • 00.Mecanum wheel motion principle
  • 01.Car Vertical Movement
  • 02.Car Diagonal Movement
  • 03.Car Sideways Movement
  • 04.Car Rotational Movement
  • 05.Car Patrol
6.Comprehensive gameplay of car
  • 01.Car tracking
  • 02.Car Obstacle Avoid
  • 03.Car Follow Hand
  • 04.Car tracking Avoid
  • 05.Car Infrared Remote
  • 06.WiFi Control Car
  • 07.IR WiFi Control Car
7.AI vision course
  • 1. Cat(dog) detection
  • 2. Color recognition
  • 3. QR code instructions
  • 4. Person Recognition
  • 5. Face Detection
  • 6. Color Follows
  • 7. Face following
8.Expand peripherals
  • 01.Digital Tube Display
  • 02.Color Recognition
Download
  • Code
  • Library
  • Hardware manual
  • Software
  • 3D Model
  • Instruction Manual
Download ZIP

Welcome to Roboduino V2 repository

02.Play Music

Play Music

Play MusicDevice connectionHardware connectionSoftware connectionBuzzer controlControl principleControl pinsCodeExperimental results

Control the passive buzzer on the Robduino expansion board to play a short piece of music "Twinkle Twinkle Little Star".

Device connection

Hardware connection

Use Type-B data cable to connect Arduino Uno and computer.

Software connection

Open the "Arduino IDE" software and select the model and serial port number corresponding to the development board.

Buzzer control

Buzzers are divided into two types: active buzzers and passive buzzers.

Active buzzers: require external working voltage to emit fixed frequency sound;

Passive buzzers: require external circuit to provide driving signal, and control the pitch and loudness of the sound by changing the frequency and amplitude of the signal.

Control principle

Arduino's tone library can be used to control the digital pin on the Arduino board to output a square wave signal of a specified frequency, thereby driving the buzzer connected to the pin to play a specified tone.

Control pins

Peripheral moduleArduino Uno
Buzzer10

Code

Here we will only briefly introduce the code content. For detailed code, please refer to the corresponding code file, which is provided in the download area!

  • Define BUZZER control pins

x
// 定义蜂鸣器控制引脚 Define BUZZER control pins
#define BUZZER_PIN 10
  • Play tones of a specific frequency and time

x
/**
 * @brief 播放具体频率和时长的音调 Play tones of a specific frequency and time
 * @param frequency: 音调频率 Tone frequency
 * @param duration: 持续时间 time of duration
 * @retval 无 None
 */
void playMusic(int frequency, int duration) {
  tone(BUZZER_PIN, frequency);
  delay(duration);
  noTone(BUZZER_PIN);
}
  • Initialization Code

x
void setup() {
  pinMode(BUZZER_PIN, OUTPUT);  // 设置蜂鸣器引脚输出模式 Set the buzzer pin output mode
}
  • Looping code

​x
void loop() {
  // Twinkle, twinkle, little star
  playMusic(523, 500);
  delay(100);
  playMusic(523, 500);
  delay(100);
  playMusic(587, 500);
  delay(100);
  playMusic(587, 500);
  delay(100);
  playMusic(659, 500);
  delay(100);
  playMusic(659, 500);
  delay(100);
  playMusic(587, 500);
  delay(1000);

  // How I wonder what you are
  playMusic(523, 500);
  delay(100);
  playMusic(493, 500);
  delay(100);
  playMusic(440, 500);
  delay(100);
  playMusic(440, 500);
  delay(100);
  playMusic(493, 500);
  delay(100);
  playMusic(493, 500);
  delay(1000);

  // Up above the world so high
  playMusic(523, 500);
  delay(100);
  playMusic(587, 500);
  delay(100);
  playMusic(659, 500);
  delay(100);
  playMusic(659, 500);
  delay(100);
  playMusic(587, 500);
  delay(100);
  playMusic(523, 500);
  delay(1000);
}

Experimental results

After compiling the program successfully, upload the code to the Arduino Uno development board.

After the program is started, the buzzer will play a short piece of music from the song "Twinkle Twinkle Little Star" in a loop!

xxxxxxxxxx
The burning program cannot use other programs to occupy the serial port or an external serial communication module (for example: WiFi camera module), otherwise the program cannot be burned or an error message will be prompted!
RGB Breath
KEY Control RGB

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文