Arduino

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 67

WHY LEARN THIS?

ARDUINO
MICROCONTROLLER
A computer for the physical world.
Able to read INPUTS – light on a sensor, a
finger on a button, or a Twitter message.

Turn it into OUTPUTS – activating a motor,


turning on an LED, publishing something
online.

Tell your Arduino what to do using the www.arduino.cc


Arduino programming language.

Uses information from INPUTS to control various OUTPUTS.


REDBOARD
MICROCONTROLLER
Sparkfun’s version of Arduino.

Uses same programming language and


electrical components as Arduino.

Sparkfun offers a lot of cool tutorials and


project ideas. Visit their website:
www.sparkfun.com

We have a handful of Sparkfun Inventor’s


Kits for checkout in the EPICS workshop
that have everything you need to get
started building cool stuff.
6

5
7
2 4
3

10
ARDUINO UNO
1) Power In (Barrel Jack): Can be used with either a 9V or 12V wall-wart or battery
2) Power In (USB Port): Provides power and communicates with your board when
plugged into your computer via USB.
3) LED (RX: Receiving): Lights up when the Arduino is receiving data (such as when
being programmed).
4) LED (TX: Transmitting): Lights up when your Arduino is transmitting data (such as
when running a program).
5) LED (Pin 13: Troubleshooting): LED is incorporated into your sketch to show if
your program is running properly.
6) Pins (ARef, Ground, Digital, Rx, Tx): Used for inputs, outputs, power, and ground.
7) LED (Indicates Arduino is ON): Simple power indicator LED.
8) Reset button: Used to manually reset Arduino, which makes code restart.
9) ICSP Pins: For “in-circuit serial programming,” used if you want to bypass the
bootloader.
10) Pins (Analog In, Power In, Ground, Power Out, Reset): Used for inputs, outputs,
power, and ground.
DOWNLOAD ARDUINO IDE
(INTEGRATED DEVELOPMENT ENVIRONMENT)

arduino.cc
/en/main/
software
CONNECT REDBOARD
TO YOUR COMPUTER
INSTALL ARDUINO
DRIVERS
OPEN ARDUINO IDE
SELECT YOUR BOARD
SELECT SERIAL
DEVICE (WINDOWS)
SELECT SERIAL
DEVICE (MAC)
DOWNLOAD CODE
KNOW THE ARDUINO
GUI
Verify: Compiles
and approves your
code. Will catch
errors in syntax.
KNOW THE ARDUINO
GUI
Upload: Sends
your code to the
RedBoard. When
you click it you
should see lights
on your board blink
rapidly.
KNOW THE ARDUINO
GUI
New: Opens up
a new code
window tab.
KNOW THE ARDUINO
GUI
Open: Open an
existing sketch,
which is where you
write your code.
KNOW THE ARDUINO
GUI
Save: Saves the
currently open
sketch.
KNOW THE ARDUINO
GUI
Serial
Monitor:
Opens a window
that displays any
serial info the
RedBoard is
transmitting. Very
useful for
debugging.

What is Serial?
Process of sending
data one bit (0 or
1) at a time.
KNOW THE ARDUINO
GUI
Sketch
Name: Name of
the sketch you are
currently working
on.
KNOW THE ARDUINO
GUI
Code Area:
Area where you
compose the code
for your sketch.
KNOW THE ARDUINO
GUI
Message
Area: Where the
IDE tells you if
there were any
errors in your code.
WHAT IS A CIRCUIT?
Electricity running in a loop with a
starting point and ending point – and a
number of components in between.

Can include resistors, diodes, inductors,


sensors of all shapes and sizes, motors,
and hundreds of thousands of other
components.

OHM’S LAW
Voltage = Current x Resistance The LED above needs 20
V = IR mA (milliamps) of current.
What size resistor should
Voltage is measured in VOLTS (V)
you use?
Current is measured in AMPERES (A)
Resistance is measured in OHMS (Ω)
BREADBOARD
How it looks How it’s connected
Connect power to
the + vertical
columns

Connect ground
down the -
vertical columns

Components placed
along horizontal
rows will be
connected when
power is running.
This line divides the
board in half
JUMPER WIRE
330 Ω RESISTOR
10 KΩ RESISTOR
POTENTIOMETER
LIGHT EMITTING
DIODE (LED)
PHOTO RESISTOR
TEMPERATURE
SENSOR
ARDUINO PINS
ANALOG VS DIGITAL
SIGNALS
5V

0V

5V

0V

Learn more: https://www.youtube.com/watch?v=Z3rsO912e3I


ANALOG TO DIGITAL
CONVERSION
Need to convert analog
signals to digital for
processing.

Digital signal depends on


the resolution of the
analog-to-digital converter
(ADC).

A 10-bit system will have


1,024 points of resolution.

210 = 1,024

Why the number 2?


Because there are two options in a binary system (0 & 1).
ANALOG TO DIGITAL
CONVERSION
Arduino translates an analog input voltage into a number
that ranges from 0 - 1,023.
Digital voltages are translated into a number that ranges
from 0 – 255.

0 255
CIRCUIT #1:
BLINKING AN LED
LEDs (light emitting
diodes) are small, powerful
lights used in many
different applications.

We’re going to learn how


to blink an LED on and off.
RESISTOR COLOR
CODE
CIRCUIT SCHEMATIC
Pin 13 is a digital pin and can be used as
an output or an input. Here we will use it to
output power to the LED.

