It is possible to develop applications for physical environments with Arduino and Mblock. In this post, there will be interactive exaples which ara done with Arduino and Mblock . Based on these examples, you can develop your own original applications and share them in the comments section.

IMPORTANT: For controlling Arduino directly with Mblock, it may be necessary to first Connect -> Firmware Update. Some Arduino versions do not accept instant commands from the program without performing this update.

IMPORTANT: Some extensions will be necessary in these activities. You can download extensions for mBlock 3 from this link;

https://www.mblock.cc/extensions/

1) Opening and closing led with virtual block in mBlock

Objective: Led controlling via Ardunio with virtual button in Mblock

First of all, let's create the Mblock file which is given below screenshot and then create our circuit according to the circuit diagram given below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





In here led will be open when button pressed and closen when presses again.

Circuit Scheme





If you have created code and circuit diagram as above, once you press the virtual button you created on the Mblock screen, the LED will light up and the next time you press it, it will go off.

2) Contolling leds with character in mBlock

Objective:In Mblock, character will be controlled with arrow keys on the keyboard and if touch the yellow, blue and red buttons, related leds will be open.

First of all, let's create the Mblock file which is given below screenshot and then create our circuit according to the circuit diagram given below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





Circuit Scheme:

If you have created the code and circuit diagram as above, you can control the ghost character with arrow keys on keyboard and light up the color leds that the ghost character touches.

3) Lighting a led gradually with slider button in mBlock

Objective: Creating a slider button in Mblock and use it as a potentiometer to give LED light gradually.

First, let's create the Mblock application and the circuit diagram shown below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





In here values ​​to be given to "value" variable between 0-255. This variable will be used to determine the voltage level to be given.

Circuit Scheme







If you have created the code and circuit diagram as above, the brightness of the led will change according to the level you bring the slider button.

4) Setting RGB LED color with 3 slider buttons in Mblock

Objective: Creating 3 slider buttons in Mblock and adjust the color of RGB LED with the buttons created.

First, let's create the Mblock application and the circuit diagram shown below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





Circuit Scheme





Important:This circuit diagram is designed for common cathode (-) led. If you are using a common anode (+) rgb led, connect the longest leg of the led to the 5v output in Arduino. And make sure the leds are connected to PWM pins.

5) Servo motor rotation with buttons in Mblock

Objective: Virtual forward and backward buttons will be created in Mblock for physical servo motors rotation.

First, let's create the Mblock application and the circuit diagram shown below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





With backward and forward buttons in here, there will be created virtual valves, for increasing and decreasing the "angle" variable. As you click the forward and backward buttons, value of the angle variable will change between 0 and 180 degrees. And this angle of rotation will also be transferred to the servo motor to be connected via Arduino.

Circuit Scheme





If you have created the code and circuit diagram as above, you can rotate the servo motor with Arduino with help of virtual buttons.

6) Opening and closing the virtual gate with ultrasonic sensor in Mblock

Objective: Connecting ultrasonic distance sensor with Mblock and use the incoming distance variable to open and close the generated virtual gate.

For this activity, you must first add the extension of HC-SR04 sensor to mBlock. You can reach extension from the link below. For adding, follow the path "Extensions-> Manage Extensions -> Add extension" in Mblock.

CLICK HERE to download HC-SR04 extension.

First, create the Mblock application and the circuit diagram shown below.

Mblock Screen and Code Blocks:

CLICK to download the mBlock file of this activity.





With the code above, the door will open when "distance" variables value is less than 4 and close when more than 4. The "distance" value is determined by the following code from the ultrasonic sensor:





With this code, the circuit diagram required to obtain the distance value from the ultrasonic sensor should be as follows.

Circuit Scheme





After creating the circuit as above, you must connect Arduino to the computer and introduce it to mBlock. If you have made the connections correctly and connected the Arduio with mBlock correctly, the virtual door will open when you place an object within 4 cm of the ultrasonic sensor.





To be continued...