User Tools

Site Tools


tutorials:learn:sensors:ir.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:learn:sensors:ir.html [2010/10/07 20:12]
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 8: Line 8:
  
  
-There are a few difference between these and say a [[cds.html|CdS Photocells]]:​ \\ +There are a few difference between these and say a [[http://​www.ladyada.net/​learn/​sensors/​cds.html|CdS Photocells]]:​ \\ 
  
  
-  *IR detectors are specially filtered for Infrared light, they are not good at detecting visible light. On the other hand, [[cds.html|cds]] ​photocells are good at detecting yellow/​green visible light, not good at IR light+  *IR detectors are specially filtered for Infrared light, they are not good at detecting visible light. On the other hand, photocells are good at detecting yellow/​green visible light, not good at IR light
   *IR detectors have a **demodulator** inside that looks for modulated IR at 38 KHz. Just shining an IR LED wont be detected, it has to be PWM blinking at 38KHz. Photocells do not have any sort of demodulator and can detect any frequency (including DC) within the response speed of the photocell (which is about 1KHz)   *IR detectors have a **demodulator** inside that looks for modulated IR at 38 KHz. Just shining an IR LED wont be detected, it has to be PWM blinking at 38KHz. Photocells do not have any sort of demodulator and can detect any frequency (including DC) within the response speed of the photocell (which is about 1KHz)
   *IR detectors are digital out - either they detect 38KHz IR signal and output low (0V) or they do not detect any and output high (5V). Photocells act like resistors, the resistance changes depending on how much light they are exposed to   *IR detectors are digital out - either they detect 38KHz IR signal and output low (0V) or they do not detect any and output high (5V). Photocells act like resistors, the resistance changes depending on how much light they are exposed to
Line 18: Line 18:
  
  
-  *[[#test|Test your IR sensor to make sure its working]] +  *[[#testing_your_ir_detector|Test your IR sensor to make sure its working]] 
-  *[[#rawir|Read raw IR codes into a microcontroller]] +  *[[#ir_remote_signals|Read raw IR codes into a microcontroller]] 
-  *[[#intervalometer|Create a camera intervalometer]] +  *[[#making_an_intervalometer|Create a camera intervalometer]] 
-  *[[#ircommand|Listen for '​commands'​ from a remote control on your microcontroller]] ​+  *[[#reading_ir_commands|Listen for '​commands'​ from a remote control on your microcontroller]] ​ 
 ==== Some stats  ==== ==== Some stats  ====
  
Line 149: 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 197: 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 277: 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 319: 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 338: 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 364: 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 393: 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 ​ |}}]]
Line 447: Line 448:
 I uploaded the new sketch and pressed the **Play** button on the Apple remote and got the following: I uploaded the new sketch and pressed the **Play** button on the Apple remote and got the following:
  
-<p class="​codefragment"​>int IRsignal[] = { \\ // ON, OFF (in 10's of microseconds) ​\\ 912, 438, \\ 68, 48, \\ 68, 158, \\ 68, 158, \\ 68, 158, \\ 68, 48, \\ 68, 158, \\ 68, 158, \\ 68, 158, \\ 70, 156, \\ 70, 158, \\ 68, 158, \\ 68, 48, \\ 68, 46, \\ 70, 46, \\ 68, 46, \\ 68, 160, \\ 68, 158, \\ 70, 46, \\ 68, 158, \\ 68, 46, \\ 70, 46, \\ 68, 48, \\ 68, 46, \\ 68, 48, \\ 66, 48, \\ 68, 48, \\ 66, 160, \\ 66, 50, \\ 66, 160, \\ 66, 52, \\ 64, 160, \\ 66, 48, \\ 66, 3950, \\ 908, 214, \\ 66, 3012, \\ 908, 212, \\ 68, 0};+<code> 
 +int IRsignal[] = { // ON, OFF (in 10's of microseconds) ​ 
 +912, 438,  
 +68, 48,  
 +68, 158,  
 +68, 158,  
 +68, 158,  
 +68, 48,  
 +68, 158,   
 +68, 158,   
 +68, 158,   
 +70, 156,   
 +70, 158,   
 +68, 158,   
 +68, 48,  
 +68, 46,   
 +70, 46,   
 +68, 46,   
 +68, 160,   
 +68, 158,   
 +70, 46,   
 +68, 158,   
 +68, 46,   
 +70, 46, 
 +68, 48,   
 +68, 46,   
 +68, 48,   
 +66, 48,   
 +68, 48,   
 +66, 160,   
 +66, 50,   
 +66, 160,   
 +66, 52,   
 +64, 160,  
 +66, 48,   
 +66, 3950,   
 +908, 214,  
 +66, 3012,  
 +908, 212,  
 +68, 0}; 
 +</​code>​ 
  
  
/home/ladyada/public_html/wiki/data/attic/tutorials/learn/sensors/ir.html.1286482346.txt.gz · Last modified: 2016/01/28 18:05 (external edit)