Leave a mCookie Out for Santa

Ever want to know when Santa is in the house? Why not set up a trap? You can do it with a mCookie, a stackable microcontroller. The goal behind this is when Santa climbs down the chimney or makes some noise while everyone is sleeping, it will trigger an alarm.

 

Earlier in the year there was a Kickstarter campaign by Microduino to create a stackable Arduino called mCookie. It is a great educational starter kit to get anyone into the world of Microcontrollers. It is mounted via magnets, so when magnets line up and snap together you know you have good connection between modules. Due to this there is no need to learn to solder as long as you get the right modules for what you need. If you want to build an IoT project, you can do so by using a Wi-Fi or a Bluetooth module. It is great for getting kids involved in this too, because you can connect these mCookies to Lego blocks. Here is a video of what mCookie can do.

 

mCookie uses Arduino IDE. The core of the mCookie is an Arduino Leonardo, so if you already have it installed you are good to go. If you do not, you can grab it from here.  You can find many more tutorials here.  For the demo, you will be combining “Sound Detection Sensor” tutorial and “The Use of Buzzer” tutorial.

 

We need to detect when Santa is making noise from eating cookies too loud, the buzzer tutorial is key to getting this to work. It uses analog pins. All that is required to read the analog pin is this command: analogRead(mic_pin). You will need to figure out how loud your existing environment is to set a base threshold. If the noise you make is louder than the threshold then you will execute the buzzer alarm using the code from the buzzer tutorial. Once you are done coding, all you need to do at this point is to put the Lego pieces together to hide the electronics. The end product should look like this in my video.

 

The code for this whole setup looks like this:

 

 


#define buzzer_pin 6 //Define buzzer driving pin 
#define mic_pin A0
 
int sensorValue;
int buzzerRingAmount = 1;
int buzzerCount =0;
void setup()
{
  pinMode(buzzer_pin,OUTPUT);
  Serial.begin(9600);
  pinMode(mic_pin, INPUT);
}
 
void loop()
{
   sensorValue = analogRead(mic_pin);
  // print out the value you read:
  Serial.print("Sound:");
  Serial.println(sensorValue);
  if(sensorValue>50){
    alarm();
  }
  delay(100);        // delay in between reads for stability
}
void alarm(){
  buzzerCount = 0;
  while(buzzerCount<buzzerringamount){ 200hz="" 2s.="" 5ms.="" 800hz="" a="" circular="" for="" frequency="" from="" highest="" i="200;i<=1000;i++)" in="" increase="" int="" lasts="" manner.="" n0.4="" output="" port.="" the="" to="" void="">=200;i--)
  {
    tone(buzzer_pin,i);
    delay(10); //The frequency lasts for 10ms. 
  }
}



#define buzzer_pin 6 //Define buzzer driving pin 
#define mic_pin A0
 
int sensorValue;
int buzzerRingAmount = 1;
int buzzerCount =0;
void setup()
{
  pinMode(buzzer_pin,OUTPUT);
  Serial.begin(9600);
  pinMode(mic_pin, INPUT);
}
 
void loop()
{
   sensorValue = analogRead(mic_pin);
  // print out the value you read:
  Serial.print("Sound:");
  Serial.println(sensorValue);
  if(sensorValue>50){
    alarm();
  }
  delay(100);        // delay in between reads for stability
}
void alarm(){
  buzzerCount = 0;
  while(buzzerCount<buzzerringamount){ 200hz="" 2s.="" 5ms.="" 800hz="" a="" circular="" for="" frequency="" from="" highest="" i="200;i<=1000;i++)" in="" increase="" int="" lasts="" manner.="" n0.4="" output="" port.="" the="" to="" void="">=200;i--)
  {
    tone(buzzer_pin,i);
    delay(10); //The frequency lasts for 10ms. 
  }
}