Cover image: Source from “2406 Studio” official account.
This is the 15th article of Easy Science Popularization.
Arduino is not only the world’s most popular open-source hardware but also an excellent hardware development platform and a trend in hardware development. The simple development method of Arduino allows developers to focus more on creativity and implementation, completing their project development faster, greatly reducing learning costs and shortening development cycles.
Due to the various advantages of Arduino, more and more professional hardware developers have started using Arduino to develop their projects and products; more software developers are entering the hardware and IoT fields using Arduino; in universities, automation, software, and even art majors, as well as home makers and individual creators are also starting Arduino-related courses.
Our 11-year-old guest editor, Wu Lehao, is a practitioner of Arduino. Let’s listen to his learning experience!
Wu Lehao
Hello everyone, I am editor Wu Lehao, I am 11 years old, and I will be in the sixth grade when school starts. This is the first article I bring to you, “Getting Started with Arduino Without Extracurricular Classes.”
Preface
I am a primary school student, soon to be in sixth grade, and I really like programming. I mainly learn C and C++, and I love exploring Raspberry Pi, but what I am most proficient in and what I started learning with is still Arduino.
Arduino is very suitable for beginners and is very easy to get started. It uses an environment similar to C language, has a dedicated IDE, and supports many mainstream platforms (such as: Windows, MAC OS X, LINUX). Moreover, it is of high quality and low price (a board costs less than 100 yuan, and compatible boards can be even less than 20 yuan).
This summer vacation, I had some free time and decided to write an easy-to-understand introductory book for beginners. I hope readers can follow me step by step and eventually become Arduino experts.
I have been using Arduino for almost 5 years and often encounter problems that I cannot solve. Please do not get discouraged, check your code and wiring, and if it still doesn’t work, rewrite your code or reconnect the wires. All programmers have come this way step by step, and there are no shortcuts.
About Each Code
Note: Every example code in the book can be downloaded from my website: www.wulehao.com.
1 | First, look at the complete code and comments in the book as required. |
2 | Try writing it yourself without looking at the book (it is highly discouraged for beginners to have the habit of just “looking at it and finishing”!) |
3 | You can refer to the example code to verify your code. |
4 | Connect the wires according to the wiring diagram. |
5 | The moment to witness the miracle has arrived; it’s time to upload your code. |
6 | Celebrate (optional). |
About Materials
I recommend everyone to purchase the “Arduino beginner kit” from “some treasure” which contains almost all the components needed for this book. Of course, if you prefer, you can also purchase individual components.
This is the list of the most popular kits on “some treasure” (Note: This is just a reference, not an advertisement or a copy):
Overview of Development Boards
Arduino Uno R3 is the most common one, very suitable for beginners. It can be directly wired to a breadboard for testing, and there are many matching expansion boards available.
This is the introduction:
Arduino Uno is based on the ATmega328P microcontroller development board. The board consists of 14 digital input/output pins (6 of which can be used as PWM outputs), 6 analog inputs, a 16MHz quartz crystal oscillator, a USB port, a power jack, an ICSP data header, and a reset button. Uno includes all the elements needed for the microcontroller to run, and can be powered by connecting it to a computer with a USB cable, or using an AC-DC adapter or battery. The feature of Uno is that the Atmega16U2 is programmed as a USB-to-serial converter to facilitate easy installation of drivers.
Arduino Mega2560 is suitable for large projects, while Arduino Due is a microcontroller board based on Atmel SAM3X8E CPU. It is the first Arduino based on a 32-bit ARM core. It has 54 digital IO ports (12 of which can be used for PWM output), 12 analog inputs, 4 UART hardware serial ports, a clock frequency of 84 MHz, a USB OTG port, two DACs (digital-to-analog converters), two TWIs, a power jack, an SPI interface, a JTAG interface, a reset button, and an erase button.
Arduino Due runs at a relatively fast speed. It is a microcontroller board based on Atmel SAM3X8E CPU. It is the first Arduino based on a 32-bit ARM core. It has 54 digital IO ports (12 of which can be used for PWM output), 12 analog inputs, 4 UART hardware serial ports, a clock frequency of 84 MHz, a USB OTG port, two DACs (digital-to-analog converters), two TWIs, a power jack, an SPI interface, a JTAG interface, a reset button, and an erase button. (This image is provided by the Arduino Chinese community).
Arduino Pro Mini is suitable for final projects. It is the most compact version of Arduino, can be plugged into a breadboard, and is suitable for situations where size is critical. The processor core of Arduino Mini Pro is ATmega328, and it has 14 digital input/output ports (6 of which can be used as PWM outputs) and 8 analog inputs. Arduino Mini must be connected to a USB to TTL converter to download programs.
These are the boards used in this book, and there are many other versions, such as Leonardo. Please visit www.arduino.cc or www.arduino.com for more information, I won’t go into detail here.
Arduino Code Structure
(Note: “//” and “/* */” are comments, written for convenience in reading later or for others. If you don’t want to write them in the code, you can skip them!)
void setup()
{
// The program in the setup function is executed only once, generally used for I/O pin definitions and serial port initialization.
}
void loop()
{
// The loop function will be executed repeatedly, generally used for the main program.
}
Setup and loop are both functions, and in C language and C++, functions must be composed of the format:
Function Type Function Name (Parameters)
{//Opening brace
Function content
}//Closing brace.
Arduino IDE
The overall interface is as follows:
Select the development board:
Select the serial port:
Compile:
Compile + Upload:
Easy Science Popularization, fun and interesting, come and follow us!
Welcome to share and reprint, but unauthorized reprints by other official accounts are not welcome.
There is no time to explain
Press and hold to follow, get on board quickly
Leave a Comment
Your email address will not be published. Required fields are marked *