element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Build a Present
  • Challenges & Projects
  • Project14
  • Build a Present
  • More
  • Cancel
Build a Present
Blog Singing Traditional Christmas star - Blog#1 using Arduino MKR ZERO
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 25 Dec 2021 4:20 PM Date Created
  • Views 44982 views
  • Likes 10 likes
  • Comments 2 comments
  • Arduino_MKR_ZERO
  • pir
  • happyholidays
  • buildapresentch
  • arduino
Related
Recommended

Singing Traditional Christmas star - Blog#1 using Arduino MKR ZERO

carmelito
carmelito
25 Dec 2021

This Holiday season, and for this years Project 14 Holiday theme , I planned to build a new traditional Christmas star at my Dad’s home with a twist. Basically the idea is - when someone visits the house OR when the children come Christmas caroling, the star which is placed in the path of the front door way will detect movement and play a small welcome message followed by a Holiday theme song/carol. To detect the movement I am using a PIR sensor connected to the Arduino MKR Zero, which in turn is connect to an I2S amplifier break out to play music downloaded to an SD card. Here is a picture of the Star from last year 2020..

Star from Last Year 2020

And before I forget,  Happy Holiday !! to you and your family .. 

Circuit

Circuit Arduino MKR Zero PIR and I2S Amp

Here are the connection details for the Adafruit I2S 3W Class D Amplifier Breakout – MAX98357A and Arduino MKR ZERO https://www.newark.com/arduino/abx00012/dev-board-music-digital-audio/dp/47AC4166

  • VIN on the I2S amplifier connected 5V of the Arduino MKR Zero
  • GND connected GND
  • LRC connected to pin 3
  • BCLK connected to pin 2
  • DIN connected to pin A6

PIR sensor is connected to pin 1 on the  Arduino MKR Zero

The Arduino sketch below only accepts wav files, which means if you have mp3 files, they will have to be converted to wav using a tool like Audacity  Once your done with the conversion process, copy the .wav file to the SD card.

Audacity Exporting to WAV format

Now, if this is the first time you are using the MKR family of Arduino boards, go to the board manager and install the latest version for the Arduino SAMD Boards

Board Manager for the Arduino MKR boards

In addition, before you upload the sketch below you will also have to install the Arduino sound library using the Library Manager.

Library Manager - ArduinoSound

Once done, upload the code below to the Arduino MKR ZERO

#include <SD.h>
#include <ArduinoSound.h>

int ledPin = LED_BUILTIN;  // using the bulit in LED as a visual indicator if motion is detected by PIR
int pirPin = 1;   //PIR signal pin 
int pirStat = 0; 
// filename of wave file to play
const char filename[] = "MUSICO.WAV"; //change this to the name you have given in the SD Card
SDWaveFile waveFile;
void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(pirPin, INPUT); 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // setup the SD card
  Serial.print("Initializing SD card...");
  if (!SD.begin()) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  // create a SDWaveFile
  waveFile = SDWaveFile(filename);
  
  // check if the WaveFile is valid
  if (!waveFile) {
    Serial.println("wave file is invalid!");
    while (1); // do nothing
  }
  // print out some info. about the wave file
  Serial.print("Bits per sample = ");
  Serial.println(waveFile.bitsPerSample());
  long channels = waveFile.channels();
  Serial.print("Channels = ");
  Serial.println(channels);
  long sampleRate = waveFile.sampleRate();
  Serial.print("Sample rate = ");
  Serial.print(sampleRate);
  Serial.println(" Hz");
  long duration = waveFile.duration();
  Serial.print("Duration = ");
  Serial.print(duration);
  Serial.println(" seconds");

  // playback volume, change this to a lower value if it is loud.
  AudioOutI2S.volume(95);
  // check if the I2S output can play the wave file
  if (!AudioOutI2S.canPlay(waveFile)) {
    Serial.println("unable to play wave file using I2S!");
    while (1); // do nothing
  }

}

void loop() {
 pirStat = digitalRead(pirPin); 
 if (pirStat == HIGH) {            // if motion detected
   digitalWrite(ledPin, HIGH);  
     //check if playback is still going on
   if (!AudioOutI2S.isPlaying()) 
   {
      // playback has stopped
      Serial.println("playback stopped");
      while (1); // do nothing
    }
   Serial.println("starting playback");
   AudioOutI2S.play(waveFile); // playing the wav file

 } 
 else {
   digitalWrite(ledPin, LOW); // turn LED OFF if we have no motion
   Serial.println("Waiting...");
 }
delay(10);
}

Here are some picture of the Traditional Star being built for Bamboo sticks.

Choping Bamboo to build the start frameStar Frame ready

Stay tuned for the next blog which will include completing the star, and applying the red and white butter paper to the frame. And,  I also plan on adding Neopixels in the center hexagon for a diffusion effect !! 

  • Sign in to reply
  • DAB
    DAB over 3 years ago

    Great build.

    Well done.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • robogary
    robogary over 3 years ago

    sweet. I didnt realize the MKR could do this topology, nice learning project for me.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube