Try Scratch for Arduino by Using mBlock
Arduino is a small prototyping board that can bring amazing ideas into real life. Besides that, using it, you can create blinking lights and sense buttons, run servos, and even make a robot, an electronic gadget, and many other interesting things. However, to achieve these goals, you must instruct the Arduino [arduino download] in a programming language, giving the Arduino steps to complete the task in the form of code. Besides that, arduino is designed to program in its own language, and this language consists of functions pulled from C/C++. Nevertheless, other languages can also be used to program an Arduino with the help of a third-party programming tool. Because by using Scratch programs, you can make Arduino Flash Lights, Read Buttons, and many of the things that you can do in a regular Arduino environment.
One such program is mBlock, which lets you use the Scratch visual programming language with an Arduino. Therefore, if you like Scratch and Arduino but are not quite ready for programming in C/C++ yet, therefore, mBlock might be something to try out, and it will make the whole process easier and more interactive without Arduino download.
How do you use mBlock to achieve a programming goal with Scratch?
At first, Scratch was a programming language for children to learn coding. Schools all over the world are now starting to teach Scratch as a part of their curriculum to prepare children to learn to program. In Scratch, kids can join labeled blocks (which serve as code snippets) to write a complete program, which turns coding into a more visually interesting process. Besides that, with the help of mBlock 3, users can even see the original C++ code after programming the Arduino. It’s an interesting and helpful function for beginners.
Let’s start, for example, by making an LED blinking program with mBlock 3.
Step 1: Gather the materials you will need
- Arduino [arduino download]
- Some LEDs
- A 560 Ohm resistor for each LED (or a similar value)
- A 10k Ohm resistor
- A Pushbutton Switch
- Breadboard for wiring up
- Some wires
Step 2: Create the flashing LED experiment
To start, we need to wire an LED and switch to the Arduino (along with some resistors) as shown.
Step 3: Program the blinking LED with mBlock
In the picture below, you can see two blocks, an Arduino block and a forever block, which are required for programming an Arduino.
For more information about Arduino, please check:
A forever block
A forever block allows a program to run indefinitely in a loop. In this case, at first, we need to blink the LED continuously, so we need a forever block. Inside the forever block, set the digital pin block to be used. This block can make a pin voltage high or low. If you have an LED connected to pin number 13 of the Arduino and want to turn it on, you will use “set digital pin 13 outputs as HIGH,” and the LED will light up. This program uses delays to pause for one second between the ON and OFF status, so we can clearly see the LED flashing in this way.
Besides that, try linking the Arduino to the LED and running the code after connecting your Arduino to the computer. Run the code, and then you will be able to see the LED blink.
more blogs here