ESP32 Easy Coding Board

1. Development Board

Link:http://keyestudio-ks5018.readthedocs.io/


2. Kidsblock Software

2.1 Installation

Windows System

  1. Download:

  2. After downloading, click to open “KidsBlock.exe”img

  3. Tick “Anyone who uses this computer(all users)” and click “Next”.

img

  1. Click “Browse…” to choose an installation path of the software, and click “Install”.

img

img

  1. click “Finish”.

img

  1. Here is the main interface of Kidsblock. If there is a warningin your computer, just click “Allow access” to enter the software.

img


MacOS

  1. Download Kidsblock package: http://xiazai.keyesrobot.cn/KidsBlock.dmg

img

  1. After downloading, click KidsBlock. And then drag the KidsBlock Desktop into Applications.

img

  1. After installation, you can see the icon of KidsBlock.

    img

  2. Open KidsBlock, but it cannot be opened, because Mac devices is set that they only allow to open apps from its App store by default. Thus, we need to modify some settings.

    img

  3. Open settings and enter Privacy&Security, tick App Store and identified developers in Security. And then click Open Anyway.

    img

  4. Click Open and the software can be opened.

    img

  5. Now re-open the Kidsblock.

    img

  6. Now enjoy your programming!

    img


2.2 Using Tutorial

We demonstrate on Windows, and MacOS users may take as a referance.

Kidsblock Toolbar

img


Language

Click img to shift languages: img


Device Driver

If the driver is already installed on the computer, you do not need to install another one. If not, you need to do the following.

  • click img to choose “Install driver”.

img

  • Enter Device Driver Installation Wizard and click “Next”.

img

  • Finish”.

img

  • Next”.

img

  • Finish”.

img

  • If a warning appears, just click “Allow” and “Install”.

img

  • Finish”.

img

  • Extract”.

img

  • Next”.

img

  • Tick “I accept this agreement” and click “Next”.

img

  • Finish”.

img

  • Click “INSTALL”.

img

  • After the driver is installed, click “OK”.

img


Board

Connect a board and a port:
  • Click img to choose a device.

  • Click Kit and find ESP32 Easy Coding Board to load it. Required sensors and modules are included in it so you do not need to load them one by one.

    img

  • The following interface will appear, and we need to choose the correct port and click Connect.

    img

  • Go to Editor

    img

  • The main interface:

    img


Disconnect:
  • Click img and Disconnect.

    img


Kidsblock Main Interface Functions

img


Extensions

This kit has been integrated required sensors and modules so does not need to be additionally loaded. If you want to add them that are not available in the kit, please refer to these steps.

  • Click img to choose an extension:

    img

  • For instance, if you want to load a passive buzzer, click it:

    img

  • When “Not loaded” becomes “Loaded”, the buzzer module is successfully imported.

    img

  • Click img and you can see a passive buzzer in the blocks:

    img

  • For how to remove the mosule, click img first.

  • Click the passive buzzer.

    img

  • When you see “Loaded” changes into “Not loaded”, the module is removed from blocks.

    img


Open Code

  1. Method One:

    • Click SB3 file to open it. If you want to open img, just double click to directly open it. After that, please connect to board and port.

      img

  2. Method Two:

    • Open Kidsblock and click “file” to choose “Load from your computer

      img

    • Find and open the SB3 file, like img

      img

      img


Upload Code

  • Load code img to Kidsblock.

  • Connect the board to your computer. If there is no port, please install driver first. Choose the correct board and port and click img

    img

  • Wait for uploading.

    img


Set Baud Rate

  • Click one of img to set the size of print box.

    • Small: img

    • Large: img

    • None: img

  • After opening print box, click img to set baud rate:

img


After setting the baud rate and uploading the code, “Hello KidsBlock” will be printed on the box.

img


3. ESP32 Easy Coding Board Basic Projects

Project 1: Heartbeat

img

1. Introduction

This project is easy to conduct with an ESP32 Easy Coding Board, a USB type-C cable and a computer. The ESP32 Easy Coding Board RGB dot matrix will display a beating heart. It serves as a start for your entry to the programming world!

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Please check code in Project 1 file.

img ==> img

Find RGB blocks to change its brightness and colors.

img

Build blocks:

Initialize the RGB dot matrix.

img

Set color, brightness and display icons.

img

