You are on page 1of 10

Amisha damor 21171341009

Practical-7

Aim: Write a program for IR Sensors


7.1)Write a program for IR Obstacle Sensor

Components:
1 Arduino Uno R3
1 IR Obstacle Sensor

Diagram:

Connection:

● The VCC pin of the IR sensor is connected to the 5V of the Arduino board.

● The GND pin of the IR sensor is connected to the GND of the Arduino board.

● The OUT pin(signal pin) of the IR sensor is connected to the 2 of the Arduino
board.

36
Amisha damor 21171341006

Code:
const int IN_A0 = A1; // analog input
const int IN_D0 = 5; // digital input

void setup() {
Serial.begin(9600);
pinMode (IN_A0, INPUT);
pinMode (IN_D0, INPUT);
}

int value_A0;
bool value_D0;

void loop( ) {
value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance
sensor value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance
sensor Serial.print(" Analogue = ");
Serial.print(value_A0);
Serial.print("\t Digital =");
Serial.println(value_D0);
delay(100);
}

37
Amisha damor 21171341006

7.2)Write a program for IR Flame Sensor

Components:
1 Arduino Uno R3
1 IR Flame Sensor

Diagram:

Connection:

● The VCC pin of the IR sensor is connected to the 5V of the Arduino board.

● The GND pin of the IR sensor is connected to the GND of the Arduino board.

● The OUT pin(signal pin) of the IR sensor is connected to the 2 of the Arduino
board.

38
Amisha damor 21171341006

Code:
const int IN_A0 = A1; // analog input
const int IN_D0 = 5; // digital input

void setup() {
Serial.begin(9600);
pinMode (IN_A0, INPUT);
pinMode (IN_D0, INPUT);
}

int value_A0;
bool value_D0;

void loop( ) {
value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance
sensor value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance
sensor Serial.print(" Analogue = ");
Serial.print(value_A0);
Serial.print("\t Digital =");
Serial.println(value_D0);
delay(100);
}

39
Amisha damor 211713410
7.3)Write a program for IR E18-D80NK Sensor
Components:

1 Arduino Uno R3
1 IR E18-D80NK Sensor

Diagram:

Connection:

● The VCC pin of the IR sensor is connected to the 5V of the Arduino board.

● The GND pin of the IR sensor is connected to the GND of the Arduino board.

● The OUT pin(signal pin) of the IR sensor is connected to the 2 of the Arduino
board.

40
Amisha damor 21171341006

Code:
const int IN_A0 = A1; // analog input
const int IN_D0 = 5; // digital input

void setup() {
Serial.begin(9600);
pinMode (IN_A0, INPUT);
pinMode (IN_D0, INPUT);
}

int value_A0;
bool value_D0;

void loop( ) {
value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance
sensor value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance
sensor Serial.print(" Analogue = ");
Serial.print(value_A0);
Serial.print("\t Digital =");
Serial.println(value_D0);
delay(100);
}

41
Amisha damor 21171341006

7.4)Write a program for IR Speed Sensor

Components:
1 Arduino Uno R3
1 IR Speed Sensor

Diagram:

Connection:

● The VCC pin of the IR sensor is connected to the 5V of the Arduino board.

● The GND pin of the IR sensor is connected to the GND of the Arduino board.

● The OUT pin(signal pin) of the IR sensor is connected to the 2 of the Arduino
board.

42
Vivek 21171341006

Code:
const int IN_A0 = A1; // analog input
const int IN_D0 = 5; // digital input

void setup() {
Serial.begin(9600);
pinMode (IN_A0, INPUT);
pinMode (IN_D0, INPUT);
}

int value_A0;
bool value_D0;

void loop( ) {
value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance
sensor value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance
sensor Serial.print(" Analogue = ");
Serial.print(value_A0);
Serial.print("\t Digital =");
Serial.println(value_D0);
delay(100);
}

43
Vivek Durga 211713410

Practical-8

Aim: Write a program to interface UltraSonic Sensor

Components:
1 Arduino Uno R3
1 UltraSonic Sensor (HE SR04)

Diagram:

Connection:

● The VCC pin of the UltraSonic sensor is connected to the 5V of the Arduino board.

● The GND pin of the UltraSonic sensor is connected to the GND of the
Arduino board.

● The OUT pin(signal pin) of the UltraSonic sensor is connected to the 7 of


the Arduino board.

44
Vivek Durga 21171341006

Code:
int inches = 0;

int cm = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)


{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echopin, and returns the sound wave travel time in
microseconds return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
}

void loop()
{
// measure the ping time in cm
cm = 0.01723 * readUltrasonicDistance(7, 7);
// convert to inches by dividing by 2.54
inches = (cm / 2.54);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.println("cm");
delay(100); // Wait for 100 millisecond(s)
}

45

You might also like