Sie sind auf Seite 1von 2

/* Example Circuit_11 IR sensor The IR Sensor is a general purpose proximity sensor.

Its typical application s like obstacle detection and collision avoidance can be achieved using this sen sor. The circuit consist of a IR emitter and IR receiver pair. The high precisio n IR receiver always detects a IR signal. The circuit consists of 358 comparator IC. The output of sensor goes high whenever it receives IR signal and low other wise. Thus it gives a digital output. LED the LED is use for output indication purpose; Hardware connections: IR Sensor As we know there is IR Transmitter and IR Reciever used in circuit. The IR transmitter is blue in color so it is easy to understand. Connect Positive terminal(longer leg) of IR transmitter to VCC (+5 V) throu gh a resistor of 220. Connect Negative terminal(shorter leg) of IR transmitter to GND. The IR Receiver has transparent casing similar to that of the LEDs, so be c areful while selecting the IR receiver and LED's. As a precaution, label and mai ntain your IR receiver in Zip lock plastic bag provided. Connect Positive terminal(longer leg) of IR Receiver to VCC (+5 V) through a resistor of 10k and connect the terminal to pin 2 of LM358 IC. Connect Negative terminal(shorter leg) of IR Receiver to GND. connect 0.1F capacitor between the positibe and negative terminal of IR recei ver. IC LM358 The IC is used is dual comparator IC. It is use to compare the input signal with the refernce selected. connect pin 1 to the Digital pin 4 of arduino. connect pin 2 to the positive terminal of IR receiver. connect pin 3 to the potentiometer. connect pin 4 to the ground. connect pin 8 to the VCC. RED LED Connect the positive side of your LED (longer leg) to Arduino digital pin 13 (or another digital pin, don't forget to change the code to match) through a 220 resistor . Connect the negative side of your LED (shorter leg) to ground. This code is completely free for any use. Visit http://www.arduino.cc to learn about the Arduino. */ // we'll use pin 4 for reading input signals from Sensor const int IR_Sen = 4; // we'll use pin 13 for output indication const int led_pin = 13;

void setup() { Serial.begin(9600); // Defining the pin as Input for IR Sensor Output pin. pinMode(IR_Sen, INPUT); // internally pullups are disabled in arduino firmware // to use pullup, enable manually digitalWrite(IR_Sen , HIGH); pinMode(led_pin, INPUT); } void loop() { // this experiment will continuosly check whether obstacle comes near the senso r or not. For indication purpose we are using an LED on Pin 13 of Arduino. // So whenever the obstacle comes near the sensor, LED glows and in idle condit ion LED is OFF. Also you see the output on serial monitor. if(digitalRead(IR_Sen) == 0) // Checking if any Obstaclke has been dete cted. { Serial.println("Obstacle detected"); digitalWrite(led_pin , HIGH); // Turns ON the LED } else { Serial.println("No obstacle"); digitalWrite(led_pin , LOW); // // Turns OFF the LED } //delay(100); ee the triggering of IR sensor more clearly } // uncomment this to s

Das könnte Ihnen auch gefallen