This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:sensor:ir_passive [2015/12/17 08:46] – kaupo.raid | en:examples:sensor:ir_passive [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ~~PB~~ | + | < |
| ====== Passive infrared sensor (PIR) ====== | ====== Passive infrared sensor (PIR) ====== | ||
| - | //Vajalikud teadmised: | + | //Necessary knowledge: |
| - | [HW] [[et: | + | [HW] [[en: |
| - | [AVR] [[et:avr:io]], | + | [AVR] [[en:avr:io]], |
| - | [LIB] [[et: | + | [LIB] [[en: |
| ===== Theory ===== | ===== Theory ===== | ||
| [{{ : | [{{ : | ||
| - | Passive infrared sensor measures infrared (IR) radiation from objects in it's field of view. All objects emit some low level of radiation. The hotter something is the more radiation is emitted. Human eye is not capable to see IR radiation, but it's possible to use special cameras and sensors to detect it. | + | Passive infrared sensor measures infrared (IR) radiation from objects in it's field of view. All objects emit some low level radiation. The hotter something is the more radiation is emitted. Human eye is not capable to see IR radiation, but it's possible to use special cameras and sensors to detect it. |
| - | The sensor is called passive | + | The sensor is called passive |
| PIR sensor is mostly used for detecting living being movement and thus is generally known as passive infrared detector (PID). The sensor is also sensitive enough to even detect IR radiation source movement while the object is already in it's field of view. | PIR sensor is mostly used for detecting living being movement and thus is generally known as passive infrared detector (PID). The sensor is also sensitive enough to even detect IR radiation source movement while the object is already in it's field of view. | ||
| Line 18: | Line 18: | ||
| * passive infrared sensor (PIR) | * passive infrared sensor (PIR) | ||
| * lens for directing radiation to the sensor | * lens for directing radiation to the sensor | ||
| - | * control | + | * control |
| [{{ : | [{{ : | ||
| Line 24: | Line 24: | ||
| ===== Practice ===== | ===== Practice ===== | ||
| - | PID andurite ehk detektorite väljundsignaal on üldjuhul lihtne digitaalsignaal, | + | PID sensors output is usually simple digital signal. If the sensor has detected something then it usually outputs high impulse which stays high for a given time period |
| - | Detektori kasutamine kontrolleriga tähendab sisuliselt, et anduri lugemine ei erine palju tavalise lüliti lugemisest. Detektori lugemiseks tuleks see ühendada mõne kontrolleri digitaal- või ka analoogsisendiga. Detektori ühendamise puhul on oluline jälgida viikude paigutust. Need võivad detektoritel erineda ja on oluline, et toide oleks detektoril ikka toite viikudega ja signaal signaaliviikudega ühendatud. | + | Using the detector with a microcontroller is not much different from reading a regular push button switch. PID can be connected to digital or analog input. Be sure to check the pinout of the detector before connecting it to microcontroller. It is especially important to not mix up power and ground pins cause failure to do so usually ends up in breaking the detector. |
| - | Kodulabor | + | On Robotic HomeLab |
| - | ~~PB~~ | + | < |
| <code c> | <code c> | ||
| - | // Kodulabori | + | // Robotic HomeLab |
| #include < | #include < | ||
| - | // Detektori sisendviigu defineerimine | + | // Detector input pin define |
| - | // Kodulabor | + | // Homelab |
| //pin pir_pin = PIN(F, 0); | //pin pir_pin = PIN(F, 0); | ||
| - | // Kodulabor | + | // Homelab |
| pin pir_pin = PIN(C, 4); | pin pir_pin = PIN(C, 4); | ||
| - | // Põhiprogramm | + | // Main program |
| int main(void) | int main(void) | ||
| { | { | ||
| - | // LED-i viikude väljundiks seadmine | + | // Setting |
| pin_setup_output(led_green); | pin_setup_output(led_green); | ||
| pin_setup_output(led_red); | pin_setup_output(led_red); | ||
| - | // Detektori signaaliviigu sisendiks seadmine | + | // Setting detector pin as input |
| pin_setup_input(pir_pin); | pin_setup_input(pir_pin); | ||
| - | // Lõputu tsükkel | + | // Endless loop |
| while (1) | while (1) | ||
| { | { | ||
| - | // Kui detektor ei ole rakendunud põleb roheline | + | // If the sensor has not detected anything then the green LED is on |
| - | // Kui detektor rakendub, süttib punane | + | // If something is detected then the RED led turns on |
| if(pin_get_value(pir_pin) == 0) | if(pin_get_value(pir_pin) == 0) | ||
| { | { | ||