SlideShare ist ein Scribd-Unternehmen logo
1 von 69
MICROCONTROLLERS &
ELECTRONICS BASICS
OR…
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
Arduino programming language.
Uses information from INPUTS to control various OUTPUTS.
www.arduino.cc
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.
5
4
3
8
2
6
7
9
1
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/s
oftware
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
V = IR
Voltage is measured in VOLTS (V)
Current is measured in AMPERES (A)
Resistance is measured in OHMS (Ω)
The LED above needs 20
mA (milliamps) of current.
What size resistor should
you use?
BREADBOARD
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
How it looks How it’s connected
JUMPER WIRE
330 Ω RESISTOR
10 KΩ RESISTOR
POTENTIOMETER
LIGHT EMITTING
DIODE (LED)
PHOTO RESISTOR
TEMPERATURE
SENSOR
ARDUINO PINS
ANALOG VS DIGITAL
SIGNALS
0V
5V
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.
Note: These components are all in series (one
after the other, like beads on a string).
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.
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, depending on the position of the knob. In this
way, it can be used as a “voltage divider”.
GND
Analog
Input
+5V
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
Arduino measures voltage, not
resistance. Need a voltage divider:
• Consists of two resistors.
• The “top” resistor is the sensor.
• The “bottom” resistor is a
normal, fixed resistor (usually 10
KΩ).
Top resistor
Bottom resistor
Resistor in disguise!
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;
void setup() {
Serial.begin(9600);
}
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);
}
float getVoltage(int pin)
{
return(analogRead(pin) * 0.004882814);
}
OUTPUT VOLTAGE VS.
TEMPERATURE FOR TMP36
http://www.analog.com/
media/en/technical-
documentation/data-
sheets/TMP35_36_37.p
df
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
QUESTIONS
Dr. Lauren Cooper
lcooper@mines.edu
Thank you for your
participation!

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt main
eddy royappa
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
Ahmed Sakr
 

Was ist angesagt? (20)

Arduino course
Arduino courseArduino course
Arduino course
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauriArduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
 
Arduino Introduction (Blinking LED) Presentation (workshop #5)
Arduino  Introduction (Blinking LED)  Presentation (workshop #5)Arduino  Introduction (Blinking LED)  Presentation (workshop #5)
Arduino Introduction (Blinking LED) Presentation (workshop #5)
 
Ardui no
Ardui no Ardui no
Ardui no
 
Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt main
 
arduino-ppt
 arduino-ppt arduino-ppt
arduino-ppt
 
Lesson sample introduction to arduino
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
 
ATMEGA 328
ATMEGA 328ATMEGA 328
ATMEGA 328
 
What is Arduino ?
What is Arduino ?What is Arduino ?
What is Arduino ?
 
Introduction of Arduino Uno
Introduction of Arduino UnoIntroduction of Arduino Uno
Introduction of Arduino Uno
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
Lab2ppt
Lab2pptLab2ppt
Lab2ppt
 
ARM Micro-controller
ARM Micro-controllerARM Micro-controller
ARM Micro-controller
 
ADC and DAC Best Ever Pers
ADC and DAC Best Ever PersADC and DAC Best Ever Pers
ADC and DAC Best Ever Pers
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
 
AVR ATmega32
AVR ATmega32AVR ATmega32
AVR ATmega32
 
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB) Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
 
Interfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the WorldInterfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the World
 

Ähnlich wie Arduino Workshop (3).pptx

Ähnlich wie Arduino Workshop (3).pptx (20)

Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
 
ATTiny Light Sculpture Project - Part I (Setup)
ATTiny Light Sculpture Project - Part I (Setup)ATTiny Light Sculpture Project - Part I (Setup)
ATTiny Light Sculpture Project - Part I (Setup)
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
Arduino programming
Arduino programmingArduino programming
Arduino programming
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote control
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
publish manual
publish manualpublish manual
publish manual
 
Basic arduino sketch example
Basic arduino sketch exampleBasic arduino sketch example
Basic arduino sketch example
 
Notes arduino workshop_15
Notes arduino workshop_15Notes arduino workshop_15
Notes arduino workshop_15
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.
 
Embedded systems presentation
Embedded systems presentationEmbedded systems presentation
Embedded systems presentation
 

Mehr von HebaEng

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
HebaEng
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptx
HebaEng
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
HebaEng
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptx
HebaEng
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
HebaEng
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
HebaEng
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
HebaEng
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
HebaEng
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
HebaEng
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
HebaEng
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
HebaEng
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptx
HebaEng
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptx
HebaEng
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
HebaEng
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
HebaEng
 

Mehr von HebaEng (20)

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptx
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptx
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
 
lecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).pptlecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).ppt
 
