Add Connectivity to a Doorbell


The goal of this tutorial is to enhance a non connected doorbell. We'll identify when the doorbell rings to send a message, all without disassembling anything, using only the doorbell sound. NanoEdge AI Studio will help create an AI model. No AI expertise required for this tutorial 

Here is the plan:

  1. Setup
  2. Collect microphone data
  3. Create the classification model
  4. Add the model in our Arduino code



First, we need to connect the microphone to the Arduino board.

Use jumper wires to connect:

  1. OUT (mic) to A0 (board)
  2. GND to one of the GND on the board
  3. VCC to 3.3v

Make sure that you have a USB data cable connecting the board to the pc.

Then we need to put the microphone close to the part of the doorbell that make sound!


In Arduino IDE:

Make sure you selected the right COM port: Tools > Port and select the right one.

Select the right board:

  1. Tools > Boards > Arduino Renesas UNO R4 boards > Arduino UNO R4 WIFI
  2. If you don't find it, click on Tools > Boards > Boards Manager..., look for the UNO R4 and install the package


Collect Microphone Data

We use a digital microphone that has a very high data rate.

We will collect chucks of the music by collecting buffers of values from the microphone and also reduce the data rate by keeping only 1 value every 32 collected.

We collect buffers of music and note single notes to classify them. Even for a human it is impossible to recognize a song with one random note taken from the song.


To accomplish this:

  1. Define the AMP_PIN to A0 as our microphone use the A0 pin to send data
  2. We define a buffer called neai_buffer to stock the value collected
  3. In our case, the buffer is of size 1024 (SENSOR_SAMPLE)
  4. We initialize the serial in the setup()
  5. We create a get_microphone_data() to collect buffers of data from the microphone. We get only 1/32 values
  6. We call the function only if a sound > 400 is detected, to avoid anything random noise that cannot be a doorbell sound. Depending on your equipment, you may need to lower it.
  7. We print the buffer to send it via serial.


The code:

/* Defines ----------------------------------------------------------*/

#define SENSOR_SAMPLES 1024 //buffer size

#define AXIS 1 //microphone is 1 axis

#define DOWNSAMPLE 32 //microphone as a very high data rate, we downsample it

/* Prototypes ----------------------------------------------------------*/

void get_microphone_data(); //function to collect buffer of sound

/* Global variables ----------------------------------------------------------*/

static uint16_t neai_ptr = 0; //pointers to fill for sound buffer

static float neai_buffer[SENSOR_SAMPLES * AXIS] = {0.0}; //souhnd buffer

int const AMP_PIN = A0; // Preamp output pin connected to A0

/* Setup function ----------------------------------------------------------*/

void setup() {




/* Infinite loop ----------------------------------------------------------*/

void loop() {

if (analogRead(A0)> 400){




/* Functions declaration ----------------------------------------------------------*/

void get_microphone_data()


static uint16_t temp = 0; //stock values

int sub = 0; //increment to downsample

//while the buffer is not full

while (neai_ptr < SENSOR_SAMPLES) {

//we only get a value every DOWNSAMPLE (32 in this case)

if (sub > DOWNSAMPLE) {

/* Fill neai buffer with new accel data */

neai_buffer[neai_ptr] = analogRead(AMP_PIN);

/* Increment neai pointer */


sub = 0; //reset increment


else {

//we read the sample even if we don't use it

//else it is instantaneous and we don't downsample

temp = analogRead(AMP_PIN);


sub ++;


//print the buffer values to send them via serial

for (uint16_t i = 0; i < SENSOR_SAMPLES; i++) {


Serial.print(" ");



neai_ptr = 0; //reset the beginning position