Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
đ Ready to explore and create with us? Click [here] and join today!
Lesson 3: Entering the World of Arduino and Codingď
In our previous lesson, we successfully built the Rocker-Bogie Suspension System. However, to make it functional, we need to provide it with power, a control board, and programming to dictate its movements.
So in this lesson, weâre going to get acquainted with the control board and the programming platform weâll be using.
Course Objectivesď
Understand the basic concepts and functions of Arduino.
Learn about SunFounder R3 Board.
Install Arduino IDE and get familiar with its interface.
Learn about basic syntax rules for Arduino programming.
Course Materialsď
SunFounder R3 Board
Arduino IDE
USB Cable
Computer
Introduction to Arduinoď
You may have often heard the term âArduinoâ in various contexts, but what exactly is it and why has it become so popular?
Arduino is an open-source electronics platform that is easy to use for both hardware and software applications. Itâs designed to make digital devices and interactive objects that can sense and control the physical world around them.
Sure, letâs break it down:
Open-source: Think of open-source like a community garden. Everyone can use it, everyone can contribute to it, and everyone can benefit from it. With open-source, both the designs of the physical parts (the hardware) and the programming instructions (the software) are shared freely. This means anyone can use them, improve them, or create their own versions. Itâs all about sharing and creativity!
Microcontroller: A microcontroller is like the brain of the Arduino. Itâs a tiny computer that can run simple software. Although itâs not as powerful as the computer youâre using now, itâs perfect for simple tasks like understanding messages from sensors or lighting up an LED (a small light).
Development Board: Imagine the development board as the body that supports the brain. Itâs the board where the microcontroller sits and it contains other parts that help the microcontroller interact with the world. These parts include things like oscillators (that help with timing), voltage regulators (that control power levels), and connectors for power and data (like the plugs and switches in your house).
Arduino IDE: This is like the teaching classroom for your Arduino. Itâs a program that runs on your computer where you can write the instructions that tell your Arduino what to do. These instructions are written in a programming language based on C++. Once youâve written your instructions, you can send them to the Arduino board using a USB cable, just like handing in your homework!
Now that you understand these basic ideas, youâre well on your way to becoming an Arduino expert!
Then weâll dive into some hands-on activities to get you acquainted with Arduino programming and engineering principles. Get ready for an exciting learning journey!
Getting to Know Your SunFounder R3 Boardď
Inside your kit, youâll find a blue board, seemingly a tiny city filled with small metallic towers and pathways. But donât let it intimidate you! This is the SunFounder R3 development board, a kind of Arduino board that can be used to program and control a vast array of electronic devices and projects.
Letâs understand its key features in simple terms:
14 Digital Pins: Think of these pins like little messengers. They can be programmed to send (output) or receive (input) simple âyesâ or ânoâ messages to other parts of your Mars Rover. These messages are actually âonâ or âoffâ signals that the board uses to control things like lights or motors.
Six of these special pins can even send messages in a kind of secret code called PWM (Pulse Width Modulation). This code can be used to control how bright a light is, how fast a motor spins, or even where a moving part positions itself.
6 Analog Pins: These pins are like the boardâs six special senses. They can read signals from different types of sensors (like a temperature sensor) and then translate these signals into a language that the board can understand and use in its programming.
USB Connection: This is like the boardâs umbilical cord. You can use it to connect your board to your computer. This connection allows your computer to âteachâ the board what to do by sending it a program you write.
Power Jack: This is the boardâs food supply. You can connect a power supply, like a battery or an AC-to-DC adapter, to this jack to âfeedâ your board the electricity it needs to work.
ICSP Header: This is like a special entrance for programming the board. It can be used if you have an external programmer (a special device for âteachingâ the board).
Reset Button: If you press it, itâs like telling the board to forget what it was just doing and start its program over from the beginning.
With these basics, youâll be all set to begin your programming adventures with the SunFounder R3 board!
Install Arduino IDEď
Now that we understand what Arduino and the Arduino board are, itâs time to start putting that knowledge to use. Weâre going to install the Arduino IDE, which is the software weâll use to program our Arduino board.
The latest version of the Arduino IDE is version 2.0. Itâs packed with features and is super user-friendly. However, you should know that it does have some system requirements:
Windows - Win 10 and newer, 64 bits
Linux - 64 bits
Mac OS X - Version 10.14: âMojaveâ or newer, 64 bits
To get started, follow these steps:
Visit Arduino IDE 2.0.0 Page and download the IDE for your OS version.
For Windows users:
Once youâve downloaded the file (it will be called something like
arduino-ide_xxxx.exe
), double-click it to start the installation process.Youâll be shown the License Agreement. Take a moment to read through this, and if you agree to the terms, click âI Agreeâ.
Next, youâll be asked to choose installation options. Leave these as they are and click âNextâ.
Choose where you want to install the software. Itâs generally best to install it on a different drive than the one your system uses.
Click âInstallâ to start the installation. Once itâs done, click âFinishâ.
For macOS users:
For Linux users:
You can find a detailed tutorial on installing the Arduino IDE 2.0 on a Linux system here: Install Arduino IDE on Linux.
Discovering the Arduino Playground (IDE)ď
Letâs imagine together that the Arduino IDE is a magical playground filled with tools and gadgets waiting for us to explore and play with. Up next, I will guide you to understand every corner of this playground.
Hereâs what youâll find in your playground:
Verify / Upload - Imagine this as your magic elevator. It takes the code youâve written and whisks it up into your Arduino board.
Select Board & Port - This is your treasure map. It automatically shows the Arduino boards youâve plugged into your computer, and tells you their port number.
Sketchbook - This is your personal library. Itâs where all your sketches (programs) are stored on your computer. Plus, it can connect to the Arduino Cloud, so you can fetch your sketches from the online world too.
Boards Manager - Think of this as your toolkit. Itâs where you can find and install different packages for your Arduino.
Library Manager - This is your endless treasure chest. Thousands of libraries made by Arduino and its community are waiting for you here. Need a tool or material for your code? Dive in and find it!
Debugger - Imagine you had a superpower that let you test and debug your code in real time, finding and fixing problems as they happen. Thatâs what this is!
Search - Think of this as your magnifying glass. It helps you search for keywords in your code.
Open Serial Monitor - This is like your communicator device. It opens a new tab that lets your computer and Arduino board send messages back and forth.
Now that weâve gotten a glimpse of the playground, itâs time to dive in and start creating!
Upload Your First Sketchď
Alright, itâs time to have some fun! Weâre going to make an LED blink - itâs like saying âHello, World!â in the world of Arduino.
Most Arduino boards have a built-in LED on pin 13, which makes this a good first experiment.
Letâs break it down:
Plug it in: Connect your SunFounder R3 Board to your computer using a USB cable. This is how weâre going to give our board power and send our program (also called a âsketchâ) to it. You might feel like youâre just plugging in a computer gadget, but believe me, youâre connecting to a world of possibilities!
Find the example sketch: On the Arduino IDE, go to File -> Examples -> Basic -> Blink. What you see that pops up is a ready-to-use program that weâre going to modify. Itâs like getting a ready-made cake that weâre about to decorate!
Understand the sketch: Look at the code in this new window. It tells Arduino to turn on the built-in LED (which is on pin 13) for one second, then turn it off for one second, and then repeat. Itâs like sending Morse code, but with light!
Upload the sketch: Once youâve selected the correct board and port, just click the upload button. Itâs as easy as sending a letter; youâre delivering your instructions to the Arduino board! Most of the time, the system will automatically detect the board and port for you.
Watch it work: If all goes well, youâll see the LED on your Arduino board start to blink on and off. Itâs like your Arduino is winking at you!
Youâve done a great job! Youâve just run your first Arduino program, making you a bona fide programmer! So whatâs next? Weâre just scratching the surface of what Arduino can do. Ready for the next challenge?
Some Fun Arduino Programming Factsď
Time to uncover some cool secrets about Arduino programming!
Code Magic:
setup()
andloop()
An Arduino sketch, or a piece of code, is like a two-act play:
setup()
: This is Act 1, the opening scene. It only happens once, when your Arduino board first wakes up. Itâs used to set the stage by preparing things like pin modes and libraries.loop()
: After Act 1, we move onto Act 2 which repeats on a loop until the final curtain (which only happens if we turn off the power or hit the reset button!). This part of the code is like the main part of our play, where the action really happens.
But remember, even if thereâs no magic (code) in the
setup()
orloop()
, we still need to keep them. Theyâre like the stage - even an empty stage is still a stage.void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } // the loop function runs over and over again forever void loop() { }
Punctuation Marks in Coding
Just like in a storybook, Arduino uses special punctuation marks to make sense of the code:
Semicolons (;)
: These are like the full stops in a story. They tell the Arduino âOkay, Iâm done with this action. Whatâs next?âCurly Braces {}
: These are like the beginning and the end of a chapter. They wrap up pieces of code together, marking where a section starts and ends.
If you happen to forget some of these punctuation marks, donât worry! The Arduino is like a friendly teacher who will check your work, point out where the mistakes are, and show you how to fix them. Itâs all part of the learning adventure!
About the Functions
Imagine these functions as magical spells. Each spell has a specific effect in our Arduino adventure:
pinMode()
: This spell decides whether a pin is an INPUT or an OUTPUT. Itâs like deciding if a character in our story speaks (OUTPUT) or listens (INPUT).digitalWrite()
: This spell can turn a pin HIGH (on) or LOW (off), like switching a magic light on and off.delay()
: This spell makes the Arduino pause for a certain amount of time, like taking a short nap in the middle of our story.
Just like a spell book, you can find all these spells and many more in the Arduino official website. The more spells you know, the more exciting your Arduino adventures can be!
Comments: Our Secret Messages
We also have a secret language in coding, called
comments
. These are messages that we can write in our code using//
or/* */
. The magic part? The Arduino completely ignores them! Itâs a great place to leave notes for yourself or others to explain what the tricky parts of the code are doing.Code Readability: Making Code Friendly
While you can write your code in any manner you want (for example, placing semicolons on a separate line wonât cause any errors), itâs important to keep in mind the readability of the code.
Just like writing a good story, the way we write code can make it either fun and easy or boring and difficult to read. Here are some ways to make your code more friendly:
Use proper indentation to arrange your sentences into neat paragraphs. It helps the reader understand where one section ends and another begins.
Use variable names that make sense. Itâs like calling a character by a fitting name in a story.
Keep your functions small and simple, like short and sweet chapters in a book.
Leave comments for the tricky parts. Itâs like leaving a footnote to explain a difficult word.
Remember, weâre not only coding for machines but also for humans, so letâs make sure our code tells a clear and understandable story!
Reflect and Improve
Taking a moment to reflect on our journey can provide us with insights that we might miss in the flurry of exploration. Ask yourself:
What was the most interesting part of this Arduino adventure?
Were there any challenges along the way? How did you overcome them?
Could you explain to a friend what Arduino is, what the Arduino IDE does, or how to run Arduino code?
How would you describe your first Arduino programming experience?
What more do you want to learn about Arduino?
By thinking about these questions, you are deepening your understanding and preparing yourself for future explorations. Always remember, thereâs no âwrongâ answer in reflection â itâs your personal journey after all!