Getting Started with Arduino
Objectives
At the end of this self-learning lab, you should be able to:
- understand Arduino’s hardware
- starting using Arduino IDE
- write basic Arduino codes
What is Arduino?
Arduino is an open-source platform used for building electronics projects. It consists of Arduino boards and the Arduino software. Arduino board is a physical programmable circuit board, or simply called a microcontroller (MCU for microcontroller unit). There are many different types of Arduino boards with different characteristics, including Arduino UNO, Arduino NANO and Arduino MEGA.
Arduino framework makes it easy for beginners to write code. It uses a dialect of features from C++.
Please visit https://www.arduino.cc/en/guide/BoardAnatomy to know more about Arduino Uno Board Anatomy
Visual Studio Code + Platform IO
Although, the official Arduino IDE is a popular IDE to program an Arduino, Visual Studio Code is a better IDE as it provides better syntax highlighting and the Platform IO plugin allows us to install new library to our project with ease.
- Installation
Go to: https://code.visualstudio.com/ and install Visual Studio Code
Then click the Extension
icon on the left and search Platform IO IDE
and install it.
After the install is success, restart the IDE.
- Create new project
Click the Platform IO icon on the left and go to PIO home
Give name to project and select Arduino Uno
as the board we are using.
-
Edit source file
Insert the following code
#include <Arduino.h> void setup() { // put your setup code here, to run once: pinMode(LED_BUILTIN, OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }
Build and upload the code by using the the buttons on the bottom-left corner
Now you can see the LED on Uno blinking
-
Install libraries to project (Optional)
Go to PIO home and search for the library you want to use Add the library to the project Include the library in the source file or header file
Now you can use functions the library provides.#include <Adafruit_SSD1306.h> #include <Adafruit_I2CDevice.h>