Click the blue text to follow us
This is an article introducing and popularizing Arduino.
I will use my final project from an elective course as an example to introduce Arduino.
What is Arduino?
In simple terms, Arduino is a very easy-to-use microcontroller. As long as you have a basic knowledge of C/C++, you can create a microcontroller project that can achieve many functions in a short time.
How to use Arduino?
First, you can buy a domestic Arduino UNO R3 development board on Taobao for 28 yuan, while the “Italian imported” version costs 128 yuan.
Just buy the domestic one; after all, the domestic board also says “Made in Italy” on the back.
After buying the board, you can purchase a beginner’s tutorial book on Arduino.
Any of them will do.
Next, you can download the Arduino software and start programming.
The initial interface looks like this:
I divide the Arduino code into four parts to write, and generally following this grouping makes it easy to grasp the Arduino coding concepts.
01
Header files + required variables
The header files are the functions you want to use. For example, here I called the header files for infrared transmission and reception and servos, which will be used later. Then there are some variables that will be used later, such as servo angles and data obtained from ultrasonic measurements. The last three lines define the results obtained from functions; you will understand it better with more practice.
02
Setting initial states in void setup()
This is generally where initial states are set, and you need to learn many functions.
For example: pinMode(LED_PIN, OUTPUT); sets the input/output mode.
digitalWrite(LED_PIN, LOW); sets high/low levels.
analogWrite(pin2, 255); sets direct PWM output.
03
Custom functions that will be called in loop.
This is a function for ultrasonic distance measurement, where the principle is S=V*T/2.
If you don’t want to write it yourself, you can call the ultrasonic header file; there is definitely an ultrasonic library in the Arduino library for you to use directly.
04
Core – loop function
The loop function is the core of the entire code. The code will run in an infinite loop in the loop function. The effects we see are the results of the code executing in the loop.
For example, the loop function continuously executes ultrasonic distance measurement, infrared signal reception, and servo rotation.
These are the four sections of the code; now let’s talk about the serial monitor.
Arduino‘s Serial Monitor
What is a serial port?
In simple terms, a serial port is a type of port used to connect via data lines to transmit data. We can receive information using the serial port.
What is the serial monitor?
The serial monitor is a tool used to monitor the serial port and obtain all information from the serial port. For example, we can send data obtained from the ultrasonic module through the serial port, and this data will appear in the serial monitor.
Find the serial monitor in the Arduino tools.
Here you can obtain the distance measured by the ultrasonic sensor in our code.
The actual effect is that the serial monitor continuously scrolls, displaying real-time distance.
Of course, we can also use the serial port to obtain more data: temperature, humidity, CO concentration… as long as there is data, we can obtain it.
About Infrared Signals
Here I am using a phone to emit infrared signals. As long as your phone supports infrared remote control, you can achieve this function.
For example, my Mi 6 phone.
These are the two apps I often use to emit infrared signals.
In our daily life, we often use the phone to emit infrared signals to control home appliances. The principle is to use different infrared signals as different commands, and the receiving end executes different tasks after receiving the command.
For my code example:
The lines drawn represent different infrared signals.
These specific values can be used to emit signals with a remote control, obtaining specific values in the serial monitor. By using different values, the servo can rotate to the corresponding angle.
With this function, you can use Arduino to create a remote-controlled car, allowing the car to move through phone control.
Button 1 starts the car, button 2 makes the car go straight, button 3 turns left, and button 4 turns right. You can have multiple buttons, enough to satisfy you.
Isn’t it simple and interesting?
This concludes the introduction to using Arduino.
At first, I didn’t understand either; I quickly got the hang of it in just two hours.
I ended up with a perfect score.
So…
But actually, very few experts use Arduino.
They often look like this:
But learning hardware and electronics is never easy.
You often find yourself in this situation:
There’s plenty of time ahead
Written by: Gao Xurong
Layout: Gao Xurong Qiu Yanliang
▇ Scan to follow us ▇
I know you are watching me
Leave a Comment
Your email address will not be published. Required fields are marked *