Pin 13 will be connected to


the positive lead on the LED.

The negative lead on the


LED will be connected to
one leg of the resistor.

The other leg of the resistor


will be connected to ground
to complete the circuit.

Note: These components are all in series (one


after the other, like beads on a string).
DESIGN IT!
CREATE THE SKETCH
/*
Blink
Turns on an LED for one second then off for one second, repeatedly.
*/
void setup() {
pinMode(13, OUTPUT);
}
 
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
CIRCUIT #2:
POTENTIOMETER
How to read analog input from the physical world
using a potentiometer (“pot” for short) and control the
blink rate of an LED. We’ll also learn how to use the
serial monitor to watch how the voltage changes.

When it’s connected with 5V across its two outer


pins, the middle pin outputs a voltage between 0 and +5V
5V, depending on the position of the knob. In this
way, it can be used as a “voltage divider”.
Analog
Input
GND
CIRCUIT SCHEMATIC
The left side of the
schematic is the same as
the previous circuit.

We’re adding a
potentiometer to
control the blink rate
of the LED.

We’re running 5V across the


outer pins of the pot. The middle
pin of the potentiometer will be
connected to analog input pin 0.

Note: All analog pins on the Arduino are INPUT


pins. Digital pins can be INPUT or OUTPUT pins.
DESIGN IT!
CREATE THE SKETCH
int sensorPin =0;
int ledPin =13;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); 
}
 
void loop() {
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue);
}
CIRCUIT #3
PHOTO RESISTOR (LIGHT SENSOR)
Photoresistors change resistance based
on how much light the sensor receives.
Use our photo resistor in a “voltage
divider” configuration. Output:
High voltage = lot of light
Low voltage = little light

Brighten and dim an LED based on the


light level picked up by the photo
resistor.

So…in this case we’re using a digital signal to control an analog output.
Wait! I thought Arduino didn’t have a digital-to-analog converter?!?
RESISTIVE SENSORS
& VOLTAGE DIVIDERS Resistor in disguise!

Arduino measures voltage, not


resistance. Need a voltage divider:
• Consists of two resistors. Top resistor
• The “top” resistor is the sensor.
• The “bottom” resistor is a
normal, fixed resistor (usually 10 Bottom resistor
KΩ).
When top resistor is connected to 5V and the bottom
resistor to ground, the middle will output a voltage
proportional to the values of the two resistors.

This is how we use resistive sensors


to measure voltage.
PULSE WIDTH
MODULATION
Sneaky trick Arduino uses to simulate the output of an analog signal.
Arduino is so fast it can blink a pin on and off 1,000 times per second.
PWM pins also vary amount of time blinking pin spends on HIGH vs.
LOW.

Use function: analogWrite(pin, value)


• Choose a pin marked by a ~
• Value is the duty cycle
• 0 = always OFF
• 255 = always ON
• 127 = on HALF the time
(50% duty cycle)
PULSE WIDTH
MODULATION (PWM)

10% duty cycle

50% duty cycle

90% duty cycle


CIRCUIT SCHEMATIC
The left side of the schematic is
almost the same as the previous
circuits. What’s changed?
DESIGN IT!
CREATE THE SKETCH
const int sensorPin=0;
const int ledPin=9;
int lightLevel, high=0, low=1023;
 
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
 
void loop() {
lightLevel = analogRead(sensorPin);
autoTune();
analogWrite(ledPin, lightLevel);
Serial.println(lightLevel);
}
CREATE THE SKETCH
void autoTune()
{
if(lightLevel<low)
{
low=lightLevel;
}
if(lightLevel>high)
{
high=lightLevel;
}
lightLevel=map(lightLevel, low+30, high-30, 0, 255);
lightLevel=constrain(lightLevel, 0, 255);
}
CIRCUIT #4:
TEMPERATURE SENSOR
Temperature sensors are used to measure
ambient temperature.

Sensor we’re using has three pins –


positive, ground, and a signal. For every
centigrade degree it reads, it outputs 10
millivolts.

We’ll integrate the temperature sensor with


Arduino and use the serial monitor to
display the temperature.
CIRCUIT SCHEMATIC
DESIGN IT!
CREATE THE SKETCH
const int temperaturePin = 0; float getVoltage(int pin)

void setup() { {
Serial.begin(9600);
return(analogRead(pin) * 0.004882814);
}
}
void loop() {
float voltage, degreesC, degreesF;

voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0;

degreesF = degreesC * (9.0/5.0) + 32.0;

Serial.print("voltage: ");
Serial.print(voltage);

Serial.print(" deg C: ");

Serial.print(degreesC);

Serial.print(" deg F: ");


Serial.println(degreesF);

delay(1000);
}
OUTPUT VOLTAGE VS.
TEMPERATURE FOR TMP36

http://
www.analog.com/
media/en/technical-
documentation/data-
sheets/
TMP35_36_37.pdf
CONGRATULATIONS!
You just learned about:
• Microcontroller basics
• Ohm’s Law
• Analog vs. digital signals
• Interpreting circuit schematics
• Designing circuits
• Basic coding
• Voltage dividers
• Pulse Width Modulation
• LEDs
• Three types of variable resistors
• How to use sensors and data sheets
WHERE TO GO
FROM HERE?
SPARKFUN

www.sparkfun.com
JEREMY BLUM
TUTORIAL SERIES

www.element14.com
ARDUINO WEBSITE
INSTRUCTABLES

You might also like