math6.pdf
math6.pdfmath6.pdf
math6.pdf
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
 
digital10.pdf
digital10.pdfdigital10.pdf
digital10.pdf
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
 
Instruction 3.pptx
Instruction 3.pptxInstruction 3.pptx
Instruction 3.pptx
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptx
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptx
 
VRAM & DEBUG.pptx
VRAM & DEBUG.pptxVRAM & DEBUG.pptx
VRAM & DEBUG.pptx
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 

Kürzlich hochgeladen

➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
amitlee9823
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
sriharipichandi
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
gajnagarg
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion pills in Kuwait Cytotec pills in Kuwait
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
amitlee9823
 
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
amitlee9823
 
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
gajnagarg
 

Kürzlich hochgeladen (20)

Sweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxSweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptx
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
 
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
Anupama Kundoo Cost Effective detailed ppt with plans and elevations with det...
 
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
 
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRLHingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
Hingoli ❤CALL GIRL 8617370543 ❤CALL GIRLS IN Hingoli ESCORT SERVICE❤CALL GIRL
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentation
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
 
The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahim
 
Hire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
Hire 💕 8617697112 Meerut Call Girls Service Call Girls AgencyHire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
Hire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
 
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfJordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
 
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
 
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
Just Call Vip call girls diu Escorts ☎️9352988975 Two shot with one girl (diu )
 

Arduino Workshop (3).pptx

  • 3. 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 Arduino programming language. Uses information from INPUTS to control various OUTPUTS. www.arduino.cc
  • 4. 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. 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.
  • 7. DOWNLOAD ARDUINO IDE (INTEGRATED DEVELOPMENT ENVIRONMENT) arduino.cc /en/main/s oftware
  • 15. KNOW THE ARDUINO GUI Verify: Compiles and approves your code. Will catch errors in syntax.
  • 16. KNOW THE ARDUINO GUI Upload: Sends your code to the RedBoard. When you click it you should see lights on your board blink rapidly.
  • 17. KNOW THE ARDUINO GUI New: Opens up a new code window tab.
  • 18. KNOW THE ARDUINO GUI Open: Open an existing sketch, which is where you write your code.
  • 19. KNOW THE ARDUINO GUI Save: Saves the currently open sketch.
  • 20. 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.
  • 21. KNOW THE ARDUINO GUI Sketch Name: Name of the sketch you are currently working on.
  • 22. KNOW THE ARDUINO GUI Code Area: Area where you compose the code for your sketch.
  • 23. KNOW THE ARDUINO GUI Message Area: Where the IDE tells you if there were any errors in your code.
  • 24. 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 V = IR Voltage is measured in VOLTS (V) Current is measured in AMPERES (A) Resistance is measured in OHMS (Ω) The LED above needs 20 mA (milliamps) of current. What size resistor should you use?
  • 25. BREADBOARD 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 How it looks How it’s connected
  • 34. ANALOG VS DIGITAL SIGNALS 0V 5V 5V 0V Learn more: https://www.youtube.com/watch?v=Z3rsO912e3I
  • 35. 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).
  • 36. 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
  • 37. 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.
  • 39. 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. Note: These components are all in series (one after the other, like beads on a string). 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.
  • 41.
  • 42. 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); }
  • 43. 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, depending on the position of the knob. In this way, it can be used as a “voltage divider”. GND Analog Input +5V
  • 44. 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.
  • 46.
  • 47. 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); }
  • 48. 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?!?
  • 49. RESISTIVE SENSORS & VOLTAGE DIVIDERS Arduino measures voltage, not resistance. Need a voltage divider: • Consists of two resistors. • The “top” resistor is the sensor. • The “bottom” resistor is a normal, fixed resistor (usually 10 KΩ). Top resistor Bottom resistor Resistor in disguise! 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.
  • 50. 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)
  • 51. PULSE WIDTH MODULATION (PWM) 10% duty cycle 50% duty cycle 90% duty cycle
  • 52. CIRCUIT SCHEMATIC The left side of the schematic is almost the same as the previous circuits. What’s changed?
  • 54.
  • 55. 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); }
  • 56. 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); }
  • 57. 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.
  • 60.
  • 61. CREATE THE SKETCH const int temperaturePin = 0; void setup() { Serial.begin(9600); } 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); } float getVoltage(int pin) { return(analogRead(pin) * 0.004882814); }
  • 62. OUTPUT VOLTAGE VS. TEMPERATURE FOR TMP36 http://www.analog.com/ media/en/technical- documentation/data- sheets/TMP35_36_37.p df
  • 63. 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

