0% found this document useful (0 votes)
3 views15 pages

Master Arduino Basics

Samuel Boateng is an educator with a focus on making technology education accessible, particularly in Arduino and IoT. The document outlines a guide for mastering Arduino basics, including installation, coding, and practical projects like blinking LEDs and using a real-time clock module. It serves as a comprehensive resource for beginners to learn about Arduino programming and electronics.

Uploaded by

Rufai Suleman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

Master Arduino Basics

Samuel Boateng is an educator with a focus on making technology education accessible, particularly in Arduino and IoT. The document outlines a guide for mastering Arduino basics, including installation, coding, and practical projects like blinking LEDs and using a real-time clock module. It serves as a comprehensive resource for beginners to learn about Arduino programming and electronics.

Uploaded by

Rufai Suleman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

ABOUT THE AUTHOR

Samuel Boateng is a passionate educator


commitment to making technology education accessible and enjoyable shines through in his writing and
teaching efforts. He is a technology enthusiast with a strong background in electronics, Arduino projects,
and IoT. He holds Diploma in Basic Education and an HND in Electrical/Electronic Engineering and has
years of experience in teaching and developing creative tech solutions. Through his platform, Samtec
Innovation, Samuel is dedicated to helping beginners, especially children, grasp the essentials of
technology, fostering their skills in robotics, electronics, and programming. His
He currently teaches Electrical and Electronic Principles at J.G. Knol Technical Institute at Adukrom
Akwapim in the Eastern Region of Ghana.
MASTER THE BASICS OF ARDUINO IN ONE WEEK
Contents
1 CHAPTER ONE ....................................................................................................................................... 4
1.1 DEFINITION OF ARDUINO ............................................................................................................ 4
1.2 SOME TYPES OF ARDUINO MICROCONTROLLER BOARDS ....................................................... 4
1.3 ARDUINO UNO PINOUTS ............................................................................................................. 4
1.4 DOWNLOADING AND INSTALLING ARDUINO INTEGRATED DEVELOPMENT ENVIRONMENT
(IDE) 5
1.5 INSTALLATION OF ARDUINO BOARD DRIVERS ........................................................................ 5
1.6 VERIFYING AUTOMATIC INSTALLATION OF DRIVERS .............................................................. 5
1.7 EVIDENCE OF SUCCESSFUL AUTOMATIC INSTALLATION OF ARDUINO DRIVERS. ................. 5
1.8 STRUCTURE OF ARDUINO SKETCH ............................................................................................ 6
1.8.1 VOID SETUP () FUNCTION ........................................................................................................ 6
1.8.2 EXAMPLES OF CODE IN VOID SETUP ....................................................................................... 6
1.8.3 VOID LOOP ( ) .......................................................................................................................... 6
1.8.4 EXAMPLES OF CODE IN LOOP FUNCTION................................................................................ 6
1.8.5 COMBINING BOTH VOID SETUP AND VOID LOOP FUNCTION ................................................. 7
2 CHAPTER TWO ...................................................................................................................................... 8
2.1 BLINKING OF AN LED ................................................................................................................. 8
2.2 CIRCUIT DIAGRAM ..................................................................................................................... 8
2.3 CODE ........................................................................................................................................... 9
2.4 BLINKING TWO LEDS AT DIFFERENT TIME INTERVAL .............................................................. 9
2.5 CIRCUIT DIAGRAM ..................................................................................................................... 9
2.6 CODE ......................................................................................................................................... 10
2.6.1 EXERCISE ................................................................................................................................ 10
2.7 OUTPUT SIMULATION OF TWO LEDS USING PROTEUS ......................................................... 10
3 CHAPTER THRE .................................................................................................................................... 11
3.1 DOWNLOADING, INSTALLATION AND INCLUDING LIBRARY IN ARDUINO IDE ........................... 11
3.1.1 Installation of libraries from the library manager ................................................................. 11
3.1.2 Adding Library Manually ....................................................................................................... 11
3.1.3 Manually install library inside libraries folder ....................................................................... 12
3.2 DISPLAYING TIME AND DATE USING RTC DS3231 ...................................................................... 12
3.3 WIRING GUIDE AND INSTALLATION OF NEEDED LIBRARIES ...................................................... 12
3.4 CIRCUIT DIAGRAM AND OUTPUT OF PROTEUS SIMULATION ................................................... 13
3.5 CODE .......................................................................................................................................... 14
.................................................................................................................................................................... 14
1 CHAPTER ONE
OBJECTIVES
By the end of this unit, the learner will be able to:
❖ Explain what Arduino is
❖ List some types of Arduino boards
❖ Identify Arduino pinouts
❖ Download and install the Arduino IDE
❖ Install the Arduino drivers
❖ Identify the structure of an Arduino sketch

1.1 DEFINITION OF ARDUINO


