This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorials:learn:arduino:lesson5.html [2010/10/22 14:58] daigo |
tutorials:learn:arduino:lesson5.html [2016/01/28 18:05] (current) |
||
---|---|---|---|
Line 142: | Line 142: | ||
[[http://www.ladyada.net/images/arduino/tiehigh.jpg|{{ http://www.ladyada.net/images/arduino/tiehigh_t.jpg?nolink&500x306 |}}]] | [[http://www.ladyada.net/images/arduino/tiehigh.jpg|{{ http://www.ladyada.net/images/arduino/tiehigh_t.jpg?nolink&500x306 |}}]] | ||
- | <class center>//Switch input tied HIGH (5v) // | + | <class center>//Switch input tied HIGH (5v) //</class> |
[[http://www.ladyada.net/images/arduino/tielow.jpg|{{ http://www.ladyada.net/images/arduino/tielow_t.jpg?nolink&500x307 |}}]] | [[http://www.ladyada.net/images/arduino/tielow.jpg|{{ http://www.ladyada.net/images/arduino/tielow_t.jpg?nolink&500x307 |}}]] | ||
- | <class center>//Switch input tied LOW (ground) //</class> | + | <class center> //Switch input tied LOW (ground) //</class> |
Line 172: | Line 172: | ||
^{{ http://www.ladyada.net/images/arduino/nopulldown.png?nolink&184x227 |}}^{{ http://www.ladyada.net/images/arduino/nopullup.png?nolink&184x197 |}}^ | ^{{ http://www.ladyada.net/images/arduino/nopulldown.png?nolink&184x227 |}}^{{ http://www.ladyada.net/images/arduino/nopullup.png?nolink&184x197 |}}^ | ||
- | //Fig 5.3Our two alternative switch wiring possibilities //For example, in these schematics we can connect and disconnect **pin 2** to 5V, or we can connect and disconnect **pin 2** to ground. In both cases, as long as the button is held down, the pin is connected to a **valid input ** voltage. When the button is released, though, **pin 2** is not connected to //anything//. This is called a **floating input** voltage. Basically, it's invalid input! | + | <class center>//Fig 5.3Our two alternative switch wiring possibilities //</class> |
+ | For example, in these schematics we can connect and disconnect **pin 2** to 5V, or we can connect and disconnect **pin 2** to ground. In both cases, as long as the button is held down, the pin is connected to a **valid input ** voltage. When the button is released, though, **pin 2** is not connected to //anything//. This is called a **floating input** voltage. Basically, it's invalid input! | ||
Try building up one of these schematics, and trying out the switch testing sketch above. When the button is held down you should definately get the right printout. When its released, it may keep the old value, or it may change, but its certainly not reliable! | Try building up one of these schematics, and trying out the switch testing sketch above. When the button is held down you should definately get the right printout. When its released, it may keep the old value, or it may change, but its certainly not reliable! | ||
- | [[http://www.ladyada.net/images/arduino/testswitchnopulldown.jpg|{{ http://www.ladyada.net/images/arduino/testswitchnopulldown_t.jpg?nolink&500x311 |}}]] \\ //Wiring when the switch is connected to 5V // | + | [[http://www.ladyada.net/images/arduino/testswitchnopulldown.jpg|{{ http://www.ladyada.net/images/arduino/testswitchnopulldown_t.jpg?nolink&500x311 |}}]] |
+ | <class center> //Wiring when the switch is connected to 5V //</class> | ||
- | [[http://www.ladyada.net/images/arduino/testswitchnopullup.jpg|{{ http://www.ladyada.net/images/arduino/testswitchnopullup_t.jpg?nolink&500x305 |}}]] \\ //Wiring when switch is connected to ground// | + | [[http://www.ladyada.net/images/arduino/testswitchnopullup.jpg|{{ http://www.ladyada.net/images/arduino/testswitchnopullup_t.jpg?nolink&500x305 |}}]] |
+ | <class center> //Wiring when switch is connected to ground//</class> | ||
One solution is to get a switch that alternates connections, like this one, diagrammed here. | One solution is to get a switch that alternates connections, like this one, diagrammed here. | ||
- | {{ http://www.ladyada.net/images/arduino/simplespdt.png?nolink&200x242 |}} \\ //Fig 5.4// | + | {{ http://www.ladyada.net/images/arduino/simplespdt.png?nolink&200x242 |}} |
+ | <class center>//Fig 5.4//</class> | ||
The problem is, these switches are suprisingly complex and 10 times more expensive than a little tactile button! Instead we use a trick called a **pull-down** resistor. | The problem is, these switches are suprisingly complex and 10 times more expensive than a little tactile button! Instead we use a trick called a **pull-down** resistor. | ||
- | {{ http://www.ladyada.net/images/arduino/pulldown.png?nolink&155x302 |}} \\ //Fig 5.5 // | + | {{ http://www.ladyada.net/images/arduino/pulldown.png?nolink&155x302 |}} |
+ | <class center>//Fig 5.5 //</class> | ||
The pull-down resistor here is the 10K resistor. When the switch is held down, the 100Ω resistor is connected directly to 5V. When the switch is released, the 100Ω resistor is connected to the 10K resistor which **pulls it down** to ground. | The pull-down resistor here is the 10K resistor. When the switch is held down, the 100Ω resistor is connected directly to 5V. When the switch is released, the 100Ω resistor is connected to the 10K resistor which **pulls it down** to ground. | ||
Line 200: | Line 205: | ||
You can also use the switch to connect the input to ground, and use a resistor as a **pull-up** resistor. | You can also use the switch to connect the input to ground, and use a resistor as a **pull-up** resistor. | ||
- | {{ http://www.ladyada.net/images/arduino/pullup.png?nolink&155x302 |}} \\ //Fig 5.6// | + | {{ http://www.ladyada.net/images/arduino/pullup.png?nolink&155x302 |}} |
+ | <class center> //Fig 5.6// </class> | ||
Try this schematic as well, and verify for yourself that the button is now reliable. | Try this schematic as well, and verify for yourself that the button is now reliable. | ||
Line 228: | Line 234: | ||
- | Here is a small part of the Arduino schematic, [[http://www.arduino.cc/en/uploads/Main/Arduino-Diecimila-schematic.pdf|(you can see the whole thing here)]][[http://www.arduino.cc/en/uploads/Main/Arduino-Diecimila-schematic.pdf|{{ http://www.ladyada.net/images/arduino/arduinoresetschem.jpg?nolink&242x285 |}}]] \\ //Fig 5.7// | + | Here is a small part of the Arduino schematic, [[http://www.arduino.cc/en/uploads/Main/Arduino-Diecimila-schematic.pdf|(you can see the whole thing here)]][[http://www.arduino.cc/en/uploads/Main/Arduino-Diecimila-schematic.pdf|{{ http://www.ladyada.net/images/arduino/arduinoresetschem.jpg?nolink&242x285 |}}]] |
+ | <class center> //Fig 5.7// </class> | ||
There is a switch and a resistor (Europeans use a rectangle instead of a squiggly for resistors), they are both connected to a pin on the Arduino microcontroller called RESET (in the bottom right corner) | There is a switch and a resistor (Europeans use a rectangle instead of a squiggly for resistors), they are both connected to a pin on the Arduino microcontroller called RESET (in the bottom right corner) | ||
Line 253: | Line 260: | ||
Here is how we will wire up the switch and LED. | Here is how we will wire up the switch and LED. | ||
- | {{ http://www.ladyada.net/images/arduino/digitallight.png?nolink&289x272 |}} \\ Fig 5.8 | + | {{ http://www.ladyada.net/images/arduino/digitallight.png?nolink&289x272 |}} |
+ | <class center>Fig 5.8 </class> | ||
Build this schematic on your protoshield | Build this schematic on your protoshield | ||
Line 340: | Line 348: | ||
**Now its your turn:** add another red LED and resistor to pin 11, modify the sketch so that when the button is pressed one LED is lit and the other one is off and when the button is released the first LED is off and the second LED is lit. | **Now its your turn:** add another red LED and resistor to pin 11, modify the sketch so that when the button is pressed one LED is lit and the other one is off and when the button is released the first LED is off and the second LED is lit. | ||
- | {{ http://www.ladyada.net/images/arduino/2ledswitch.png?nolink&409x272 |}} \\ //Fig 5.9// | + | {{ http://www.ladyada.net/images/arduino/2ledswitch.png?nolink&409x272 |}} |
+ | <class center>//Fig 5.9//</class> | ||
Try to wire up the protoshield just from the schematic. If you're having trouble, [[http://www.ladyada.net/images/arduino/2ledswitch.jpg|click here for a photo of the parts wired up]]. | Try to wire up the protoshield just from the schematic. If you're having trouble, [[http://www.ladyada.net/images/arduino/2ledswitch.jpg|click here for a photo of the parts wired up]]. |