Introduction
Do you want to make a doorbell that plays your own voice or mp3 audio? In this video, I create a simple doorbell that plays “Hello, welcome” and displays a welcome note whenever it detects a motion using M5GO IoT Starter Kit.
Video
This tutorial shows how to make an audio doorbell using the M5GO IoT Starter Kit.
Hardware Preparation
This is the list of items used in the video.
Sample Program
This is the Arduino sample code is to play an mp3 audio when the motion sensor is triggered. Please install the following library through Library Manager.
- M5Stack V0.3.0
- ESP8266 Audio
#pragma mark – Depend ESP8266Audio and ESP8266_Spiram libraries | |
#include <M5Stack.h> | |
#include <WiFi.h> | |
#include "AudioFileSourceSD.h" | |
#include "AudioFileSourceID3.h" | |
#include "AudioGeneratorMP3.h" | |
#include "AudioOutputI2S.h" | |
AudioGeneratorMP3 *mp3; | |
AudioFileSourceSD *file; | |
AudioOutputI2S *out; | |
AudioFileSourceID3 *id3; | |
bool playing = false; | |
bool curr = false; | |
bool prev = false; | |
void setup() { | |
M5.begin(); | |
M5.Power.begin(); | |
pinMode(36, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
curr = digitalRead(36); | |
if (curr != prev) { | |
if (curr == true) { | |
M5.Lcd.setTextColor(WHITE); | |
M5.Lcd.setCursor(30, 70); | |
M5.Lcd.setTextSize(10); | |
M5.Lcd.printf("Hello!Welcome"); | |
play(); | |
} | |
prev = curr; | |
} | |
if (playing) { | |
if (mp3->isRunning()) { | |
if (!mp3->loop()) { | |
mp3->stop(); | |
playing = false; | |
M5.Lcd.fillScreen(BLACK); | |
delay(500); | |
} | |
} else { | |
delay(1000); | |
} | |
} | |
M5.update(); | |
} | |
bool play() { | |
if (file) { | |
delete file; | |
file = NULL; | |
} | |
if (mp3) { | |
delete mp3; | |
mp3 = NULL; | |
} | |
if (out) { | |
delete out; | |
out = NULL; | |
} | |
file = new AudioFileSourceSD("/Hello.mp3"); | |
id3 = new AudioFileSourceID3(file); | |
out = new AudioOutputI2S(0, 1); | |
out->SetOutputModeMono(true); | |
mp3 = new AudioGeneratorMP3(); | |
mp3->begin(id3, out); | |
playing = true; | |
return true; | |
} |
Thank You
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.
“Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.“