Master Arduino in Just Two Hours: A Beginner’s Guide

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

Any of them will do.

Next, you can download the Arduino software and start programming.

The initial interface looks like this:

Master Arduino in Just Two Hours: A Beginner's Guide

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

Master Arduino in Just Two Hours: A Beginner's Guide

Header files + required variables

Master Arduino in Just Two Hours: A Beginner's Guide

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

Master Arduino in Just Two Hours: A Beginner's Guide

Setting initial states in void setup()

Master Arduino in Just Two Hours: A Beginner's Guide

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

Master Arduino in Just Two Hours: A Beginner's Guide

Custom functions that will be called in loop.

Master Arduino in Just Two Hours: A Beginner's Guide

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

Master Arduino in Just Two Hours: A Beginner's Guide

Core – loop function

Master Arduino in Just Two Hours: A Beginner's Guide
Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

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:

Master Arduino in Just Two Hours: A Beginner's Guide

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.

Master Arduino in Just Two Hours: A Beginner's Guide

So…

Master Arduino in Just Two Hours: A Beginner's Guide

But actually, very few experts use Arduino.

They often look like this:

Master Arduino in Just Two Hours: A Beginner's Guide

But learning hardware and electronics is never easy.

You often find yourself in this situation:

Master Arduino in Just Two Hours: A Beginner's Guide

There’s plenty of time ahead

Master Arduino in Just Two Hours: A Beginner's Guide
Master Arduino in Just Two Hours: A Beginner's Guide
Master Arduino in Just Two Hours: A Beginner's Guide

Written by: Gao Xurong

Layout: Gao Xurong Qiu Yanliang

Scan to follow us ▇

I know you are watching me

Master Arduino in Just Two Hours: A Beginner's Guide

Leave a Comment

Your email address will not be published. Required fields are marked *