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

Arduino-Basics RJFC

Uploaded by

skyespino65
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)
13 views

Arduino-Basics RJFC

Uploaded by

skyespino65
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/ 44

Electronics & Robotics

▪ Open-source electronic prototyping platform enabling users to create


interactive electronic objects (https://www.arduino.cc/en/about)
▪ an easy to learn, open-source programmable electronics platform
(MakeUseOf, 2021)

▪ Basically Arduino is Microcontroller.


▪ With Arduino, you can control almost everything around you be it simple LED
or giant Robots.

▪ 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

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 6


Arduino Nano Arduino LilyPad

Arduino Mega 2560


DIY Arduino

Arduino Uno

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 7


a Microcontroller
Development Board

Microcontroller is
microprocessor with memory,
RAM and some other
peripheral connected with it.

The Arduino Uno is a


microcontroller board based
on the ATmega328 .
The ATmega328 has Flash
memory of 32 KB (with 0.5 KB
used for the bootloader). It
also has 2 KB of SRAM and 1
KB of EEPROM
8
▪ What does it have?
▪ 14 Digital In/Out pins (6 can be used as PWM)
▪ 6 Analog Inputs
▪ A USB Connection
▪ A Power Jack
▪ Reset Button
▪ On-board LED
▪ SCL/SDA pins (Serial Clock/ Serial Data pins)

▪ In short, it contains everything needed to support the microcontroller; simply


connect it to a computer with a USB cable or power it with a AC-to-DC adapter or
battery to get started.

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 9


Digital pins:
▪ 14 digital IO pins
▪ 6 are PWM pins (3, 5, 6, 9, 10, and 11).

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.

▪Analog signals are anything that can be a full range of values.

5V 5V

0V 0V

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 11


▪Analog Sensors ▪Digital Sensors
•Digital sensors are more
Sensors Variables straight forward than Analog.
•No matter what the sensor
Mic soundVolume there are only two settings: On
Photoresistor lightLevel and Off
Potentiometer dialPosition
•Example, Push button, Switch
Temp Sensor temperature
Flex Sensor bend
Accelerometer tilt/acceleration

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 12


13
▪ the software where
code is programmed
▪ or Arduino Software
(IDE) - contains a text
editor for writing
code, a message area,
a text console, a
toolbar with buttons
for common functions
and a series of
menus. It connects to
the Arduino hardware
to upload programs
and communicate
with them
14
▪ You need to download Arduino IDE (Integrated Development Environment).
▪ Arduino IDE is available for all Mac, Windows.and Linux.

▪ Once you have downloaded and installed/extracted the folder,


you can directly run Arduino.exe, which will take you to its IDE.
▪ The IDE will look like the shown screenshot.

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 15


▪ Before you start programming,
double check that correct board is
selected under Tools → Board.
▪ Now, you can start playing with
Arduino.

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 16


▪ The Arduino Uno can be
programmed with the Arduino
software. Select "Arduino Uno from
the Tools > Board menu (according
to the microcontroller on your
board).
▪ All the peripheral connected with
Computers are using Serial Port.
▪ You can check port for Arduino Uno
in Device Manger.

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 17


VERIFY SERIAL
MONITOR
UPLOAD
NEW TAB
OPEN CODE GOES
SAVE HERE
BOARD &
SERIAL PORT
SELECTIONS

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

// it’s good to put a description at


the top and before anything ‘tricky’

/* this is for multi-line comments


Like this…
And this….
*/
digitalWrite()

BIG 6 CONCEPTS
analogWrite()

digitalRead()

if() statements / Boolean

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)

▪ Uploading sends the bits through USB cable to the Arduino

▪ 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

Pune Makers ( http://www.meetup.com/Pune-Makers/ ) 35


Pune Makers ( http://www.meetup.com/Pune-Makers/ ) Image from Theory and Practice of Tangible User Interfaces at UC Berkley 36
Basic Coding
▪ Pin 13 is connected to a Test LED
▪ Pseudo-code – how should this work?

Turn Turn Rinse &


Wait Wait
LED ON LED OFF Repeat

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.

▪ // NOTE: -> commands are CASE-sensitive


1. In void setup(), write the pinMode you want to test and identify if it is input/output
pinMode(pin#, INPUT/OUTPUT)
i.e. pinMode(13, OUTPUT)
// NOTE: -> commands are CASE-sensitive
& always put semicolon (;) after every line

2. In void loop(), write digitalWrite(pin#, HIGH/LOW)


i.e. digitalWrite(13, HIGH)

3. Add a delay
i.e. delay(1000)
// NOTE: -> delay time is in milliseconds

4. Add LOW and delay then Upload


Go to:

File >
Example >
Basic >
Blink

*Test LED code


is LED_BUILTIN

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.

Image created in Tinkercad


▪ TASK 3: blink with a 200 ms second interval.

▪ TASK 4: find the fastest blink that the human eye can still detect…
1 ms delay? 2 ms delay? 3 ms delay???

▪ TASK 5: blink to mimic a heartbeat

▪ TASK 6: Generate your own Morse Code Flashing (SOS)

▪ TASK 7: make more LED (4) blink!


// NOTE: -> each LED will need its own 330Ω resistor
FINAL TASK (Task 8)
of Arduino Activity 1

// NOTE -> the picture is


a byte (8-bits), your task
is just 4 bits

https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.electroschematics.com%2Farduino-8-bit-binary-
led%2F&psig=AOvVaw1QxExqdldzFR9BfbFqfXTk&ust=1709577115779000&source=images&cd=vfe&opi=8997844 44
9&ved=0CBQQ3YkBahcKEwiogeW03diEAxUAAAAAHQAAAAAQCA

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy