0% found this document useful (0 votes)
7 views

H2 Introduction To Arduino

Uploaded by

Abdurrohim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

H2 Introduction To Arduino

Uploaded by

Abdurrohim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Introduction to Arduino

Integrated Development system (IDE) and


Software development

1
Introduction to Arduino
• Arduino is a computation tool for sensing and controlling
signals
• It is more convenient and cost effective than using a personal
computer PC.
• It's an open-source system in terms of hardware and
software.
• You can download the Integrated Development Environment
(IDE) for your own OS from
http://arduino.cc/en/Main/Software
• Follow the instruction to install the IDE
• Useful Reference:
https://forum.arduino.cc/t/pdf-version-of-the-project-book/999501
Stem1: Introduction to Arduino v.0.a
2
(230522a)
Embedded system comparison
https://en.wikipedia.org/wiki/STM32
• ARM7, LPC2100, LPC2131, runs at 11Mz
• Arduino UNO ATmega328 Runs at 20Mz
• STM32F1 (M3) ,¥7.5
• Cortex M4, NuMicro family M4, STM32F4 ,180 MHz
STM32F4,@¥19.40,
• Raspberry Pi 3:1.1GHz Cortex-A53 550MHz
• Raspberry Pi 4:uses 64/32-bit quad-core ARM Cortex-
A72, runs at 1.5 GHz
• Apple A13,ARMv8.3-A,instruction A64,7µm,6
(2xLightning+ 4xThunder)2.65 GHz
Stem1: Introduction to Arduino v.0.a (2305 3
22a)
Download Arduino IDE, from
• https://www.arduino.cc/en/software. Pick “Just download” if
asked, it is ok if you don’t want to donate money.
• Pick your choice

Stem1: Introduction to Arduino v.0.a (2305 4


22a)
Run the first test
• Select: FileExample-01 Basics Blink

//The main part of the code


// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
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
}

Stem1: Introduction to Arduino v.0.a (2305 5


22a)
Working with Arduino IDE 2: Select your
board and USB

• After installation you


need to pick setup the
board-library .

Stem1: Introduction to Arduino v.0.a (2305 6


22a)
Verify/compile and
upload
• Sketch  Verify/Compile
– If it is successful
• Sketch  upload
• You may have to run
“select board” and select
USB num.
– Find Arduino UNO , and
select the suitable USB-
COM. etc.
Stem1: Introduction to Arduino v.0.a (2305 7
22a)
Setup sketch and library directory
• The default position may cause problems
when using Chinese Windows, set it to “c:\
Arduino_project” should work

Stem1: Introduction to Arduino v.0.a (2305 8


22a)
Add libraries for hardware/sensors
• E.g. If your code needs DHT.h
• #include
<Adafruit_Sensor.h>
• #include <DHT.h>
• #include <DHT_U.h>
• You may download the libraries
• Step1: Click “tools/manage
libraries”
• Step2: the “LIBRARY MANAGER”
will be shown. Type “DHT” or
“Adafruit_Sensor” in the
search windows for libraries
• Step3: if you see suitable library
click INSTALL

Stem1: Introduction to Arduino v.0.a (2305 9


22a)
Arduino UNO
14 digital input/output (I/O) pins
• Microcontroller is based on 13,12,… ………2,1,0
ATmega328
– If needed , download Arduino Integrated D
evelopment Environment IDE http://arduino.cc
/en/Main/Software#toc1

• 14 digital input/output (I/O)


pins plus
• 6 analog input pins (these A0-A5
6 Analog inputs, they can also be
pins can also be programmed used as digital I/O pins
to be digital I/O pins)
• A 16 MHz ceramic resonator

Stem1: Introduction to Arduino v.0.a


10
(230522a)
Start to use the Arduino. This I
is IDE1. IDE2 may looks slightly
different but similar fucntion.

• To start Arduino IDE,


click Start Menu 
All Programs 
Arduino

• Make sure the board


model (Arduino Uno)
and connected port
(depends on your
Your board Model The port that your
PC) are correct board connected to
Stem1: Introduction to Arduino v.0.a
11
(230522a)
Select Board

Select a correct board

Stem1: Introduction to Arduino v.0.a


12
(230522a)
Select Port

Select a correct port.


The actual number
depends on your
system.

Find Port Number on Windows


Open WIN10-Device Manager, and expand
the Ports (COM & LPT) list. Note the
number on the USB Serial Port.
Unplug-and pulg the USB cable connected
to the Arduino board will see the port
displayed

Stem1: Introduction to Arduino v.0.a


13
(230522a)
Arduino IDE (integrated development environment )

Tool Bar Serial monitor,


Can use this to issue
commands to the
board, and read
outputs from the
board.
This programming Area
is called “Sketch”.

The program code are placed here.

Status Message

Messages from the system

Stem1: Introduction to Arduino v.0.a


14
(230522a)
Toolbar
• Verify
• Checks code for errors
• Upload
• Compiles and uploads code to the Arduino I/O board
• New
• Creates a new sketch
• Open
• Open sketch
• Save
• Save sketch
• Serial Monitor
• Display serial data being sent from the Arduino board
Stem1: Introduction to Arduino v.0.a
15
(230522a)
Arduino Code
To run a program in Arduino, your sketch should
contain two methods
void setup()
{
// initialization of variables, pin modes, libraries
// run once after each power up or reset
}