Hinweis der Redaktion

  1. Answer: 450 ohms
  2. The five analog pins are used ONLY to input analog signals, which can take on a continuous range of values. These signals can vary between 0V and 5V. The 13 digital pins are used to input OR output digital signals, which are either “on” or “off”. These signals will always be 5V (which we call “high”) or 0V (which we call “low”). The Arduino has an analog-to-digital converter (ADC), which allows it to convert analog signals (such as temperature or light, which can take on a continuous range of values) into digital signals (such as blinking a light, which is either ON or OFF). The Arduino, however, does not have a digital-to-analog converter. When you are writing your Arduino code, you have to specify whether the digital pins are either being used as input or output pins. You do not have to specify how the analog pins are being used because they can only be input pins. In this workshop we will also use the pins for power (5V) and ground.
  3. An analog signal is a signal that can have a huge range of values. These values are continuous, like a sine wave. If you’re using a microcontroller that has a “logic level” of 5V, it has a base voltage of 0 (ground) and a maximum voltage of 5V. With this logic level, an analog signal can vary anywhere between these two levels. Most things we deal with in the real world are analog. Consider a light sensor that is used to measure the intensity of sunlight. When configured in a “voltage divider circuit” (more on this later), the amount of sunlight that shines on the light sensor will change the voltage across the light resistor. No light might correspond to a 0V signal. Partial shade might correspond to a 2.5 V signal, and full light might correspond to a 5V signal. And there are many many values in between. It’s a CONTINUOUS SIGNAL. Digital signals are different. They have one of two values – either HIGH or LOW. The way we often seen this represented is as a 1 or a 0. 1 representing HIGH or ON, and 0 representing LOW or OFF. So if we’re talking about the same 5V microcontroller that we were before, when we get a voltage close to 5, it corresponds to a 1, and when we get a voltage close to 0 it corresponds to a 0. An example in real life is just a simple light switch. When we close the switch, electricity from the battery will flow through and turn the light bulb on. A microcontroller would measure that as a 1 because it’s seeing the full voltage. If the switch is open it would register that as a 0.
  4. Since most everything in the world is analog, how do we convert between the two? How do we take an analog signal and convert it to a digital signal? That’s done with analog-to-digital converters. Let’s say we have that analog signal from the light sensor coming into our system, which ranges from 0V – 5V. So now we need to convert that to a digital signal because that’s what our Arduino needs in order to process it. What our digital signal looks like is going to depend on the resolution of the analog to digital converter (ADC) in our system. Basically our system’s resolution is based on the number of bits. If we have a 10 bit ADC, that’s going to be 2^10 bits because 2 is the number of options we have (0 or 1). That equals 1,024. So a 10-bit system is going to have 1024 bits of resolution. Generally we see 0 to 1023 because 0 registers as 0V. This is really important because when we use the “serial monitor” in Arduino to read the voltage from the analog input pins, we’ll read values between 0 and 1,023. So keep this in the back of your head as we move forward. So - a 10 bit system will break our analog signal into 10 different horizontal steps. As the figure on the slide shows, a 3-bit system will break the analog signal into 3 bits, which we can easily see. With a 16-bit system, it’s hard to see the different steps, and the signal looks a whole lot smoother.
  5. Notes: // Is how you make single-line comments in the sketch. /* is how you make multi-line comments. Make sure the end of your comment ends with */ Notice the two functions setup() and loop (). All sketches must have these functions, which will run automatically when the sketch is uploaded. The setup() function runs only once when the sketch starts and is used for things you need to do first, or only once. In this case we are setting digital pin 13 to be an output, which means that it will output 0V and 5V (which will turn the LED off and on). After setup() finishes, the loop() functions runs over and over until you turn off or reset your Arduino. This is where the bulk of your sketch will be. Here, this is where we will write the code to make the LED blink on and off. Since we have an LED connected to pin 13, if we make the output HIGH, the LED will get voltage and light up. If we make the output LOW, the LED will have no voltage and will turn off. We use the function digitalWrite() to do this. It takes two values – a pin number followed by the word HIGH or LOW. To make the LED show a blinking pattern, we have to use a delay so the LED stays on and off for a certain amount of time. We use the function delay() which takes one input – milliseconds. So delay(1000) would cause the program to pause for one second. Experiment: 1. Make the LED blink more rapidly. Then more slowly. 2. Make a blinking pattern like short, short, long. 3. Determine how rapidly the LED has to blink for our eyes to perceive the LED as staying on (not blinking).
  6. This example shows you how to read analog input from the physical world using a potentiometer. We will use the potentiometer to control how fast an LED blinks. We’ll also start using “variables”, which are used to store numbers that change, such as measurements from the outside world. A potentiometer (“pot”, for short) is a simple mechanical device that changes resistance when the knob is turned. Hence, it’s called a “variable resistor.” Basically it’s a control knob, like the ones you use to adjust the volume on your speakers or dim a lamp. When it’s connected with 5V across its two outer pins, the middle pin outputs a voltage between 0 and 5V, depending on the position of the knob. In this way, it can be used as a “voltage divider”. The change in voltage level is used to control the blink rate of the LED. We will read these voltage changes in the pot using the serial monitor.
  7. In this sketch we’ll start to use variables to name and store numbers that change. In this case the changing number is the analog input from the potentiometer. Variables can be different data types such as integers, boolean, etc. See http://arduino.cc/en/Reference/VariableDeclaration. Integers, which we are using here, are whole numbers that can be negative. If you declare variables outside of a function, they are called “global variables” and can be seen by all the functions. In general, you want to limit the scope of the variables, but in this case global variables are fine. Variables must be “declared” before you can use them. In this sketch we are declaring three integer variables, sensorPin, ledPin, and sensorValue. The variable sensorPin will be used to refer to analog input pin 0. The variable ledPin will be used to refer to digital pin 13. Sometimes it’s easier to follow a sketch if we use variable names instead of just numbers, so we often name the pins we are using. The variable sensorValue will be used to store values from analog input pin 0. You might notice in the setup() function that we are setting the digital pin named ledPin to an OUTPUT, but we aren’t setting the analog pin named sensorPin to anything. Why is this? This is because Arduino’s digital pins can be either input or output signals, but the analog pins can only input signals. In other words, an Arduino can interpret (input) analog information like the turning of a knob, but it can’t control that knob to turn (output) in the same continuous way. You’ll also notice in the setup() function that we declared a function Serial.begin(9600). This just sets the data rate in bits per second (baud) for serial communication. We do this because we’re going to watch the serial monitor to see how values change when the pot knob is turned. In the loop() function we call another function Serial.println(sensorValue) to print the values on the serial monitor as text we can read. In this case, it will print the values that correspond to the voltage of the potentiometer. Question: what is the range going to be on the serial monitor? Remember what we talked about with analog and digital values. We could also use Serial.println() to print the values for the ledPin. What is the range going to be in this case? Play with turning the knob as you watch what’s happening on the serial monitor. Do you see how when the knob is turned all the way to the left, the value on the serial monitor is 0? That corresponds to a voltage of 0. Do you see how when the knob is turned all the way to the right, the value on the serial monitor is 1023? That corresponds to a voltage of 5V. And then there are many values in between. So, you can see how a potentiometer is used as a voltage divider because it simply divides a given voltage. So what’s happening in the loop() function? The variable sensorValue is storing the voltage values (from 0 to 1023) from the pot, which vary as the knob is turned. The knob all the way to the left is 0V, and the knob all the way to the right is 5V (1023). The LED blinks for the same amount of time as the sensorValue. So, if the knob is all the way turned to the left, the LED doesn’t actually blink because the delay is 0. If the knob is turned all the way to the right, the LED blinks and pauses for 1023 milliseconds, or about one second. Experiment: Now, is this what you’d expect, or does the knob feel a little “backward” to you? How do you need to reconfigure either the pot or the code so that as you turn the knob from left to right the LED blinks more rapidly?
  8. We’ve already played with a potentiometer, which varies resistance based on the twisting of a knob. Here we’ll be using a photo resistor, which changes resistance based on how much light the sensor receives. Arduino’s analog input pins can’t directly measure resistance (rather, they read voltage), but we can measure voltage changes by building a voltage divider with the photoresistor. The voltage divider will output a high voltage when it’s getting a lot of light and a low voltage when it’s not, and a variety of values in between. We’ll use this information about the voltage change across the photo resistor to brighten and dim and LED based on the light level picked up by the sensor. So, in this case we’re using a digital signal to control an analog output. But Arduino doesn’t have a digital-to-analog converter. We’ll have to use a trick!
  9. Many of the sensors you’ll use (like potentiometers, photoresistors, and temperature sensors, to name a few) are “resistors in disguise.” Their resistance changes in proportion to whatever they’re sensing. As we discussed before, Arduino’s analog input pins measure voltage, not resistance, But we can use resistive sensors to measure voltage changes by building a voltage divider. A voltage divider consists of two resistor. The “top” resistor is the sensor you’re using (like a photoresistor or temperature sensor). The bottom resistor is a normal, fixed resistor (usually 10 k-ohms). When the top resistor is connected to power and the bottom resistor is connected to ground, the middle of the voltage divider will output a voltage that is proportional to the values of the two resistors.
  10. So back to our issue with wanting to convert digital to analog. In this case we want to use the digital signal from our Arduino to change the brightness of an LED. So, we need to be outputting some varying voltage level. But our Arduino isn’t built for that. We employ a trick called pulse width modulation (PWM). Because the Arduino is so fast, it can blink a pin on and off almost 1,000 times per second. Certain Arduino pins (those that can do PWM, indicated with a ~ next to them) go one step further by varying the amount of time the blinking pin spends HIGH vs. LOW. If it spends most of its time HIGH, a LED connected to that pin will appear bright. If it spends most of its time on LOW, the LED will look dim. Because the pin is blinking much faster than your eye can detect, the Arduino creates the illusion of a true analog output. We use the function analogWrite() to do PWM. The first argument is the pin, and the second is the duty cycle (see next slide).
  11. On the left side of the circuit schematic, the positive lead of the LED has been moved to Pin 9 (previously it was connected to Pin 13). This is because Pin 9 does PWM.
  12. So, where do you think the formula for degrees C came from? The specification sheet for the temperature sensor, of course! See next slide.
  13. Look at line b, which corresponds to TMP36 (the version of the temperature sensor we are using). At 100˚C, the output voltage is about 1.5 V. Using this point of information, we can write a function for degrees C as a function of output voltage: Degrees C = (Output voltage – 0.5) * 100. From the spec sheet, it looks like this function will hold true for any temperature from -50˚C to 125˚C.