fbpx
Magicblocks Lesson 21 : Tilt Sensor
Magicblocks Project

Lesson 21: Tilt Sensor [Magicblocks]

Use the Tilt Sensor on the Magicbit using Magicblocks

Components Required

Story

 

Hello and Welcome, This tutorial will teach you to use a Tilt Sensor with a Magicbit using Magicblocks. We will be detecting the orientation of the Magicbit and displaying the output in the dashboard.

First, log into your Magicblocks account,

Magicblocks is easy visual programming software for the program of your Magicbit. Anyone can program their microcontroller by using magicblocks.io and there is no need for programming knowledge. You can sign up for free.

Start and Open the Playground.

Next, make sure your Magicbit is connected to the internet and plugged in, and also linked to your account through Device Manager.

All Done? Great! Now let’s find out the theory behind the tilt sensor.

 

Theory

 

When the device gets power and is in its upright position, then the rolling ball settles at the bottom of the sensor to form an electrical connection between the two end terminals of the sensor.

https://github.com/HarshaWeerasinghe/MagicBit_Sensors/blob/master/resources/TiltSensor/43.jpg?raw=true

 

Now let’s follow these steps to build the Tilt detector.

 

Set up the Digital In Block

 

1. Drag & Drop the Digital In block from the Magicbit nodes section to the flow.

2. Double-click on the Digital In block and select your unique Device ID from the drop-down menu.

3. Both PINs 32 & 33 can be used with the Tilt Sensor, so connect it to one of them and make sure to choose the correct PIN (which you connected the sensor) from the drop-down menu.

4. Select the Method as Interrupt from the drop-down menu.

 

 

4. In this Tutorial, PIN 33 will be used. Therefore, plug the Tilt sensor to pin 33.

Set up the Text Block

 

5. Drag and Drop a text block into the flow.

6. Configure the test block as follows to display text on the dashboard.

 

Set up the Change Block

(This Node is used to change the 1 & 0 signal input from the Digital In node to any text you want)

7. Drag & Drop the Change Block from the function nodes section on the left of the screen to the flow.

 

8. Configure the Change block as follows. You can use the add button to add the second rule.

 

Set up the Display node and the Debug node.

9. Drag and Drop a Display node and a debug node and connect to the output of the Change node as follows.

 

 

10. Double-click on the Display node to enter your Device ID.

 

[Optional] Import Already Setup Nodes

If you had trouble setting up nodes, you can use the import feature in Magicblocks to get the nodes that have already been set up.

  • First, copy this code to your clipboard;
[{"id":"47ce29b9.688f98","type":"DI","z":"ebde6e60.160c","name":"","epId":"id3359-1673348308190","pin":"33","method":"1","x":140,"y":200,"wires":[["6c6dcd69.af9044"]]},{"id":"d4dc3839.644ce8","type":"ui_text","z":"ebde6e60.160c","group":"a24f1d37.70871","order":0,"width":0,"height":0,"name":"","label":"Tilt Sensor","format":"{{msg.payload}}","layout":"row-spread","x":530,"y":200,"wires":[]},{"id":"6c6dcd69.af9044","type":"change","z":"ebde6e60.160c","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"Stable","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"Titled","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":200,"wires":[["d4dc3839.644ce8","d45952d7.a0a9e","e561853c.f445d8"]]},{"id":"d45952d7.a0a9e","type":"OLED","z":"ebde6e60.160c","name":"","epId":"id3359-1673348308190","fontSize":"1","x":520,"y":140,"wires":[]},{"id":"e561853c.f445d8","type":"debug","z":"ebde6e60.160c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":260,"wires":[]},{"id":"a24f1d37.70871","type":"ui_group","name":"Group 1","tab":"f1a4f840.46d658","order":1,"disp":true,"width":6},{"id":"f1a4f840.46d658","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1}]
  • Click on the options menu on the top right-hand corner of the screen.

 

  • Next, hover your cursor over the Import sub-menu.

 

  • Then click on Clipboard and paste the code on your clipboard to the text field.
  • Select current flow or new flow and click on Import.

IMPORTANT

Make sure you type your device ID on the Digital In node properties and choose the PIN to which your Motion Sensor is connected.

Finally, Deploying the Blocks

  • Connect all the blocks.
  • Click on the Deploy button on the top right-hand corner of the screen.
  • After deploying, go to the dashboard UI by clicking the link to the dashboard URL on the top right-hand corner of the screen.

 

  • Tilt the Magicbit off the table, and the text will be displayed on the dashboard.

Troubleshooting

  • Check whether your Magicbit is connected to the internet.
  • Check whether the Tilt Sensor is connected correctly and the correct PIN is used (e.g., PIN 33).

If you need help or couldn’t understand a step, be sure to check out our YouTube video by clicking here: Youtube Video

Related Posts
Leave a Reply