img

Complete code:

img

5. Test Result

After uploading test code to ESP32 Easy Coding Board and powering via USB cable, the RGB dot matrix alternately shows patterns of a small and a large heart.

img

img


Project 2: Single RGB Blinking

img

1. Introduction

In this project, we intend to control a certain RGB of the ESP32 Easy Coding Board to be on and off.

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. 5*5 RGB Dot Matrix

The RGB dot matrix has a total of 25 beads, and we mark them as number 0 to 24 from left to right and from top to bottom.

The serial number is as follows:

img

5. Test Code

Find code blocks:

img

Initialize RGB: img

Set one RGB to light up in a certain color: img

Clear RGB display: img

Refresh all RGB: img

Build blocks:

img

6. Test Result

The set RGB will light up once per second.

img


Project 3: LED Dot Matrix

img

1. Introduction

Dot matrices are very commonplace in daily life. They have found wide applications in RGB advertisement screens, elevator floor display, bus stop announcement and so on.

The dot matrix of ESP32 Easy Coding Board contains 25 RGB in a grid. Previously, we have succeeded in controlling a certain RGB to light by integrating its position value into the test code. Theoretically, we can turn on many LEDs at the same time to show patterns, digits and characters.

What’s more, we can also click ”show icon“ to choose the pattern we like to display. Last but not the least, we can design patterns by ourselves as well.

2. Components

ESP32 Easy Coding Board *1

img

USB type C Cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Find code blocks:

img

Build blocks:

We set the icon to an arrow and set its brightness and color.

img

Set the full color brightness and delay time

img

Complete code:

img

5. Test Result

After uploading test code, the dot matrix start to show arrows in may directions, and then it exhibits two light shows in full color with each for 5 seconds.

img


Project 4: Programmable Buttons & Touch

img

1. Introduction

Buttons can be used to control circuits. In an integrated circuit with a button, the circuit is connected when the button is pressed and if you release the button, the circuit is open.

Capacitive touch detects the user’s operation by measuring changes in capacitance. When you touchg the capacitive sensing area, the charge of the human body affects the value of the capacitor, which can be sensed by the module due to this change.

ESP32 Easy Coding Board boasts three buttons: two programmable buttons (marked with A and B), and a reset button at back. By pressing the two programmable buttons, three different signals can be input. We can press button A or B or both so that the LED dot matrix shows A, B and AB respectively.

Let’s get started!

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code 1

Find code blocks:

Find “if…then…” block to determine whether the buttons are pressed.

img

Add buttons and touch:

img

Choose button A or B in the condition.

img

Build blocks:

img

5. Test Result 1

After uploading test code and powering on, the 5x5 dot matrix shows A if button A is pressed, and shows B if button B pressed, and shows AB if button A and B pressed together. When the touching area is touched, it shows T.

img

img

img

6. Test Code 2

Read the touching area analog values.

Find code blocks:

img

img

Build blocks:

img

7. Test Result 2

After uploading test code and setting baud rate to 115200, when you touch this area, the value will reduce to lower than 10.

img


Project 5: Passive Buzzer

img

1. Introduction

The board boasts an built-in passive buzzer, which is a device without an oscillating circuit so need an external driving signal to produce sound.

  • Passive: Unlike active buzzers, passive buzzers do not include a built-in oscillator circuit, so an external driving signal with a certain frequency is required. This is usually done by a microcontroller or other signal source.

  • Frequency control: The frequency of the driving signal determines the frequency at which the buzzer produces sound. By changing the frequency of the input signals, different tones of sound can be played.

  • Applications: Passive buzzers are widely used in various electronic devices to provide audio prompts or alerts, such as embedded systems, electronic products, alarm systems, etc.

  • Driving: Due to its passiveness, they have relatively low requirements for external drive signals, so they usually only need to provide enough current and the appropriate frequency.

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Find code blocks:

img

Build blocks:

Play do, re, mi, fa, sol, la, si, or you may compose them by yourself.

img

Integrated musics and songs:

img

Complete code:

img

5. Test Result

Play do, re, mi, fa, sol, la, si, and a song.


Project 6: Microphone

img

1. Introduction

Microphone is a device that converts sound into electrical signals, which is an important part of the audio field. It is widely used in voice recording, communication and audio playback.

