Microcontrollers & Electronics Basics OR : Pimp My Project
Microcontrollers & Electronics Basics OR : Pimp My Project
ELECTRONICS BASICS
OR…
I CS
EP ∨
PIMP MY
PROJECT
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.
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/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.
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
210 = 1,024
0 255
CIRCUIT #1:
BLINKING AN LED
LEDs (light emitting
diodes) are small, powerful
lights used in many
different applications.
We’re adding a
potentiometer to
control the blink rate
of the LED.
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
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!
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;
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(degreesC);
delay(1000);
}
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