Arduino-Basics RJFC
Arduino-Basics RJFC
▪ Arduino is the go-to gear for artists, hobbyists, students, and anyone with a
gadgetry dream.
2
3
▪ The key component of an Arduino board is the microcontroller.
▪ Traditionally, microcontrollers are pretty complicated to use.
▪ The user manual for one is easily over 300 pages long, and it’s filled
with tons of technical jargon.
▪ What the creators of Arduino did was make using microcontrollers as
easy as possible.
▪ So instead of just electrical engineers and computer scientists using
microcontrollers, now pretty much anybody can get their hands dirty
on them, and start building stuff.
https://www.programmingelectronics.com/what-is-arduino/ 4
TRIFECTA
ARDUINO Board
▪ Hardware (Circuit Board) – the physical component of the Arduino
ARDUINO IDE
▪ Integrated Development Environment – the software where code is
programmed
ARDUINO Code
▪ Arduino code you write is called a Sketch (a jargon which is the same
w/ program)
▪ a basically C & C++ programming languages but it got some Arduino
specific functions and structure
https://www.programmingelectronics.com/what-is-arduino/ 5
USB
PWR IN
(to Computer)
RESET
SCL\SDA
(I2C Bus) ▪ the Hardware –
the physical
component of
POWER the Arduino
5V / 3.3V /
GND Digital I\O
PWM(3, 5, 6, 9, 10,
11)
Analog
INPUTS
Arduino Uno
Microcontroller is
microprocessor with memory,
RAM and some other
peripheral connected with it.
Analog pins:
▪ 6 analog pins(A0, A1, A2, A3, A4, and
A5)
▪ Takes analog values as an input
10
▪Microcontrollers are digital devices – ON or OFF. Also called – discrete.
5V 5V
0V 0V
18
Upload
Compile
Status Message
error & status messages
19
▪ Arduino programming
language (API) can be
divided in three main
parts: functions, values
(variables and
constants), and
structure.
20
21
22
23
24
25
▪ setup() function
• Called when a sketch starts.
• To initialize variables, pin modes, start using
libraries, etc.
• Will only run once, after each power-up or reset
of the Arduino board.
▪ loop() function
• Loops consecutively.
• Code in the loop() section of the sketch is used
to actively control the Arduino board.
▪ Commenting
• Any line that starts with two slashes (//) will not
be read by the compiler, so you can write
anything you want after it.
26
▪ Comments are for you – the programmer and
your friends…or anyone else human that
might read your code.
comments
// this is for single line comments
BIG 6 CONCEPTS
analogWrite()
digitalRead()
analogRead()
Serial communication
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
29
30
31
32
▪ pinMode()
▪ Instruction used to set the mode (INPUT or OUTPUT) in
which we are going to use a pin.
▪ Eg: pinMode (13, OUTPUT);
▪ ie. setting pin13 as output.
▪ digitalWrite()
• Write a HIGH or a LOW value to a digital pin.
• Eg: digitalWrite (11, HIGH);
• ie. setting pin 11 to high.
33
▪ delay()
• Pauses the program for the amount of time (in milliseconds)
specified as parameter.
• Eg: delay(1000);
• ie. waits for a second (1000 ms = 1 s)
▪ digitalRead()
• Reads the value from a specified digital pin,
either HIGH or LOW
• Eg: int inPin=7;
val = digitalRead(inPin);
• ie. reads the value from inPin and assigns it to val.
34
▪ “Serial” because data is broken into bits, each sent one after another in a single
wire.
▪ Compiling turns your program into binary data (ones and zeros)
▪ The two LEDs near the USB connector blink when data is transmitted.
▪ RX blinks when the Arduino is receiving data.
▪ TX blinks when the Arduino is transmitting data
Procedure:
1. Connect your Board to the IDE by selecting the board and port
Go to: Tools > Board > Arduino AVR Boards > Arduino Uno
Tools > Port > COM#
2. Check the BOARD & SERIAL PORT SELECTIONS at the lower right of IDE for
correctness of Board and Port
▪ pinMode(pin, INPUT/OUTPUT);
▪ ex: pinMode(13, OUTPUT);
▪ digitalWrite(pin, HIGH/LOW);
▪ ex: digitalWrite(13, HIGH);
▪ delay(time_ms);
▪ ex: delay(2500); // delay of 2.5
sec.
3. Add a delay
i.e. delay(1000)
// NOTE: -> delay time is in milliseconds
File >
Example >
Basic >
Blink
41
Materials Needed: LED, 330Ω resistor, Breadboard, Jumper Wires
Procedure:
1. Connect anode (longer leg) of LED with 330Ω resistor.
2. Connect a jumper wire in the cathode (shorter leg) of LED to GND
or Ground (beside pin13).
3. Connect a jumper wire from 330Ω resistor to pin 13 header.
4. Upload the code.
▪ TASK 4: find the fastest blink that the human eye can still detect…
1 ms delay? 2 ms delay? 3 ms delay???
https://www.google.com/url?sa=i&url=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fwww.electroschematics.com%2Farduino-8-bit-binary-
led%2F&psig=AOvVaw1QxExqdldzFR9BfbFqfXTk&ust=1709577115779000&source=images&cd=vfe&opi=8997844 44
9&ved=0CBQQ3YkBahcKEwiogeW03diEAxUAAAAAHQAAAAAQCA