This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorials:learn:sensors:ir.html [2010/10/07 20:27] daigo |
tutorials:learn:sensors:ir.html [2016/01/28 18:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
==== ==== | ==== ==== | ||
- | [[http://www.ladyada.net/learn/../make/logshield/Documents/ladyada_net-www/ladyada_net-www/images/sensors/pna4602.jpg|{{ http://www.ladyada.net/images/sensors/pna4602_t.jpg?nolink&500x385 |}}]] | + | [[http://www.ladyada.net/images/sensors/pna4602.jpg|{{ http://www.ladyada.net/images/sensors/pna4602_t.jpg?nolink&500x385 |}}]] |
==== What is an IR detection sensor? ==== | ==== What is an IR detection sensor? ==== | ||
Line 150: | Line 150: | ||
{{ http://www.ladyada.net/images/sensors/arduinopna4602.gif?nolink&618x416 |}} | {{ http://www.ladyada.net/images/sensors/arduinopna4602.gif?nolink&618x416 |}} | ||
- | The good news is that it is very easy to hook up this sensor. Just connect the output to a digital pin. The bad news is that the Arduino's friendly **digitalRead()** procedure is a tad too slow to reliably read the fast signal as its coming in. Thus we use the hardware pin reading function directly from pin D2, thats what the line IRpin_PIN & (1 << IRpin)does. | + | The good news is that it is very easy to hook up this sensor. Just connect the output to a digital pin. The bad news is that the Arduino's friendly **digitalRead()** procedure is a tad too slow to reliably read the fast signal as its coming in. Thus we use the hardware pin reading function directly from pin D2, thats what the line "IRpin_PIN & BV(IRpin))" does. |
[[http://github.com/adafruit/Raw-IR-decoder-for-Arduino|You can also get the latest version of this code on github]]<code C> | [[http://github.com/adafruit/Raw-IR-decoder-for-Arduino|You can also get the latest version of this code on github]]<code C> | ||
Line 198: | Line 198: | ||
| | ||
// while (digitalRead(IRpin)) { // this is too slow! | // while (digitalRead(IRpin)) { // this is too slow! | ||
- | while (IRpin_PIN & (1 << IRpin)) { | + | while (IRpin_PIN & _BV(IRpin)) { |
// pin is still HIGH | // pin is still HIGH | ||
Line 278: | Line 278: | ||
- | OK step one is easy, point the remote control at the IR sensor and press the button, we got the following for our ML-L3 Canon remote | + | OK step one is easy, point the remote control at the IR sensor and press the button, we got the following for our ML-L3 Nikon remote |
{{ http://www.ladyada.net/images/sensors/canonirread.gif?nolink&385x307 |}} | {{ http://www.ladyada.net/images/sensors/canonirread.gif?nolink&385x307 |}} | ||
Line 320: | Line 320: | ||
<code C> | <code C> | ||
- | // This sketch will send out a canon D50 trigger signal (probably works with most canons) | + | // This sketch will send out a Nikon D50 trigger signal (probably works with most Nikons) |
// See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html | // See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html | ||
// this code is public domain, please enjoy! | // this code is public domain, please enjoy! | ||
Line 339: | Line 339: | ||
Serial.println("Sending IR signal"); | Serial.println("Sending IR signal"); | ||
| | ||
- | SendCanonCode(); | + | SendNikonCode(); |
delay(60*1000); // wait one minute (60 seconds * 1000 milliseconds) | delay(60*1000); // wait one minute (60 seconds * 1000 milliseconds) | ||
Line 365: | Line 365: | ||
} | } | ||
- | void SendCanonCode() { | + | void SendNikonCode() { |
- | // This is the code for my particular Canon, for others use the tutorial | + | // This is the code for my particular Nikon, for others use the tutorial |
// to 'grab' the proper code from the remote | // to 'grab' the proper code from the remote | ||
| | ||
Line 394: | Line 394: | ||
- | If you look at SendCanonCode() you will see the IR command code that we deduced in the previous project by timing the pulses from the IR sensor. | + | If you look at SendNikonCode() you will see the IR command code that we deduced in the previous project by timing the pulses from the IR sensor. |
[[http://www.ladyada.net/images/sensors/intervalometer.jpg|{{ http://www.ladyada.net/images/sensors/intervalometer_t.jpg?nolink&500x463 |}}]] | [[http://www.ladyada.net/images/sensors/intervalometer.jpg|{{ http://www.ladyada.net/images/sensors/intervalometer_t.jpg?nolink&500x463 |}}]] |