Microphones can be divided into many types, including Dynamic Microphone, Condenser Microphone, Wireless Microphone, USB Microphone and Laser Microphone.

In this project, we use a minimal capacitive microphone.

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code 1

Find code blocks:

img

Build blocks:

img

5. Test Result 1

After uploading test code and setting baud rate to 115200, speak to the ESP32 Easy Coding Board or clap your hands or desks, and the analog value of sound will increase. The louder the sound is, the greater the value will be.

img

6. Test Code 2

We represent the sound on RGB dot matrix, and as the sound gets louder, the lighting RGB will be more.

Initialize RGB.

img

Determine the sound level and rate it.

img

RGB display:

img

Complete code:

img

7. Test Result 2

Upload test code and power on, and the louder the sound is, the more the RGB will light up.

img

img


Project 7: Temperature and Humidity Detection

img

1. Introduction

AHT11 temperature and humidity sensor is equipped on the board, which outputs digital signals. It uses special analog signal acquisition&conversion technology and temperature and humidity sensing technology to ensure that the sensor features good long-term stability and high reliability. The MCU on the ESP32 Easy Coding Board communicates with it via I2C.

2. Components

ESP32 Easy Coding Board*1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Find code blocks:

img

img

img

Build blocks:

img

5. Test Result

After uploading test code, open the serial monitor and set baud rate, and the temperature, humidity and Dewpoint value will be printed.

img


Project 8: MPU6050 Accelerometer and Gyroscope

img

1. Introduction

The MPU6050 is a six-axis motion processor that includes a 3-axis gyroscope and a 3-axis accelerometer. Two sensors integrated on a single chip that can detect static and dynamic object motion states, including angular speed, Angle and acceleration.

The MPU6050 is integrated with a 16-bit ADC that can simultaneously read data from six axes to measure diagonal speed and Angle, and can also infer acceleration information from the object. The MPU6050 also boasts a built-in temperature sensor used to measure the temperature of the chip, helping to monitor the temperature of the sensor during operation.

In addition, the MPU6050 is equipped with a fast Digital Motion Processor (DMP), which helps process raw data from the gyroscope and accelerometer to obtain the motion state of the object.


Typical circuit diagram:

img

#

NAME

DESCRIPTION

1

GND

Negative interface (0V).

2

VCC

Positive interface (3.3V or 5V).

3

SDA

I2C data line, connected to MCU, used to transmit data.

4

SCL

I2C clock line, connected to MCU, used to synchronize data transmission.

5

XDA

I2C data line, connected to external extension sensors, used to transmit data.

6

XCL

I2C clock line, connected to external extension sensors, used to synchronize data transmission.

7

AD0

I2C Slave address. The sensor address is 0x69 at high and 0x68 at low.

8

INT

External interrupt pin, detects the internal interrupt time of the MPU6050.

  • Operating voltage: 3.3V, 5V

  • Static current: 5μA

  • Rotating current: 3mA

  • Maximum rotation speed: 2000°/s

  • Acceleration range: ±2g, ±4g, ±8g, ±16g

  • Temperature range: –10 ~ +65°C


MPU6050 can be used to measure the attitude of an object. Measurements of three angles can be provided: roll, pitch and yaw. It can also provide the acceleration of the object, and obtain the speed and position information of the object through calculation.

Its three axises:

img

img

The corresponding Euler Angle indicates the Angle of rotation of the object in three-dimensional space, and its coordinate axis can be adjusted arbitrarily.

Euler Angle consists of three angles, namely Roll, Pitch and Yaw.

Roll

Rotation Angle with x-axis as rotation axis

Pitch

Rotation Angle with y-axis as rotation axis

Yaw

Rotation Angle with z-axis as rotation axis

img

When acquiring Yaw, the gyroscope inside the MPU6050 is automatically calibrated to zero, which causes Yaw to drift to zero.

Zero drift means that the detected data will have an accidental small fluctuation, for example, the sensor value will automatically have an accidental small change. Even after a good algorithm, zero drift still exists, as it is limited by hardware.

Solution: add a magnetometer to calibrate the MPU6050.


For more details, please refer to the MPU6050 data sheet:

https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf

https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf


2. Components

ESP32 Easy Coding Board*1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Find code blocks:

img

img

Build blocks:

Initilize serial monitor and MPU6050

img

This block is used to update the data each time it is fetched

