Title: Week 10 Today
1Week 10Today
- Homework presentations and critique.
- Review digital and analog inputs.
- DIY - jumpers, soldering etc.
2Homework
- Those who did not show last week show
- Pushbutton and LED
- Light sensor and LED
- Serial input to Arduino software
- Either Knight Rider or Shooting Star
- Potentiometer
- New version of above with a control structure
(below) - This weeks assignments
- Multiple switch assignment - make a project that
uses at least 2 for interesting outputs. - Create project with two HOMEMADE switches.
- Create a cool creative piece using at least one
photocell and one other sensor and two LEDs or
other outputs. This should be more than just some
lights on your board, it should feel more
finished - like the eyes project. As a class
well crit and vote on the best ones - theyll
get an extra credit mark.Criteria creativity,
function, ability to explain code, clarity of
codeTHIS ONE MUST BE LIVE AND WORKING IN CLASS.
3 4Arduino Sketch Structure
- Top of sketch
- Declare variables at top
- Initialize
- setup() run once at beginning, set pins
- Running
- loop() run repeatedly, after setup()
- Pins can be changed in loop() too, but
conceptually easier in setup()
5Arduino Programming
6Arduino Programming
Known Good Configuration Rule 1 of
experimenting Before trying anything new, Get
back to a known working state Get your entire
edit-gtcompile-gtupload-gtrun working Even if it
becomes so second nature to you that you feel you
shouldnt need to, do it anyway. Especially when
mysterious problems arise, revert to a known state
7Digital Input
Switches make or break a connection Most inputs
youll use are variations on switches Fundamentall
y, theyre all like the simple knife switch
Knife Switch
Toggle Switch
8Digital Input
Switches make or break a connection But Arduino
wants to see a voltage Specifically, a HIGH (5
volts) or a LOW (0 volts)
9Analog Inputs
Many states, not just two (HIGH/LOW) Arduino has
six ADC inputs (ADC Analog to Digital
Converter) Reads voltage between 0 to 5 volts
Resolution is 10-bit (1024 states) You used
this for the Potentiometer Homework exercise
10An Analog Sensor
Photocell, photoresistor, light-dependent
resistor A variable resistor ANALOG Brighter
light lower resistance Photocells have range
approx. 0-10k schematic symbol
11Reading Diagrams
Analog Sensor w/o Arduino shown Power Photocell C
ommon Join Arduino pin (Analog pin
0) Resistor Ground
12Reading Diagrams
Switch w/Arduino Power LED Arduino pin (Digital
pins) Ground Resistor Switch
13 14Do It Yourself!
The exciting part of all this is that you can
make almost anything. If you are careful,
thoughtful, and test, retest, and document your
work.
15Doing It Yourself
Making Jumper Wires strip off about 1/2 of
insulation Can use wire strippers, cutters, or
fingers Can be a pain.. so often use pre-cut
wires to save time but they do cost more.
16Doing It Yourself
The End Result ready to go in the Breadboard
17Doing It Yourself
- Soldering
- Permanent connections
- When inputs and outputs need to be further away
from the breadboard - Demonstration
- Be careful not to overheat
- Watch for good connections
- Protect solder joints with hot glue when they are
likely to be delicate or subject to stress - Ventilation is good if you are doing a lot of it
18Talking to the computer
Communicating with Others Arduino can use same
USB cable for programming and to talk with
computers Talking to other devices uses the
Serial commands Serial.begin() prepare to
use serial Serial.print() send data to
computer Serial.read() read data from
computer Can talk to not just computers. Most
things more complex than simple sensors/actuators
speak serial.
19Talking to the computer
Watch the TX/RX LEDS TX sending to PC RX
receiving from PC Used when programming or
communicating
20Talking to the computer
- serial_hello_world
- Send Hello world! to your computer (and blink
LED) - Click on Serial Monitor to see output
- Watch TX LED compared to pin13 LED
- Assgn 1
- Do this. Get it working and save it.
21Telling Arduino what to do
serial_read_basic (get from examples) In
Serial Monitor type H, press Send Watch pin
13 LED blink once Notice how you might not always
read something, thus the -1 check. Assign
2 Modify to print hello world after it
receives something, but before it checks for
H. This way you can verify its actually
receiving something.
22Cool! Now what?
Now its your turn! Assgn 3 Add other outputs
onto your board. Use different key commands to
trigger them. Assgn 4 Get data in from an
analog sensor and print it out in at least 3
formats. (hint http//www.arduino.cc/en/Serial/Pr
intln) Assgn 5 Add other responses on the
screen and have different sensors trigger them.
23Homework
- Complete and post your work (description of
project, photo of it, plus code) - Assgn 1
- Get basic serial communication working.
- Assgn 2
- Modify to print hello world after it receives
something, but before it checks for H. This way
you can verify its actually receiving something.
- Assgn 3
- Add other outputs onto your board. Use different
key commands to trigger them. - Assgn 4
- Get data in from an analog sensor and print it
out in at least 3 formats. (hint
http//www.arduino.cc/en/Serial/Println) - Assgn 5
- Add other responses on the screen and have
different sensors trigger them.