Tell your fortune with IoT

Table of Contents
Tell your fortune with IoT

Introduction

Even young programmers want to know what their future holds. The box will tell you. IoT magic will answer all the questions that come into your head. 🔮 😱

Under this project, you will learn to turn the box into an oracle or magic 8-ball. ️🎱 Set it to randomly choose one of a number of options when it is shaken.

You will need the box with button and a USB Dongle. The basic HARDWARIO Starter Kit is sufficient for this.

Make it happen in Node-RED

  1. Put the Starter Kit together and pair it. You need the radio-8-ball firmware for the Core Module. If you don't know how to download the firmware or what it is,you can find out here.

After downloading the firmware, you will see that the Alias of your device under the Devices tab has changed to Future teller.

Node-RED

  1. In Playground, click on the Functions tab - this is where you will find the programming desktop.

  2. Place an MQTT node from the Input section onto the desktop. MQTT

  3. Double-click on the node and set the key function to fortune-telling. 🔮 Copy this line to the Topic field:

node/future-teller:0/future/trigger

Topic

Confirm with the Done button.

Leave it to chance

  1. The box works by providing one of the preset answers. It works on the basis of random selection. Now let's set it up. You can program the random selection process according to a simple javascript. How? Behind the MQTT node, place a Function node, which you will find under the section of the same name.

Function node

  1. Double-click on the node to open it. Name the node in the Name line (for example 8-ball). Copy the following code into the Function line, as you can see in the screenshot.
var answers = ["Nejspíš ano", "S tím nepočítej", "Možná", "Určitě ano"] var num = Math.floor(Math.random() * Math.floor(answers.length)); msg.payload = answers[num]; return msg;

Name node

This code selects one of four options: - Probably yes, - Don't count on it, - Maybe, - Definitely yes. Confirm with the Done button.

  1. Next to the Random node, add a Text node, which can be found under the Dashboard section. Text

  2. In the node, set Label to Answer.

Label

Confirm with the Done button.

  1. Add a robot to your desktop to read the result out loud. This will make the experience just that little bit creepier. 🤖 You do this by using the Audio Out node, which can also be found under the Dashboard section.

Dashboard Set the voice in the node to read the message.

Voice setting Confirm with the Done button.

  1. Connect the nodes as shown in the screenshot. Deploy

Start the flow with the Deploy button in the top right.

Let the Great One tell you what your future holds.

  1. Lift the box and ask it the question that is burning inside you. For example:
  • Will David from the higher class return my love?
  • Will there be blueberry dumplings for lunch tomorrow at school?
  • Will I become a successful circus artist?
  • Will the sun rise in the morning?
  • Will I finally learn to eat with chopsticks?
  • Will I work at Google someday?
  • Should I dye my hair green?
  1. Shake the box and find out the answer in Playground under the Dashboard tab.🎱 Be sure to turn on the speakers so that you hear it too. Hallelujah!

Dashboard

P.S. The box does not guarantee that the answer it gives is right. 🤡