Device Description

Arduino Uno uses the ATmega328 developed by Atmel. It provides 14 digital pins (among which six are capable of PWM output), six analog input pins, and one 16MHz crystal oscillator clock, power jack, USB connector, ICSP connector, and reset button.

Arduino Uno (device) - 图1
① USB connector, used to connect Arduino Uno to a PC for power supply or programming.

② DC power jack, used to connect a power adapter for power supply.

③ RESET pin, used to reset the Arduino development board.

④ 3.3 V and 5 V pins, used to supply stabilized output voltage of 3.3 V or 5 V.

⑤ GND pin, used to ground circuits.

⑥ Vin pin, used to apply external power to Arduino Uno.

⑦ Six analog input pins, A0 to A5, used to read signals from analog sensors (such as a humidity or temperature sensor) and convert them into numeric values that can be read by the microprocessor.

⑧ ICSP pin.

⑨ Fourteen digital pins, 0 to 13, among which pin 13 is connected to the on-board LED indicator; pins 3, 5, 6, 9, 10, and 11 are capable of PWM output; pins 2 and 3 can be used for suspension; and pins 0 (RX) and 1 (TX) can be used for serial communication.

⑩ GND pin, used to ground circuits.

⑪ AREF pin.

⑫ RESET button, used to reset the Arduino development board.

Start to Program with mBlock 5

  1. Connect Arduino Uno to a PC by using a USB cable.

  2. Add Arduino Uno from the device library.
    Arduino Uno (device) - 图2

  3. Connect the device to mBlock 5.
    Arduino Uno (device) - 图3 Arduino Uno (device) - 图4

  4. Select the programming mode.
    Upload: You need to upload the program to your device for execution. You can disconnect the device from mBlock 5 after uploading the program, and the program can be executed on the device. Some blocks for Arduino Uno are available only in the Upload mode.
    Live: You can view the execution result in real time without uploading the program to your device. This mode facilitates the debugging of program fragments. In this mode, your device needs to keep connected to mBlock
    Arduino Uno (device) - 图5

  5. Start to have fun with programming.


2. [ICON] read digital pin [PORT]

Arduino Uno (device) - 图6

The report condition is met if high-level input is detected at the specified digital pin.

How to Use

This is a Boolean block that reports only “true” or “false”. It must be used in combination with another block requiring a condition. It cannot be used independently.

Digital pins of Arduino Uno:
Pins 0 to 13 of Arduino Uno can be used for digital input or output, among which pin 13 is connected to the on-board LED indicator. You can configure these pins as digital input pins to read a logical value (0 or 1) or as digital output pins to drive various modules, such as an LED indicator.
Arduino Uno (device) - 图7

Example

After you turn on Arduino Uno, if high-level input is detected at digital pin 9, the output of digital pin 13 is set to high level and the on-board LED indicator is lit up.
Arduino Uno (device) - 图8


3. [ICON] reset timer

Arduino Uno (device) - 图9

Resets the timer to zero.

Example

In the Live mode , when you press the space key, the timer is reset to zero.
Arduino Uno (device) - 图10


4. [ICON] timer

Arduino Uno (device) - 图11

Reports the count value of the timer.

Example

After you turn on Arduino Uno, the timer is reset and counts from zero. When the count value of the timer is greater than 6, the output of pin 13 is set to high level, and the on-board LED indicator is lit up.
Arduino Uno (device) - 图12


5. [ICON] read analog pin(A)[PORT]

Arduino Uno (device) - 图13

Reports the value of the specified analog pin.

How to Use

This is a reporter block that must be used in combination with another block requiring data. It cannot be used independently.

Analog pins of Arduino Uno:
Arduino Uno provides six analog input pins, A0 to A5. These pins can be used to read signals from analog sensors (such as a humidity or temperature sensor) and convert them into numeric values that can be read by the microprocessor.

Arduino Uno (device) - 图14

Example

After you turn on Arduino Uno, if an input value greater than 50 is detected at analog pin 0, the output of digital pin 13 is set to high level and the on-board LED indicator is lit up.

Arduino Uno (device) - 图15


6. [ICON]read pulse pin[PORT] timeout[TIME]

Arduino Uno (device) - 图16

Reports the pulse width (in μs) of the specified pin within the specified time.

How to Use

This block reads the pulse width (in μs) of the specified pin. The timing starts if the pin is detected as high level and stops when the pin changes to low level.

This block returns a pulse width in μs, and returns the value 0 if no pulse is generated within the specified time.

