fbpx
Magicblocks Lesson 05: Control light over the internet
Magicblocks Project

Turn on an LED through the Internet [Magicblocks]

Control an LED on your Magicbit using Magicblocks

Components Required

Story

 

Hello and Welcome, This short tutorial will teach you how to make a light controller over the internet using Magicblocks and magicbit.

There are 2 main methods of achieving this goal;

  • By using Inject Block.
  • By using Dashboard Switch.

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? Then scroll down to Method 1

 

[Method 1]

 

Step 1: Setting Up the Inject Block

 

1. Drag & drop the Inject block from the input nodes section on the left of the screen to the Flow.

2. Double-click on the block and select the type of payload from the drop-down menu to a numerical input (number).

3. Set up the node name and number to inject -> 1

 

4. Set up another inject node and set the node name and number to inject -> 0

Step 2: Setting Up the Digital Out Block

 

1. Drag & drop the Digital out a block from the Magicbit nodes section on the left of the screen to the flow.

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

3. Set the PIN to one of the LED Pins.

 

[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 been already set up.

  • First copy this code to your clipboard;
[{"id":"b08b873f.cdf938","type":"inject","z":"d2db2033.c2624","name":"","topic":"Off","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":300,"wires":[["7c612530.efad4c"]]},{"id":"7c612530.efad4c","type":"DO","z":"d2db2033.c2624","name":"","epId":"","pin":"16","x":550,"y":240,"wires":[]},{"id":"3191bf6d.8716a","type":"inject","z":"d2db2033.c2624","name":"","topic":"On","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":180,"wires":[["7c612530.efad4c"]]}]
  • 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 display node properties and type the text you need inside the inject node.

Step 3: Finally, Deploying the Blocks 

 

1. Connect the inject block with the Digital Out node.

2. Click on the Deploy button on the top right-hand corner of the screen.

3. After deploying click on the box located to the left side of the inject block to activate it. If you click the ‘On’ inject block, the LED you chose will turn on, If you click on the ‘Off’ inject block the LED will turn off.

To Control All Four LEDs at Once

 

1. Duplicate the Digital Out block 3 times and assign each block to the four LED Pins.

2. Next connect the ‘On’ and ‘Off’ inject blocks with the new Digital Out block.

 

3. Click on the Deploy button on the top right-hand corner of the screen.

4. After deploying click on the box left-side of the inject block to activate it and if you click the ‘On’ inject block the LEDs you chose will turn on, next click on the ‘Off’ inject block to turn it off.

Troubleshooting

  • Check whether it shows as “connected” (or 1/0) below the display block, if not, recheck the Device ID which you typed into the display block.
  • Check whether your Magicbit is connected to the internet (Check whether the wifi icon is visible on the Magicbit’s display).
[Method 2]

 

Step 1: Setting Up the Switch Block

 

1. Drag & drop the Switch block from the dashboard nodes section to the Flow.

2. Double-click on the Switch node and set up a basic dashboard UI [user interface] from the drop-down menu and a name for your field.

3. Select the Mode as number input from the drop-down menu for both On and Off. Set the payload of the “on” block as 1 and that of the “off” block as 0.

Step 2: Setting Up the Digital Out Block 

 

1. Drag & drop the Digital out block from the Magicbit nodes section on the left of the screen to the flow.

2. Double-click on the digital out block and select or type your unique Device ID from the Device Manager Tab on your Magicblocks account. [This will link the digital out block with your Magicbit]

[Optional] Import Already Setup Nodes

  • First copy this code to your clipboard;
[{"id":"f5c6f3ff.5d9a","type":"ui_switch","z":"d2db2033.c2624","name":"","label":"switch","group":"b6e2a4f1.2e9cd8","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":330,"y":700,"wires":[["1bb5fdbe.71ac32"]]},{"id":"1bb5fdbe.71ac32","type":"DO","z":"d2db2033.c2624","name":"","epId":"","pin":"16","x":570,"y":700,"wires":[]},{"id":"b6e2a4f1.2e9cd8","type":"ui_group","z":"","name":"LED","tab":"1e4dddd7.63fc02","disp":true,"width":"10","collapse":false},{"id":"1e4dddd7.63fc02","type":"ui_tab","z":"","name":"Magicbit Tutorial","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 display node properties and type the text you need inside the inject node.

Step 3: Finally, Deploying the Blocks & Using the Dashboard UI to Access It 

  • Connect the Switch block with the Digital Out node.
  • 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.

  • Once in the dashboard, you can toggle the switch you just set up on and off to control the LED you assigned to the digital out block.

  • Copy your Dashboard URL. This can be accessed via the internet to control the LEDs on your Magicbit from anywhere in the world.

Troubleshooting

  • Check whether it shows as “connected” (or 1/0) below the display block, if not, recheck the Device ID which you typed into the display block.
  • Check whether your Magicbit is connected to the internet (Check whether the wifi icon is visible on the Magicbit’s display).

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

Related Posts
Leave a Reply