Introduction:
IR sensor module will have 3pins VCC, GND and D0 respectively.
VCC – +5V DC
GND – Ground
D0 – Digital Out
Requirements:
Arduino UNO – 1
IR Module – 1
Jumper Wires
This module consists of two leds (looks like led but not an led), one is IR Transmitter (i.e., white one) and second is photodiode (i.e., black one). IR Tx will transmits the IR rays(Infrared rays) continuously when module is powered up and photodiode is detectes the reflected IR rays. Here photodiode will detect only objected ir rays, IR rays will be reflect when an object is strike.
So, Module is used to find the object in front the module. IR used in the application of line following robot and robot with object finding.
If an object is there in front of the IR module, module will produce LOW signal at D0 pin or no object is there then IR rays won’t objected so, module produce HIGH signal at D0 pin.
Below program is the sample code for object finding using IR module:
- #define IR 3
- void setup()
- {
- Serial.begin (9600);
- pinMode (IR, INPUT);
- }
- void loop()
- {
- int val;
- val = digitalRead(IR);
- if(val)
- Serial.println(“No object detected”);
- else
- Serial.println(“Object Detected”);
- delay(1000);
- }
In the first line, declared a macro with the pin number to which we can connect the D0 pin of IR module.
In set up function configuring serial communication with the baud rate of 9600 and initializing ir pin as INPUT.
In loop function reading the sensor value by the digitalRead function, it will return the value either HIGH or LOW and storing in a variable val. Checking val variable with if condition, if val is HIGH condition goes true printing on Serial Monitor as “No Object detected”. if val is LOW then if condition goes false and control goes to the else part and printing on the Serial Monitor as “Object Detected”.
OUTPUT:
No object detected
No object detected
Object Detected
Object Detected
Note: More Information about predefined functions is explained in my previous blog click here.