Example

After you turn on Arduino Uno, the pulse width of pin 13 within 20 seconds is read and written to the serial port.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.

Arduino Uno (device) - 图17


7. [ICON] set digital pin [PORT] output as [LEVEL]

Arduino Uno (device) - 图18

Sets the output of the specified digital pin to high or low level.

How to Use

Pins 0 to 13 of Arduino Uno are digital input/output pins. You can click the pin number in the block to set the target pin number.

Arduino Uno (device) - 图19

Example

In the Live mode, when you click the green flag, the output of digital pin 13 is set to high level and the on-board LED indicator is lit up.
Arduino Uno (device) - 图20


8. [ICON] set PWM [PORT] output as [POWER]

Arduino Uno (device) - 图21

Sets the output of the specified PWM pin to the specified value.

How to Use

What is PWM?
Pulse width modulation (PWM) is technology for performing digital encoding on analog signals. It involves two key parameters, namely frequency and duty cycle. The frequency determines the time required for completing a single cycle and the rate of signals changing from high to low level. The duty cycle determines the time the signals stay in high level within the total period of time. By changing the duty cycle of PWM, you can change the average voltage of the output signals, and thus provide analog voltage output.

PWM signals can be used to control the speed of DC motors and the brightness of LED indicators.

Pins 3, 5, 6, 9, 10, and 11 of Arduino Uno can be used for PWM output. You can click the pin number in the block to set the target pin number.

Value range: 0–255, where 0 indicates the duty cycle of 0%, and 255 indicates that of 100%

Example

Connect an LED indicator to pin 5 of Arduino Uno. In the Live mode, when you click the green flag, the LED indicator changes gradually from dark to bright.
Arduino Uno (device) - 图22


9. [ICON] play pin[PORT] with note [NOTE] for [BEAT] beats

Arduino Uno (device) - 图23

Makes the buzzer connected to the specified pin play the specified note for the specified number of beats.

How to Use

After connecting a buzzer to the specified pin of Arduino Uno, you can use this block to control the buzzer to play music. This block can be used only in the Live mode.

Note description
Determined by frequency, notes can represent the pitch and duration of a sound in musical notation. The character in a note name is called letter name, and the number on the right indicates an octave.

Mapping between letter names and solfeges:
Arduino Uno (device) - 图24

Beat description
A beat refers to the total length of a note in each measure in a musical notation. Common beats include 1/4, 2/4, 3/4, 4/4, 3/8, 6/8, 7/8, 9/8, 12/8. The length of each measure is fixed.

Example

Connect a buzzer to pin 9 of Arduino Uno. After you turn on Arduino Uno, the music “Twinkle Twinkle Little Star” is played.
Arduino Uno (device) - 图25


10. [ICON] set servo pin [PORT] angle as[ANGLE]

Arduino Uno (device) - 图26

Sets the output angle of a servo connected to the specified pin to the specified value.

How to Use

After connecting a servo to the specified pin of Arduino Uno, you can use this block to set the output angle of the servo.

Servo description
A servo is an automatic control system consisting of a DC motor, underdrive gear set, sensor, and control circuit. It can rotate precisely the specified angle based on simple input signals.

Example

Connect a servo to pin 9 of Arduino Uno. When you click the green flag, the output angle of the servo is set to 90 degrees.
Arduino Uno (device) - 图27


11. [ICON] suspend pin[PORT] mode [MODE] executes

Arduino Uno (device) - 图28

Executes the suspension program when the suspension condition of the specified suspension pin is met.

How to Use

What is suspension?
During the sequential execution of programs, the main control board stops immediately the execution of the current program when receiving some predefined digital input signals, and executes the program in the suspension part. After executing the program in the suspension part, the main control board continues to execute the previous program it paused before.

Diagram of the suspension process
Arduino Uno (device) - 图29

Digital pins 2 and 3 of Arduino Uno can be used for suspension. This block is available only in the Upload mode.

The mode in this block refers to the way suspension is triggered. Arduino Uno provides four ways of triggering suspension, namely rising edge, falling edge, change, and low. The way change refers to level change, for example, high level changes to low level, and low level changes to high level.
Arduino Uno (device) - 图30

Example

After you turn on Arduino Uno, the value of number increases by 1 each time suspension is triggered and is written to the serial port. You can view the value of number in real time by using the serial port monitor provided by the Arduino software.
Arduino Uno (device) - 图31


12. [ICON] do not suspend pin [PORT]