img

img

Complete code:

img

5. Test Result

After uploading code and powering on, Put ESP32 Easy Coding Board flatwise on the desk, press the reset button to initialize MPU6050, and wait 2 or 3 seconds.

When the serial monitor shows values, the initialization is completed; and if values on each axis is not greater than 10, the initialization is correct; otherwise you need to re-initialize.

img

img


Project 9: Light Brightness

img

1. Introduction

Photoresistors measure light intensity and are commonly used to detect brightness in the surrounding environment.

Working principle: This module is designed by the light-sensitive materials. There are two main types: photoresistor and photodiode.

  • Photoresistor: The resistance of a photoresistor varies with the intensity of ambient light. For one photoresistor, the stronger the ambient light is, the lower the resistance will be.

  • Photodiode: The current output of a photodiode is proportional to the intensity of the incident light. The electrical signals they produce can be used to measure light brightness.

Applications: Photoresistors are widely applied to various fields, including light control systems, lighting systems, camera exposure control, light monitoring, automatic adjustment of screen brightness, etc.

Unit of brightness: They usually measure light intensity in illuminance units (such as Lux). Illuminance represents the luminous flux per unit area.

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable *1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code

Find code blocks:

img

img

Build blocks:

img

5. Test Result

Upload the test code and open the serial monitor. When the light intensity detected by the sensor changes, the sensor values will also change.

img

img


Project 10: Read SD Card

img

1. Introduction

The SD card module is used in conjunction with the MCU on the ESP32 Easy Coding Board for reading and writing data on the SD (Secure Digital) card. This module makes it easier to use SD cards to store and access data in projects.

  • Function: SD card module allows the ESP32 Easy Coding Board to communicate with the SD card to achieve data reading and writing. This is very useful for data logging, file storage, logging, etc.

  • Interface: The SD card module usually connects to the ESP32 Easy Coding Board using the Serial Peripheral Interface (SPI) interface. It needs to be connected to the corresponding pin of the ESP32 Easy Coding Board, For example, MOSI (Master Out Slave In), MISO (Master In Slave Out), SCK (Serial Clock), and CS (Chip Select).

  • SD card type: SD card modules are generally compatible with various types, including standard SD cards, SDHC cards (High Capacity), and SDXC cards (eXtended Capacity).

2. Components

ESP32 Easy Coding Board*1

img

USB type C cable *1

img

SD card *1 (not included in the kit)

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

Insert the SD card into the slot.

img

img

4. Test Code

Find code blocks:

img

Initialize the serial monitor and SD card.

img

Refresh the SD data before using.

img

Read SD card type

img

Serial monitor outputs type:

img

Read SD card message

img

img

Serial monitor outputs messages:

img

File:

Determine whether there is a ‘’file.txt‘’ file in SD card.

img

If there is no ‘’file.txt‘’, it create a file and input “hello,world” in a new line.

img

After that, read the content in ‘’file.txt‘’.

img

Read all list files in SD card, including hidden files.

img

Delet this ‘’file.txt‘’.

img

Complete code:

img

Serial monitor output:

img


Project 11: Read ESP32 Easy Coding Board Current

img

1. Introduction

ESP32 Easy Coding Board boasts a built-in current measurement module (only measure USB power supply and PH2.0 interface power supply) to measure current by a resistive current sensor.

Resistive current sensor is commonly used to monitor the current value by measuring the voltage drop generated by the current through the resistance. The working principle of such sensors is based on Ohm’s law, which states that when a current passes through a resistor, the voltage generated at both ends of the resistor is proportional to the current.

img

  • Current sensing: Resistive current sensor contains a current sensing element, usually, a resistor. When current passes through this resistor, a voltage drop will be generated at both ends of the resistor, the magnitude of which is proportional to the strength of the current.

  • Volateg output: By measuring the voltage drop at both ends of the resistor, the sensor can provide a voltage signal that is related to current. This voltage signal can be digitally processed by devices like an analog-to-digital converters (ADC).

Resistive current sensors are widely applied to power system monitoring, power consumption measurement of electronic devices, electric vehicle current monitoring and so on.

2. Components

ESP32 Easy Coding Board *1

img

USB type C cable*1

img

3. Connection

Connect the ESP32 Easy Coding Board to your computer via USB cable.

img

4. Test Code 1

