Dec50122 Embedded Robotics - Pw3 (Procedure)
Dec50122 Embedded Robotics - Pw3 (Procedure)
SESSION 1 2023/2024
LECTURER’S NAME:
GROUP NO. :
1 LEARNING OUTCOMES (LO):
a) CLO3: manipulate the application of sensor and actuator, robot identification and
communication during practical work based on land mobile robot design (P4, PLO5)
2 OBJECTIVE
3 THEORY
Distance sensors are sensors used for determining the proximity of an object without any
physical contact involved. There are many types; ultrasonic, IR proximity, laser distance, etcs.
Ultrasonic Sensor
Ultrasonic Sensor also known as sonar sensor is a sensor that can measure distance. It emits
an ultrasound at 40 000 Hz (40kHz) which travels through the air and if there 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 the distance. 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
a) The ultrasonic sensor emits high-frequency sound waves towards the target object
b) Target object picks up the sound waves
c) Sound waves are then bounced off and reflected back towards the ultrasonic sensor
d) The time it took for the sound wave to return is used as the measurement of the
distance between
IR Sensor
An infrared sensor is an electronic device that emits in order to sense some aspects of the
surroundings. An IR sensor can measure the heat of an object as well as detects the motion.
These types of sensors measure only infrared radiation, rather than emitting it that is called a
passive IR sensor
The amount of reflected light depends upon the colour of the surface from which it is reflected.
The reflection is different for different coloured surfaces. This makes it a colour detector. The
IR transmitter sends an infrared signal that, in case of a reflecting surface (e.g. white colour),
bounces off in some directions including that of the IR receiver that captures the signal detecting
the object. When the surface is absorbent 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.
5 PROCEDURE
Schematic Diagram
b) Then, write the following code and compile and observe the result.
#define trigPin 9
#define echoPin 8
long duration, cm, inches;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
cm = (duration/2) / 29.1;
inches = (duration/2) / 74;
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(250);
}
TASK 2 : IR SENSOR
#include <IRremote.h>
int button = 0;
int mapCodeToButton(unsigned long code)
{
if ((code & 0x0000FFFF) == 0x0000BF00) {
code >>= 16;
if (((code >> 8) ^ (code & 0x00FF)) == 0x00FF)
{
return code & 0xFF;
}
}
return -1;
}
int readInfrared()
{
int result = -1;
if (IrReceiver.decode()) {
unsigned long code =
IrReceiver.decodedIRData.decodedRawData;
result = mapCodeToButton(code);
IrReceiver.resume();
}
return result;
}
void setup()
{
IrReceiver.begin(2);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
button = readInfrared();
if (button == 16)
{
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
else if (button == 13)
{
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
}
delay(10);
}