void loop()
{
// loops the content consecutively
// allowing the program to change and respond
}
Stem1: Introduction to Arduino v.0.a
16
(230522a)
Simple experiment
Try in the main Arudino IDE window:
Step1: Click File  Examples 01. basics  Blink
•Step2: Click Sketch  upload (will run automatically)
or Click on the tick will has the effect
The program code (The LED on File 01Basics
the Arduino -Uno board will
blink) Blink

• // the setup function runs once when you press reset or power
Example
the board
• void setup() {
• // initialize digital pin LED_BUILTIN as an output.
• pinMode(LED_BUILTIN, OUTPUT);
• }
// the loop function runs over and over again forever
• void loop() {
• 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
• } Stem1: Introduction to Arduino v.0.a (2305 17
22a)
Basic software functions
• Hardware related
– pinMode(), setup the functions of hardware pins
– digitalWrite() , set a pin to a digital level : either HIGH or LOW
– Digitalread(), read the digital level of a pin: either HIGH or LOW
– delay()
• Software related
– If-then-else
– For
– Switch-case
• Additional useful functions: Analog read/write
– analogRead() , read the level of an analog pin (any one of A0-A5), data value is from
0 to 1024 (equivalent to 0 - 5V)
– analogWrite(), set an analog pin (any one of A0-A5) to 0-5V
Stem1: Introduction to Arduino v.0.a
18
(230522a)
System setup procedures
• (Step 1) Setup the direction of the pins:
– using pinMode(),
• (Step 2) Then you can set a pin to : HIGH or
LOW
– (Step 2a) digitalWrite() //set pin to : HIGH ‘1’ or
LOW ‘0’
– or
– (step 2b) digitalRead(), //read state of pin: HIGH
‘1’ or LOW ‘0’
Stem1: Introduction to Arduino v.0.a
19
(230522a)
Basic Function (step1) – pinMode()
• pinMode() is used to configure the specified pin to behave
either as an input or output, or input_pullup
• Syntax Pin =0,..,13, or A0,A1,..,A5
Write comment for you to read
for Digital I/O, or
pinMode(pin, mode) // comment

– pin: the index number of the pin whose mode you wish to set
– mode: INPUT, OUTPUT, INPUT_PULLUP
– Example:
• pinMode(1, OUTPUT)//setup pin1 =digital out
• pinMode(3, INPUT)//setup pin3 =digital in
• pinMode(A3, INPUT)//setup A3 for digital in
• pinMode(A3, OUTPUT)//setup A3 for digital out
• If no PinMode applied to A0->A5, they are analog_in by default.

Stem1: Introduction to Arduino v.0.a


20
(230522a)
Meaning of INPUT, OUTPUT, INPUT_PULLUP

HIGH(5V) or LOW(0V)
• INPUT: Arduino

• OUTPUT:
HIGH(5V) or LOW (0V) Arduino

High(5V))
• INPUT_PULLUP:
1KΩ
When the pin is not Arduino
connect to HIGH(5V) or LOW)
or
anything, it is HIGH not_connected_to_anything

Stem1: Introduction to Arduino v.0.a


21
(230522a)
Basic Function(step2a) – digitalWrite()

• digitalWrite() is used to write a HIGH or a LOW value to


a digital pin

• Syntax digitalWrite(pin, value) // comment

– pin: the number of the pin whose value you wish to set
– value: HIGH (5 V) or LOW (Ground)
– Example:
• digitalWrite(pin, value) // comment
• E.g
• digitalWrite(1, HIGH)//set pin1 to HIGH
Stem1: Introduction to Arduino v.0.a
22
(230522a)
Basic Function(step2b) – digitalRead()
• digitalWrite() is used to read the value from a
specified digital pin, either HIGH or LOW
digitalRead(pin)
• Syntax

– pin: the number of the pin whose mode you want to read
(integer)
– Example:
• digitalRead(pin)// read the state of the
• // it can be “HIGH” or “LOW”

Stem1: Introduction to Arduino v.0.a


23
(230522a)
Some other basic Function – delay()
• delay() is used to pause the program for the
amount of time (in milliseconds)
delay(ms)
• Syntax

– ms: the number of milliseconds to pause


(unsigned long)

Stem1: Introduction to Arduino v.0.a


24
(230522a)
Basic Control Structure – IF
• Syntax
IF(condition1){
// do stuff if condition1 is true
}ELSE IF (condition2){
// do stuff only if condition1 is false
// and conition2 is true
}ELSE{
// do stuff when both condition1 and
// condition2 are false
}

Stem1: Introduction to Arduino v.0.a


25
(230522a)
Basic Control Structure – FOR
• Syntax
FOR(initialization; condition; increment){
// statement(s);
}

Stem1: Introduction to Arduino v.0.a


26
(230522a)
Basic Control Structure
– SWITCH-CASE
• switch (var) {
• case label1:
• // statements when var=label1
• break;
• case label2:
• // statements when var=label2
• break;
• default:
• // statements
• }

Stem1: Introduction to Arduino v.0.a


27
(230522a)
More Functions
• Please visit http://arduino.cc/en/Reference/
for Arduino Language Reference

Stem1: Introduction to Arduino v.0.a


28
(230522a)
Conclusion
• Learned how to use the IDE (interactive
development environment) of Arduino
• Learned how to upload program to the
Arduino board
• We studied the basic functions of an Arduino
system

Stem1: Introduction to Arduino v.0.a (2305 29


22a)
Reference
• https://forum.arduino.cc/t/pdf-version-of-the-
project-book/999501

Stem1: Introduction to Arduino v.0.a (2305 30


22a)

You might also like