Skip to main content

Highest centrifugal force

Introduction​

Do you remember spinning tops? You might have had a wooden or plastic one, but we bet it wasn't a smart one. Now you can finally make one that records your centrifugal force. Then compete with your friends and find out which of you is the centrifugal champion! πŸ’ͺ

In this project, you will learn to measure how fast the box spins. πŸ‘ˆ

All you need is the box with a button and the USB dongle, so the basic HARDWARIO Start Set will do.

Download new firmware​

  1. If you haven't done it yet, assemble the Start Set.

  2. Upload the new bcf radio spinning game firmware to the Core Module (you'll find it in Playground among the other firmware). It makes the box react to spinning. πŸ‘Œ

  3. Pair the Core Module with the USB dongle. Right after pairing, you'll see that its Alias has changed to rotation-g-meter.

Playground Devices tab: the paired device row with alias rotation-g-meter:0 highlighted

Build it in Node-RED​

  1. In Playground, click the Functions tab, where you'll find the Node-RED programming workspace. πŸ€–
  2. Start as always: first place an mqtt in node from the network section on the workspace.

Double-click it and copy this line into the Topic field. It lets the box measure the centrifugal force:

node/rotation-g-meter:0/rotation-g
Edit mqtt in node dialog with the rotation-g topic in the highlighted Topic field

Confirm with Done.

  1. Surprise! 😲 Below the first MQTT node, place a second mqtt in node from the network section. This time, enter a different Topic in its settings, so the box measures how long it spins:
node/rotation-g-meter:0/rotation-time
Second MQTT node: Edit dialog with the rotation-time topic in the highlighted Topic field
  1. Next to each of them, add one node for JavaScript. You'll find it in the function section under the name function (original, right? 🀑).
Node-RED workspace with a Function node highlighted next to each of the two MQTT nodes
  1. Double-click the upper function node and paste this code into the large field on the On Message tab. It records the highest centrifugal force. πŸ’ͺ
var record = flow.get("record") || flow.set("record", 0.0);
var lastSpin = parseFloat(msg.payload);

if(lastSpin > flow.get("record"))
{
flow.set("record", lastSpin);
return msg;
}

In the Name field, name the node Save the record.

Edit function node dialog with the record-saving code and the Name field highlighted

Confirm with Done.

  1. In the lower function node (again on the On Message tab), paste the code that records the longest spin time. ⏰
var record = flow.get("timeRecord") || flow.set("timeRecord", 0.0);
var lastSpinTime = parseFloat(msg.payload);

if(lastSpinTime > flow.get("timeRecord"))
{
flow.set("timeRecord", lastSpinTime);
return msg;
}

In the Name field, name the node Save the record.

Edit function node dialog for the bottom node with the spin-time record code and the Name field highlighted

Confirm with Done.

  1. Below the upper function node, place a text node from the dashboard section. You can put it somewhere else, but it's clearer when the nodes sit one under another.
Node-RED workspace with a Text node from the Dashboard section highlighted under the upper Function node

In its settings, name it Last spin. It will show the value the box has just measured.

Edit text node dialog with the Label field for the last spin value highlighted
  1. Below this node, place one more, which plots the values in a chart. πŸ“ˆ You'll find it as the chart node in the dashboard section. In the Label field, name it History. In the X-axis Label field, choose automatic, so the unit is added automatically.
Edit chart node dialog with the Label field and the automatic X-axis Label setting highlighted
  1. Below the second JavaScript node, place a text node from the dashboard section. In it, set the label for the time of the last spin: Time of last spin.
Edit text node dialog with the Label field for the time of the last spin highlighted
  1. After each branch, place one text node from the dashboard section. They decide how you'll see the records. Set their Labels to Record and Record time.
Node-RED workspace with the record and record-time Text nodes highlighted next to each flow level
  1. Then connect everything as shown in the picture. You'll end up with two separate flows on the workspace. Finally, don't forget to press the Deploy button to start it all up. 🚨
Two finished flows connected in Node-RED with the Deploy button highlighted

Give it a spin!​

  1. Invite all your friends and get them fired up. Maybe have a cola. πŸ˜„
  2. Measure your centrifugal force! Take turns spinning the box. Our tip: The box spins best when you stand it on its button.
  3. Follow the results on the Dashboard tab. Good luck and… spin it for all you're worth!
Dashboard with last spin value, history chart, last spin time, record, and record time