Download living with the lab - Louisiana Tech University

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Power electronics wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Rectiverter wikipedia , lookup

Crossbar switch wikipedia , lookup

Transcript
living with the lab
switches & whiskers on the Arduino
lever arm switches mounted to Arduino
© 2012 David Hall
living with the lab
DISCLAIMER & USAGE
The content of this presentation is for informational purposes only and is intended only for students
attending Louisiana Tech University.
The author of this information does not make any claims as to the validity or accuracy of the information
or methods presented.
Any procedures demonstrated here are potentially dangerous and could result in injury or damage.
Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are
not liable or responsible for any injuries, illness, damage or losses which may result from your using the
materials or ideas, or from your performing the experiments or procedures depicted in this presentation.
If you do not agree, then do not view this content.
The copyright label, the Louisiana Tech logo, and the “living with the lab” identifier should not be removed
from this presentation.
You may modify this work for your own purposes as long as attribution is clearly provided.
2
living with the lab
the switches
•
•
•
•
long lever with three electrical terminals
can be wired as normally open (electricity flows only when switch pressed)
can be wired as normally closed (electricity stops flowing when switch pressed)
used with 0.183 inch quick disconnect terminals
3
living with the lab
wiring
when the switch is not pressed, electricity can pass through the normally closed (NC) path
when the switch is pressed, electricity can pass through the normally open (NO) path
4
living with the lab
use a digital input to sense when switch is on or off
switch
AREF
GND
10kW
3 2 1 0 9 8
1 1 1 1
7 6 5 4 3 2 1 0
DIGITAL
RESET
3V3
POWER
5V Gnd Vin
ANALOG
check status of pin 7 using . . .
0 1 2 3 4 5
digitalRead(7)
switch
status
open
voltage
at pin 7
0V
(not pressed)
(no power applied)
closed
5V
(pressed)
(direct connection to power)
status of
digital input 7
LOW
HIGH
5
living with the lab
why the 10kΩ resistor?
using a large resistance limits the current so that we don’t waste electricity
switch
AREF
GND
10kW
3 2 1 0 9 8
1 1 1 1
7 6 5 4 3 2 1 0
DIGITAL
RESET
3V3
POWER
5V Gnd Vin
ANALOG
0 1 2 3 4 5
𝑉2
5𝑉 2
𝑃 =𝑉∙𝐼 =
=
= 0.0025W = 2.5mW
𝑅
10,000Ω
. . . any resistor will do, but there’s no sense in wasting power
6
living with the lab
hooking things up on your robot
•
space is tight, and it’s easy to break the quick disconnect terminals (can solder them if desired)
•
connect wires to the common and normally open terminals on the switch
7
living with the lab
tools
a wire stripper and some sort of crimping tool are needed (can also crudely crimp using a vise)
8
living with the lab
completing the circuit on the breadboard
white and red leads provide digital input
try to keep the wiring tidy . . .
•
•
one 10kΩ resistor per switch is installed
violet leads go to +5V source
to prevent wires from coming loose
to make it easier to see what’s going on (easier to troubleshoot)
9
living with the lab
programming
this program causes the built-in LED on pin 13 to turn on when the switch is pressed
int whisker1=0;
void setup(){
pinMode(7,INPUT);
pinMode(13,OUTPUT);
}
void loop(){
whisker1=digitalRead(7);
if(whisker1== HIGH)
{ digitalWrite(13,HIGH); }
else
{ digitalWrite(13,LOW); }
}
// whisker1==HIGH if whisker pressed
// turn LED on pin13 on
// turn LED on pin13 off
this is our first time to use if … else control (see next slide)
10
living with the lab
if / else
if/else allows greater control over the flow of code than the basic if statement, by allowing
multiple tests to be grouped together arduino.cc
if (x <
{
//
}
else if
{
//
}
else
{
//
}
500)
do Thing A
(x >= 1000)
do Thing B
can use an unlimited number of else if blocks
. . . or none, as in the program on the previous slide
do Thing C
11