0% found this document useful (0 votes)
22 views

Lecture 15

The IR sensor module uses an IR transmitter and receiver to detect obstacles by sending out IR rays and measuring reflected rays. The detection range can be adjusted using a potentiometer. The output is high when no obstacle is detected and low when an obstacle is detected. An RGB LED can be controlled using analogWrite to independently set the brightness of the red, green, and blue LEDs and cycle through different colors.

Uploaded by

Azam Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lecture 15

The IR sensor module uses an IR transmitter and receiver to detect obstacles by sending out IR rays and measuring reflected rays. The detection range can be adjusted using a potentiometer. The output is high when no obstacle is detected and low when an obstacle is detected. An RGB LED can be controlled using analogWrite to independently set the brightness of the red, green, and blue LEDs and cycle through different colors.

Uploaded by

Azam Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

IR Sensor

Infrared Sensor
Infrared Sensor Module has built-in IR transmitter and IR receiver that sends out IR
rays and looks for reflected IR rays to detect presence of any obstacle in front of the
sensor module. The module has on board potentiometer that lets user adjust
detection range. The sensor has very good and stable response even in ambient
light or in complete darkness.

2
Principle of operation
• The IR transmitter sends an infrared signal that, in case of a reflecting surface (e.g.
white color), bounces off in some directions including that of the IR receiver that
captures the signal detecting the object.

• When the surface is absorbent (e.g. black color) the IR signal isn’t reflected and the
object cannot be detected by the sensor. This result would occur even if the object is
absent.

3
Principle of operation
The package has three connection pins:
Vcc to the power supply 3-5V DC;
Gnd to the ground reference;
Out for the digital output signal of the sensor.

This sensor detects objects at a distance in range between 2~30cm. With the
potentiometer you can calibrate the sensitivity according to the application
and environmental conditions (e.g. brightness). The IC LM393 is an open-
collector voltage comparator which provides an output if there is a pull-up R
between the output of the IC (DO) and the power supply Vcc (R=10KΩ). The
output DO is:

• high if the object is not detected;


• low if the object is detected.

4
Code
#define IR 2
int detection = HIGH; // no obstacle
void setup() {
Serial.begin(9600);
pinMode(IR, INPUT);
}
void loop() {
detection = digitalRead(IR);
if(detection == LOW){
Serial.print("There is an obstacle!\n");
}
else{
Serial.print("No obstacle!\n");
}
delay(500); // in ms
}

5
RGB LED

6
RGB LED

7
Code
int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup() {
  pinMode(red_light_pin, OUTPUT);
  pinMode(green_light_pin, OUTPUT);
  pinMode(blue_light_pin, OUTPUT);
}
void loop() {
  RGB_color(255, 0, 0); // Red
  delay(1000);
  RGB_color(0, 255, 0); // Green
  delay(1000);
  RGB_color(0, 0, 255); // Blue
  delay(1000);
  RGB_color(255, 255, 125); // Raspberry
  delay(1000);
  RGB_color(0, 255, 255); // Cyan
  delay(1000);
  RGB_color(255, 0, 255); // Magenta
  delay(1000);
  RGB_color(255, 255, 0); // Yellow
  delay(1000);
  RGB_color(255, 255, 255); // White
  delay(1000);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
  analogWrite(red_light_pin, red_light_value);
  analogWrite(green_light_pin, green_light_value);
  analogWrite(blue_light_pin, blue_light_value);
}

8
4

You might also like