Catch the greedy snack thief in the act

Table of Contents

Introduction

You know this for sure. In the fridge, you keep the last piece of cake from your birthday party, but when you finally get to it… it's gone. And your greedy sibling has chocolate all over her chin. Stop her with the smart box! 🎂

In this project, you will learn to make a fridge opening detector. 👈

All you need is the box with button and the USB dongle in the basic BigClown Starter Kit.

Download new firmware

  1. If you haven't done it yet, put togetherthe Starter Kit.
  2. Upload a special firmware to Core Module - bcf-radio-x-axis-detector (you will find it among other firmware in the Playground). Thanks to this firmware, the box will become sensitive to movement.👌 Our tip: You don't know how to download firmware or what it even is? You can find out here.
  3. Pair the Core Module with the USB Dongle. Right after pairing it, you will notice that your Core Module has changed Alias to x-axis-detector.
BigClown Playground - devices

Get it started in the Node-RED

  1. In the Playground, click on the Functions tab, where is the programming desktop Node-RED.
  2. Start as always: first place the MQTT node from the Input section on the desktop.
node/x-axis-detector:0/accelerometer/-/event-count
MQTT topic

Confirm it with the Done button.

  1. Now, upload there a small javascript. 🙌 First, place the Function node from the section of the same name on the desktop...
Node-RED function
  1. ...and then double-click on this node. Copy the following code to the Function field. This code will count how many times the fridge opened:
var count = flow.get("count") || 0;
count++;
flow.set("count", count);
msg.payload = count;
return msg;

Name the node in the Label field, e.g. Counter.

Node-RED counter

Confirm it the the Done button.

  1. Next to this node, place the last one - the Text node from the Dashboard section.
Node-RED dashboard text input
  1. Inside the node, change its Label to a text you want to see while it’s counting. It could be, for example, Open fridge.
Node-RED dashboard text input label

Confirm it with the Done button.

  1. Connect all three nodes, just as you can see in the picture. In the top-right corner, remember to click on the good old Deploy button which will start up the entire flow.
Connect and deploy flow in Node-RED

And… action!

  1. Let’s make the little trap work. Put a cake or any other lure in the fridge. 🍰
  2. Place the box horizontally into the door of the fridge.
  3. When someone opens the door, the box will send you a notification to the Dashboard tab.
Node-RED dashboard results
  1. Run to subdue the wicked villain! 👮
  2. And now enjoy your sweet victory. 💘