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

Arduino IR&US

This document describes two Arduino programs that use infrared and ultrasonic sensors. The first program uses an infrared sensor to identify objects by transmitting an infrared signal that bounces off an object and is received. The second program uses an ultrasonic sensor to measure distance by transmitting an ultrasound pulse and measuring the time until the pulse is received after bouncing off an object. Both programs require an Arduino board, sensors, jumper wires and breadboard. Schematic diagrams and programming code are provided to connect the sensors to the Arduino and output distance measurements to the serial monitor.

Uploaded by

yerni ganesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Arduino IR&US

This document describes two Arduino programs that use infrared and ultrasonic sensors. The first program uses an infrared sensor to identify objects by transmitting an infrared signal that bounces off an object and is received. The second program uses an ultrasonic sensor to measure distance by transmitting an ultrasound pulse and measuring the time until the pulse is received after bouncing off an object. Both programs require an Arduino board, sensors, jumper wires and breadboard. Schematic diagrams and programming code are provided to connect the sensors to the Arduino and output distance measurements to the serial monitor.

Uploaded by

yerni ganesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ACTIVITY 5

IR SENSOR & ULTRASONIC SENSOR


Program 1:
AIM:
Write an Arduino Program to Identify Objects using a IR Sensor on Arduino Platform

Components Required:
1. Arduino UNO & USB Connector

2. IR Sensor
3. Male to Male Jumper Wires
4. Breadboard

Schematic Diagram:

*** Draw this on left side in record

Theory:

Infrared Sensor is an electronic instrument that is used to detect any type of


obstacle/object & it is also used to detecting the black & white colour.
The basic concept of an Infrared Sensor which is used as Obstacle detector is totransmit an
infrared signal, this infrared signal bounces from the surface of an object and the signal is
received at the infrared receiver.

Arduino Program:
IR Sensor Connected to Arduino

OUTPUT:
Hence an Arduino Program to Identify Objects using a IR Sensor on Arduino Platform is done
Program 2:

AIM:

Write an Arduino Program to Measure Distance with Ultrasonic Sensoron Arduino


Platform

Components Required:
1. Arduino UNO & USB Connector

2. Ultrasonic Sensor

3. Male to Male Jumper Wires


4. Breadboard

Schematic Diagram:

*** Draw this on left side in record

Theory: Ultrasonic Sensor HC-SR04 is a sensor that can measure distance. It emits an
ultrasound at 40,000 Hz (40 kHz) which travels through the air and ifthere is an object or
obstacle on its path It will bounce back to the module.
Considering the travel time and the speed of the sound you can calculate thedistance.

The configuration pin of HC-SR04 is VCC (1), TRIG (2), ECHO (3), and GND (4).
The supply voltage of VCC is +5V and you can attach TRIG and ECHO pin to any
Digital I/O in your Arduino Board
In order to generate the ultrasound we need to set the Trigger Pin on
a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel at the
speed sound and it will be received in the Echo Pin. The Echo Pinwill output the time in
microseconds the sound wave travelled.

For example, if the object is 20 cm away from the sensor, and the speed of the sound is 340
m/s or 0.034 cm/µs the sound wave will need to travel about 588 microseconds. But what
you will get from the Echo pin will be double that number because the sound wave needs
to travel forward and bounce backward.So in order to get the distance in cm we need to
multiply the received travel time value from the echo pin by 0.034 and divide it by 2 .

For the programming code, first we need to define the Trigger Pin and Echo Pin that
connected to Arduino board. Then define variables for the distance (int) and duration
(long).
In the loop first you have to make sure that the trigPin is clear so we have to setthat pin
on a LOW State for just 2 µs. Now for generating the ultrasound wave we have to set the
trigPin on HIGH State for 10 µs.
Using the pulseIn()function you have to read the travel time and put that value into the
variable “duration”. This function has 2 parameters, the first one is the name of the echo
pin and for the second one you can write either HIGH or LOW. In this case, HIGH
means that the pulseIn() function will wait for the pinto go HIGH caused by the bounced
sound wave and it will start timing, then itwill wait for the pin to go LOW when the
sound wave will end which will stop the timing. At the end the function will return the
length of the pulse in microseconds. For getting the distance we will multiply the duration
by 0.034 and divide it by 2 as we explained this equation previously. At the end we will
print the value of the distance on the Serial Monitor.
Arduino Program:

Ultrasonic Sensor Connected to Arduino

OUTPUT:
Hence an Arduino Program to Measure Distance with Ultrasonic Sensoron Arduino
Platform is done.

You might also like