Arduino Uno (device) - 图32

Cancels the suspension function of the specified pin.

Example

After you turn on Arduino Uno, pin 13 does not provide high-level output and the on-board LED indicator is not lit up even when the triggering condition of pin 2 is met.
Arduino Uno (device) - 图33


13. [ICON] write[TEXT]to serial port

Arduino Uno (device) - 图34

Writes a text to the serial port of Arduino Uno.

How to Use

Arduino Uno uses serial communication to exchange data with other serial devices (such as computers, displays, and sensors). Serial communication is performed through digital pins 0 (RX) and 1 (TX) and the USB connector. Arduino Uno provides the TX and RX LED indicators to indicate serial communication. The TX LED indicator blinks when serial data is sent, and the RX LED indicator blinks when data is received.
Arduino Uno (device) - 图35

Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software or connect an external screen to view information of the serial port.

Example

After you turn on Arduino Uno, the text hello is written to the serial port.
Arduino Uno (device) - 图36


14. [ICON] readable bytes from serial port

Arduino Uno (device) - 图37

Reports the number of bytes that can be read by the current serial port.

Example

After you turn on Arduino Uno, the number of bytes that can be read is written to the serial port.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图38


15. [ICON] read a byte from serial port

Arduino Uno (device) - 图39

Reads a byte from the serial port.

Example

After you turn on Arduino Uno, if the number of bytes that can be read is greater than 0, the data of the serial port is read byte-by-byte.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图40


16. [ICON] map [value] from( [fromLow] , [fromHigh] )to( [toLow] , [toHigh] )

Arduino Uno (device) - 图41

Maps the specified numeric value from one set to another.

Example

After you turn on Arduino Uno, the value 50 is mapped from the set (1,100) to (1,1000) and the value obtained is written to the serial port. The final output value is 495.
Arduino Uno (device) - 图42


17. [ICON] constraint [x] between( [a] , [b] )

Arduino Uno (device) - 图43

Constrains the specified numeric value to the specified range.

Example

After you turn on Arduino Uno, the value of number is constrained to the range (0,100). Therefore, the value of number is not increased any more after it reaches 100.
Arduino Uno (device) - 图44


18. [ICON] [NUMBER] converted to [TYPE]

Arduino Uno (device) - 图45

Converts the specified numeric value into an integer, decimal, or character string.

Example

After you turn on Arduino Uno, the number 123 is converted into a decimal and written to the serial port.

Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图46


19. [ICON] [NUMBER] converted ASCII character

Arduino Uno (device) - 图47

Converts the specified decimal number into the corresponding ASCII character.

Example

After you turn on Arduino Uno, the decimal number 97 is converted into the ASCII character a.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图48


20. [ICON] [STRING] converted ASCII number

Arduino Uno (device) - 图49

Coverts the specified ASCII character into the corresponding decimal number.

Example

After you turn on Arduino Uno, the ASCII character a is converted into the corresponding decimal number 97.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图50


21. [ICON] read ultrasonic sensor trig pin [PORT1] echo pin [PORT2]

Arduino Uno (device) - 图51

Reports the value of the distance detected by the ultrasonic sensor.

How to Use

An ultrasonic sensor is used to detect the distance between the sensor and an obstacle. The detection distance ranges from 2 cm to 400 cm. Ultrasonic sensors are applicable to automatic obstacle avoiding or other ranging projects.

Ranging principle
An ultrasonic sensor includes an ultrasonic transmitter and receiver. The timing begins when the transmitter transmits an ultrasonic wave in a certain direction and stops when the receiver receives the ultrasonic wave reflected by an obstacle. Use t to denote the time. The transmission speed of ultrasonic waves in air is 340m/s. Therefore, we can calculate the distance between the ultrasonic sensor and obstacle: s = 340 × t/2.

To use this block, you need to set the pin numbers of the trig and echo pins of the ultrasonic sensor. This block is available only in the Upload mode.

Example

After you turn on Arduino Uno, the value of the distance detected by the ultrasonic sensor is read and written to the serial port.
Note: Currently, mBlock 5 does not support serial port monitors. You can use the serial port monitor provided by the Arduino software to view information of the serial port.
Arduino Uno (device) - 图52


22. when Arduino Uno starts up

Arduino Uno (device) - 图53

When Arduino Uno starts up, run the script.

Example

After you turn on Arduino Uno, the output of digital pin 13 is set to high level and the on-board LED indicator is lit up.
Arduino Uno (device) - 图54