Read current value:

img

Complete code:

img

5. Test Result 1

After uploading test code, open the serial monitor and you will see the current value is 0. Because many modules are not working on the board, so the current is close to 0.

img

6. Test Code 2

Enable RGB dot matrix and then measure the current value.

Initialize the seial monitor and RGB dot matrix.

img

First measure 10 RGB beads.

img

Then measure 18 RGB beads.

img

Last measure 25 RGB beads.

img

Complete code:

img

7. Test Result 2

Upload test code and you will find that the more the beads are, the larger the current will be.

img

8. Test Code 3

The conversion of current to power: power (P) equals current (I) times voltage (V).

P = IV

  • P is power, unit: Watt(W)

  • I is current, unit: ampere(A)

  • V is voltage, unit: volt(V)

This formula is suitable for DC circuits.

For AC circuits, power calculation may require more complex formulas due to power factor.

In a circuit, power describes the conversion of electrical energy. Input current and voltage values into the above formula and you can get real-time power values.

This is commonly used for energy monitoring, power system management and equipment power consumption evaluation.

The power voltage of ESP32 Easy Coding Board is 3.3V, so we only need to measure the current and multiply it by 3.3 to get the power of the Board at this time.

Find code blocks:

Create valriables P and I.

img

img

img

Assign the read current value to variable I.

img

I multiplies by 3.3 is power of the ESP32 Easy Coding Board(the board voltage is 3.3V).

img

Complete code:

img

9. Test Result 3

Upload code and open serial monitor to set baud rate. The more the beads are, the greater the current value and power will be.

img


Project 12: WiFi Wireless Communication

ESP32 Easy Coding Board is built with Wi-Fi (2.4G) and Bluetooth (4.2) to easily connect to a Wi-Fi network and communicate with other devices in the network, so you can use this Board to display web pages in your browser.

img

ESP32 Easy Coding Board WiFi Function

  • Base mode (STA / Wi-Fi Client mode): ESP32 Easy Coding Board is connected to a Wi-Fi hotspot (AP).

  • AP mode (Soft-AP / Wi-Fi hotspot mode): Other Wi-Fi devices connect to ESP32 Easy Coding Board.

  • AP-STA mode: ESP32 Easy Coding Board is both a Wi-Fi hotspot and a Wi-Fi device connected to another Wi-Fi.

  • These modes support multiple security modes: WPA, WPA2, WEP, etc.

  • Wi-Fi hotspots can be searched (active and passive scanning).

  • Support hybrid mode monitoring of IEEE802.11 Wi-Fi packets.


For more wifi reference, please visit: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html

Espressif Official: https://www.espressif.com.cn/en/home

img


WiFi Web Page

Add an extension of web page editing.

img

img

Load it.

img

You will see code blocks:

img

Connect to a Wifi and input your wifi name and passwords. After connecting, the IP address will be printed on the serial monitor.

img

img

Set up a web component and name as temperature in the unit of ℃.

img

img

Add a button module and name as button.

img

img

Complete code:

img

As long as connecting to Wi-Fi, you may use the Web Server Library of ESP32 Easy Coding Board to provide web page.

In the example, we set up a simple web page to display a certain temperature value.

Open your browser to check and visit the IP address of ESP32 Easy Coding Board. Herein, you may access to “http://[IP address of ESP32 Easy Coding Board]” to visit its website.

NOTE: When PC, mobile phone and ESP32 Easy Coding Board are connected to one network, this website(your own IP address of ESP32 Easy Coding Board) can be accessed via PC and mobile at the same time.


PC:

img


Mobile:

img


4. ESP32 Easy Coding Board Button Piano Projects

4.1 Introduce to Piano

In this project, you will embark on the journey of piano exploration. With eight buttons connected on the board and each one corresponding to one tone, we will learn how to build a basic piano that may open the door to a wonderful world of tone.

img


1. Music Theory