Arduino is an open-source electronics platform based on easy-to-use hardware and software. It consists of
a physical programmable circuit board (often referred to as a microcontroller) and a development
environment used to write and upload computer code to the board.
1.2 SOME TYPES OF ARDUINO MICROCONTROLLER BOARDS
❖ ATmega328P (used in Arduino Uno)
❖ ATmega2560 (used in Arduino Mega)
❖ Arduino Nano
❖ Arduino Pro Mini
❖ Arduino Leonardo
1.3 ARDUINO UNO PINOUTS
1.4 DOWNLOADING AND INSTALLING ARDUINO INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
The Arduino Integrated Development Environment (IDE) is the software you’ll use to write and upload
code to your Arduino board. It’s free and available for Windows, macOS, and Linux. You can download it
from the official Arduino website.
Download and install the Arduino IDE using this link. ( https://www.arduino.cc/en/software )
1.5 INSTALLATION OF ARDUINO BOARD DRIVERS
❖ Installing Arduino drivers for the first time involves a few straightforward steps. Here’s a step-by-
step guide:
❖ Connect Arduino board to Computer:
o Use a USB cable to connect your Arduino board to your computer.
❖ Windows Detection:
o Windows will automatically attempt to install basic drivers. Let it complete this process,
1.6 VERIFYING AUTOMATIC INSTALLATION OF DRIVERS
❖ Connect the Arduino board to the computer
❖ Open your Arduino IDE
❖ Go to tools
❖ Select the board type you have connected
❖ From tools>port
❖ If drivers are correctly installed, you will see com4(Arduino/Genuino Uno
1.7 EVIDENCE OF SUCCESSFUL AUTOMATIC INSTALLATION OF ARDUINO
DRIVERS.
This shows that drivers have successfully been installed. The type of board connected to the computer is
visible. Therefore, you can upload your code unto the microcontroller.
1.8 STRUCTURE OF ARDUINO SKETCH
1.8.1 VOID SETUP () FUNCTION
❖ Runs once when the Arduino is powered on or reset.
❖ Used for initialization, such as setting pin modes (input/output), starting serial
communication, and initializing sensors.
1.8.2 EXAMPLES OF CODE IN VOID SETUP

1.8.3 VOID LOOP ( )


❖ Continuously runs after the setup ( ) function finishes.
❖ Contains the main logic of the program, such as reading sensor data, controlling actuators,
and responding to inputs.
1.8.4 EXAMPLES OF CODE IN LOOP FUNCTION
1.8.5 COMBINING BOTH VOID SETUP AND VOID LOOP FUNCTION
2 CHAPTER TWO
OBJECTIVES
By the end of this unit, the learner will be able to:
❖ Design, construct and write the code for blinking an LED
❖ Design, construct and write the code for blinking two LEDs at different time interval

2.1 BLINKING OF AN LED


Components Needed
❖ Arduino Uno board
❖ LED
❖ Breadboard
❖ Male to male jumper wires
❖ 220Ω resistor

2.2 CIRCUIT DIAGRAM


2.3 CODE

2.4 BLINKING TWO LEDS AT DIFFERENT TIME INTERVAL


Component needed
❖ Arduino Uno board
❖ Two LEDs
❖ Breadboard
❖ Male to male jumper wires
❖ Two, 220Ω resistors

2.5 CIRCUIT DIAGRAM


2.6 CODE

2.6.1 EXERCISE
1. Change the delay time to make the LEDs blink faster or slower.
2. Add more LEDs and control them using different pins
2.7 OUTPUT SIMULATION OF TWO LEDS USING PROTEUS

The blue LED is on while the yellow LED is off. The yellow LED is on while the blue LED is off.
3 CHAPTER THRE
3.1 DOWNLOADING, INSTALLATION AND INCLUDING LIBRARY IN ARDUINO IDE
OBJECTIVES
By the end of this unit, the learner will be able to:
❖ Install libraries from the library manager
❖ Add libraries manually
❖ Manually install library inside libraries folder

3.1.1 Installation of libraries from the library manager

▪ Open the Arduino IDE:


▪ Launch the Arduino IDE on your computer.
Access the Library Manager
▪ Click on Sketch in the menu bar.
▪ Hover over Include Library.
▪ Select Manage Libraries… from the submenu.
Search for the Library
▪ In the Library Manager window, you’ll see a search bar at the top right.
▪ Type the name of the library you want to add (e.g., RTClib or LiquidCrystal or Software Serial).
Install the Library:
▪ Once you find the desired library, click on it to select it.
▪ You will see an Install button on the right side. Click on this button to install the library.
▪ Wait for the installation to complete.
Close the Library Manager:
▪ After installation, you can close the Library Manager window.
Include the Library in Your Sketch:
▪ Now that the library is installed, you can include it in your sketch by adding #include
<LibraryName.h> at the beginning of your code.

3.1.2 Adding Library Manually


If you have a library file that you want to add manually (for example, if you downloaded it from GitHub),
follow these steps:
▪ Download the Library:
▪ Download the library as a ZIP file from the source (e.g., GitHub).
Open the Arduino IDE:
▪ Launch the Arduino IDE on your computer.
Access the Library Manager:
▪ Click on Sketch in the menu bar.
▪ Hover over Include Library.
▪ Select Add .ZIP Library… from the submenu.
▪ A file dialog will open. Navigate to the location where you downloaded the ZIP file.
▪ Select the ZIP file and click Open.
Library Installation:
▪ The Arduino IDE will automatically install the library from the ZIP file.
▪ Include the Library in Your Sketch:
▪ You can now include the library in your sketch using #include <LibraryName.h>.
3.1.3 Manually install library inside libraries folder
Download the Library:
▪ Download the library files, usually as a ZIP file or a folder.
Locate the Arduino Libraries Folder:
▪ The Arduino libraries folder is typically located in your Arduino sketchbook directory.
▪ You can find it by going to File > Preferences in the Arduino IDE. The path to your sketchbook
folder will be shown there.
Create a Library Folder:
▪ Inside the Libraries folder, create a new folder named after the library (e.g., RTClib).
Copy Files:
▪ Unzip the library ZIP file if necessary.
▪ Copy the library files into the newly created folder. Ensure the folder structure is correct (the
header file .h and the source file .cpp should be directly inside the library folder).
Restart the Arduino IDE:
▪ Close and reopen the Arduino IDE to recognize the new library.
Include the Library in Your Sketch:
▪ Use #include <LibraryName.h> at the beginning of your code.

3.2 DISPLAYING TIME AND DATE USING RTC DS3231

Overview
This project uses the DS3231 Real-Time Clock (RTC) module to keep track of and display the current
time and date.
Components Required
❖ Arduino Uno board
❖ DS3231 RTC module
❖ LCD (16x2)
❖ Breadboard
❖ Jumper wires

3.3 WIRING GUIDE AND INSTALLATION OF NEEDED LIBRARIES


 DS3231 RTC Module:
 Vcc to 5V on Arduino.
 GND to GND on Arduino.
 SDA to A4 on Arduino.
 SCL to A5 on Arduino.
I2C LCD Display:
 SDA to A4 on Arduino.
 SCL to A5 on Arduino.
 Vcc to 5V on Arduino.
 GND to GND on Arduino.
 Install the Necessary Libraries:
 In the Arduino IDE, go to Sketch > Include Library > Manage Libraries.
 Install the RTClib and LiquidCrystal_I2C libraries.
3.4 CIRCUIT DIAGRAM AND OUTPUT OF PROTEUS SIMULATION
3.5 CODE

#include <Wire.h> void loop() {

#include <RTClib.h> unsigned long currentMillis = millis();

#include <LiquidCrystal.h> // Alternate display every few seconds

// Initialize the LCD (pins 13 12, 11, 10, 9, 8 are connected if (currentMillis - displayMillis >= displayInterval) {
to LCD)
displayMillis = currentMillis;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
displayTime = !displayTime; }
// Initialize the RTC
// Display time or date on the first line
RTC_DS3231 rtc;
lcd.setCursor(0, 0);
// Time variables
DateTime now = rtc.now();
unsigned long displayMillis = 0;
if (displayTime) {
const long displayInterval = 5000; // 5 seconds interval for
alternating display lcd.print("Time: ");

bool displayTime = true; // Flag to alternate between time lcd.print(formatTime(now.hour(), now.minute()));


and date
} else {
void setup() {
lcd.print("Date: ");
// Initialize the LCD
lcd.print(now.day());
lcd.begin(16, 2);
lcd.print('/');
lcd.print(" Samtec Nexus");
lcd.print(now.month());
delay(100);
lcd.print('/');
// Initialize the RTC
lcd.print(now.year()); }}
if (!rtc.begin()) {
// Function to format time in 12-hour format with AM/PM
lcd.setCursor(0, 1);
String formatTime(int hour, int minute) {
lcd.print("Couldn't find RTC");
String period = " AM";
while (1);}
if (hour >= 12) {
// Check if RTC lost power and set a default date and time
period = " PM";
if necessary
if (hour > 12) {
if (rtc.lostPower()) {
hour -= 12; }
lcd.setCursor(0, 1);
} else if (hour == 0) {
lcd.print("RTC lost power");
hour = 12; }
// Set the date and time to a specific value, e.g., Jan 1
2024 00:00:00 char timeBuffer[6];
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // snprintf(timeBuffer, sizeof(timeBuffer), "%02d:%02d",
Set RTC to the date and time the sketch was compiled hour, minute);
delay(2000); // Delay to show the message}} return String(timeBuffer) + period;}
REFERENCES
https://diyguru.org/term/arduino-pin-diagram/
RESOURCES
1. Arduino IDE
2. Proteus simulation software
3. Fritzing software

Feel free to contact me for any help especially on how to write the code with easy. In fact, you do
not need to be a computer scientist to write codes these days. Contact me on:
brainytech87@gmail.com

You might also like