Example Code for MakeCode- Ambient Noise Analysis (based ThingSpeak)

This project reads the data changes of the sound sensor, uploads them to thingspeak, and generates graphs for analyzing noise situation in the current environment, and then we can find the period with the most serious noise in a day.

Hardware Preparation

  • MBT0039 micro:bit board x1
  • MBT0008 IO Extender for micro:bit x1
  • DFR0034 Gravity: Analog Sound Sensor x1
  • WiFi IoT module x1
  • Wires

Wiring Diagram

Software Preparation

I2C Library

MakeCode I2C Library: https://github.com/DFRobot/pxt-DFRobot_WiFi_IoT_I2C

How to use ThingSpeak

Open ThingSpeak website,, click the right-upper corner to enter the register and login interface.

7-1

When using for first time, register an account in the following interface. Fill in the correct email address and vertify the mail box.

7-2

7-3

The following interface will appear after finishing the registeration.

7-4

The above interface can also be found by clicking "Channels->My Channel". Now click new channel.

7-5

Enter the interface below then.

7-6

Here, we need to fill in the name, channel description, and tick the number of fields. In the makecode library, the fields are the same as the fields in the channel. In the routine, only the noise analog value is transferred to the channel. So only one is ticked here, and the field name can be customized. We modify the field name here as noise. Save the channel now. Here is the channel I created.

7-7

After saving, the channel is created. The created channel is shown in the figure below, the parameters uploaded can be seen here.

7-8

If more data needs to be uploaded, you need to click channel settings, click to enter the figure below, tick the "box" behind the field, and save it. You can also delete channel and clear channel data here.

7-9

Channel added successfully.

7-10

Click API Keys then we can see the related password of the channel. The password in the red box should be filled in the corresponding block in programming.

7-11

Sample Code

Program Link

https://makecode.microbit.org/_MA3LC6cYwRoH

Program Blocks

7-13

Result

Check the uploaded data in private view of thingSpeak platform, the sound value read by analog sound sensor will be uploaded to IoT platform in real time, and displayed in the form of line graph.

7-14

Was this article helpful?

TOP