Today, Teacher Cheng from the Marker Pen Design Study Abroad program continues to explain the relevant knowledge of Arduino. Previously, we introduced many Arduino sensors in the article “How to Use Arduino Human Infrared Sensors”. In this article, we will discuss the programming language within Arduino, specifically the application of some common functions.
Arduino is written in a mix of C/C++. The Arduino language inherits the syntax of C/C++. The so-called Arduino language refers to a collection of various application programming interfaces (API) provided by the Arduino core library files. The basic structure of an Arduino program consists of two functions: setup() and loop(). Let’s first take a look at how these two functions are used.
After the Arduino controller is powered on or reset, it will start executing the program within the setup() function. Generally, we write the program to be executed within the brackets, and this part of the program will only run once. Typically, we complete the Arduino initialization settings in the setup() function, such as configuring I/O port states, initializing the serial port, and other operations.
After the program in the setup() function has executed, the Arduino will then execute the program in the loop() function. The loop() function is a dead loop, where the program continuously runs repeatedly. Usually, we complete the main functions of the program in the loop() function, such as driving various modules and collecting data. Taking the simplest example of a blinking light bulb, we can explain the LOOP function: the content written within the brackets can be interpreted as follows: first, the LED light bulb turns on, then it waits for one second, then the LED light bulb turns off, and then waits for another second, finally repeating this segment of the program, thus achieving the blinking effect of the light bulb.

-
Description: Pauses the program for a given amount of time (in milliseconds).
-
Function Prototype: delay(ms)
-
Parameter: ms – the number of milliseconds to pause.
-
Return Value: None.
The if-else statement is a selection structure that allows the code to choose to execute. The so-called selective execution means that “some code may execute, or may not execute, selectively executing some code”. An if statement can be followed by an optional else if … else statement, which is very useful for testing various conditions.
When using if … else if … else statements, we need to remember three key points:
1) An if can have 0 or 1 else statement, which must be after all else ifs.
2) if can have 0 to multiple else if statements, which must be before the else.
3) Once an else if is successful, the remaining else if or else statements will not be tested.


HIGH | LOW indicates the high and low levels of digital I/O ports. HIGH indicates high voltage (1), LOW indicates low voltage (0).
INPUT | OUTPUT indicates the direction of digital I/O ports, INPUT indicates input (high impedance), OUTPUT indicates output (the AVR microcontroller can provide 5V voltage and 40mA current). The low output level in Arduino is 0V, and the high output level is the current working voltage of the Arduino. For example, the working voltage of Arduino UNO is 5V, so its high output level is also 5V; the working voltage of Arduino UNO is 3.3V, so the high output level is also 3.3V.
Students who have not come into contact with the C language may find it a bit difficult to absorb so much knowledge at once. However, learning C language is not very difficult and is quite friendly. We can start by writing some simple statements and using simple functions to conduct experiments. Once we truly master the application scenarios of various common functions, we can achieve complex effects. I must also emphasize that whether it is Arduino circuit connections or learning C language, continuous attempts and trial and error are necessary; only through this can we truly learn how to use functions.
Article Author:Cheng Yaqiu
Master’s Degree in Product Design from the Royal College of Art, UK
Specializes in product service system design, user experience design, and hardware Arduino interaction
Any questions about schools and portfolios
Feel free to communicate at any time
Knowledge should be shared openly.