The piano is versatile and usually consists of 88 keys, covering a wide vocal range. Tone is the basis of music, which is represented by black and white keys on the piano. In music theory, there are seven basic tones: C, D, E, F, G, A, B. They make up the scale for multiple musical compositions.

  1. C(Do)

    • On pianos, C is white key at the most left side.

    • C is the beginning note of the scale and the first note in the diatonic scale.

    • C major: C D E F G A B C

  2. D(Re)

    • D is the white key next to C.

    • D is the second note in scale.

    • D major: D E F# G A B C# D。

  3. E(Mi)

    • E is the white key next to D.

    • E is the third note in scale.

    • E major: E F# G# A B C# D# E。

  4. F(Fa)

    • F is the white key next to E.

    • F is the forth note in scale.

    • F major: F G A Bb C D E F。

  5. G(Sol)

    • G is the white key next to F.

    • G is the fifth note in scale.

    • G major: G A B C D E F# G。

  6. A(La)

    • A is the white key next to G.

    • A is the sixth note in scale.

    • A major: A B C# D E F# G# A。

  7. B(Si)

    • B is the white key next to A.

    • B is the seventh note in scale.

    • B major: B C# D# E F# G# A# B。

These seven basic tones and the interstitial relationships among them form the basis of music. With these tones, different scales, chords and melodies can be composed. Beyond that, semitone and whole tone are also included to have a better understanding of more complex aspects of music. Learning music theory can help piano players perform compositions.

img


2. Wiring

In this kit, in addition to the 7 basic syllable keys, there is also a high syllable key, totaling eight keys, enabling the playing of more intricate melodies.

Button

Pin

C

io14

D

io4

E

io15

F

io32

G

io18

A

io19

B

io23

C

io5

img

Connect ESP32 Easy Coding Board to your computer via USB cable.

img


3. Read Single Button Value

Build code:

img

img

Determine the pin state. When the pin is at high, serial monitor prints 1. Otherwise, it prints 0.

img

Complete code:

img

Test result:

Open serial monitor. When we press button C, 0 is displayed. When we release, 1 is shown.

img

img


4. Make A Sound in C Tone

After reading the value, determine the button state through the value. When the button is pressed, the C tone is emitted from the buzzer.

Build code:

img

img

Here a not block is required to invert the obtained value.

img

img

img

Complete code:

img

Test result:

When the button C is pressed, the piano plays a Middle C Tone.

img


5. A 7-key Piano

We now make all eight buttons to be able to play tones by pressing them.

Build Code

Duplicate the code block, as shown below. And then modify the tones and pins one by one.

img

img

Set pins to input.

img

Modify the button value and tone of the code blocks.

img

img

Complete code:

img

Test result:

Each button corresponds to the related Middle Tone, and when you press them, the tone will be played.

img


4.2 High, Middle, Low Tone

To enrich the music, high, middle and low tone are inevitable. Yet only eight buttons integrated in the piano. Therefore, we may program to shift tones by the two programmable buttons and the touching area, which just correspond to high, middle and low.

Build code:

We create three tone functions first.

img

img

Create “low-pitched”, “mid-pitched”, “high-pitched” functions.

img

img

img

img

img

Read the button value to determine the state of button A and B on the board as well as the touching area.

img

img

img

Make a variable pitch.

img

img

img

img

img

img

When pitch=0, piano is in low tone.

When pitch=1, piano is in middle tone.

When pitch=2, piano is in high tone.

img

Complete code:

img

Test result:

When Button A on the board is pressed, piano is in low tone.

When the touching area on the board is touched, piano is in middle tone.

When Button B on the board is pressed, piano is in high tone.

img


4.3 Music with Light

In this project, we integrate the RGB dot matrix to the piano to display different icons when pressing different buttons.

Build code:

img

Initialize RGB dot matrix.

img

Here we set to letters corresponding to buttons. You can modify to any other icons as you like.

img

img

img

img

img

img

img

Complete code:

img

Test result:

Press the piano button, and RGB dot matrix will show related tone:

img


4.4 Music Box

We will program to build a music box so that we can change songs by pressing buttons.

Build code:

Initialize RGB dot matrix and pins.

img

Define a music function

img

img

Customize the tone, or select built-in music.

img

Complete code:

img


5. FAQ

Q: Battery model?

A: 4 AAA batteries. Please mount batteries in a correct way. Do not insert the them backwards! For children, please be accompanied by parents!


Q: Errors in burning programs to ESP32 board?

A:

  • Please check whether the USB port is correct.

  • Please check whether the board model is correct.


Q: Other external modules?

A: This kit is able to connect to external modules. When connecting, please check the ESP32 pin instructions to ensure a right installation so that modules can work properly.


6. Resources