0% found this document useful (0 votes)
2 views23 pages

Physical Computing and Robotics - Week 7-1

The document outlines a lecture on Ultrasonic Sensors and Relays for a Physical Computing and Robotics course. It covers the functionality of ultrasonic distance sensors, their components, and how they can be used in practical applications, as well as the use of relays to control high power devices safely. Additionally, it includes challenges for students to implement these concepts in projects involving buzzers and LEDs.

Uploaded by

play24comn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

Physical Computing and Robotics - Week 7-1

The document outlines a lecture on Ultrasonic Sensors and Relays for a Physical Computing and Robotics course. It covers the functionality of ultrasonic distance sensors, their components, and how they can be used in practical applications, as well as the use of relays to control high power devices safely. Additionally, it includes challenges for students to implement these concepts in projects involving buzzers and LEDs.

Uploaded by

play24comn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Physical Computing and Robotics

(ITS310)

Monday & Wednesday


9:45 am - 11:15 am
A-B1-03 (IT Research Lab)
Berzy Bahzad
Lecturer
The American University of Iraq, Sulaimani

Week 7, Lecture 13
Ultrasonic Sensor, and Relays
Lecture Outline
➢ Exploring Ultrasonic Distance Sensor
➢ Exploring Relays
○ Controlling low power devices
○ Controlling high power devices

➢ Practice and Challenge


➢ Creating an Account on Tinkercad
➢ Additional Input Devices
Exploring Ultrasonic Distance Sensor
● The ultrasonic sensor is a handy device that measures
the distance of a target by emitting ultrasonic waves, and
reflected sound into an electrical signal.
● The waves emitted are faster than the speed of audible
sounds (sound heard by humans).
● It has two main components:
○ The transmitter → Trig pin (Stands for triggering
sound waves)
○ Receiver → Echo pin (Receives back the triggered
ping)
● The sensor measures the time-frame between the ping
and reply that hits an object.
Exploring Ultrasonic Distance Sensor
● It is very similar to how bats navigate and fly in the dark.
○ Bats send out a sonar wave and measure the distance based on the returning
sound waves using their ears.

● It has four pins:


○ VCC → +5V
○ GND → Ground
○ Echo
○ Trig
Exploring Ultrasonic Distance Sensor

Modern Car Object Detection and Avoidance Parking Space - Occupied vs Available
Exploring Ultrasonic Distance Sensor
Ultrasonic Distance Sensor
● Examine this sketch:

#include <NewPing.h> // Download the library from manage library void loop() {
int cm = sonar.ping_cm(); //function to give
int TrigPin = 11; reading in cm
int EchoPin = 12; Serial.print("Distance in cm: ");
Serial.println(cm);
NewPing sonar(TrigPin, EchoPin, 100); //an object from the library delay(100);
//Three parameters: trig, echo, max distance [2 - 400]
}
void setup() {
Serial.begin(9600);

}
Ultrasonic Distance Sensor Challenge

Modify the sketch you wrote for the Ultrasonic


Distance Sensor replicating a vehicle proximity
sensor.

You need to include a buzzer in your application.


One meter away from the object, the buzzer
should buzz one beep per second. The closed
the sensor gets to the object, the buzzer will
beep much faster indicating how close you are to
the object.
Exploring Relays
● The Arduino board can only control low power devices directly.
○ In order to control high power devices, such as home appliances, you need to
use relays.

You should be very careful with relays, as the high power may cause
severe damage to you and your electronic components.

● Relays are switches that can be controlled by very low power that can be obtained
from microcontroller outputs.
● They come in DC and AC output control with certain current load (amps).
Exploring Relays
Controlling High Power Devices (Example):
Exploring Relays
● Relay connections and schematics:
Exploring Relays
● Relay connections and schematics:
Exploring Relays
● Relays usually have four, five, or eight terminals depending on their type:
○ Single Pole Single Through (SPST) relays have only four terminals.
○ Single Pole Double Through (SPDT) relays have only five terminals.
○ Double Pole Double Through (DPDT) relays have eight terminals.
● The two COIL terminals connect to the low power provided by your microcontroller.
● The other terminals control how high power flows to your high power device(s).
○ For example, on a SPST relay, the other two terminals control the electricity
flow to your home appliances using the switch.
Exploring Relays

● To make sure you understand how your


particular relay works, test it with a low power
first. For example, using LEDs.
○ Then you can move to higher power.
Exploring Relays: Turning On/Off an LED
● Examine the following schematics and write a simple blink sketch:
Exploring Relays: Turning On/Off an LED
● Add another LED without changing the sketch
Exploring Relays: Turning On/Off a Lamp
● Observe:
PLEASE, DO NOT TRY THIS AT HOME WITH
HIGH VOLTAGE!

Consult/practice with someone that has


experience with relays and high power!
More on relays can be found on Arduino Get Started Tutorial

https://arduinogetstarted.com/tutorials/arduino-relay
Combining Ultrasonic with Relay
● Examine this sketch:
void loop() {
int cm = sonar.ping_cm();
#include <NewPing.h>
Serial.println(cm);
delay(200);
int TrigPin = 11;
int EchoPin = 12;
if(cm >= 10){
int RelayPin = 3;
digitalWrite(RelayPin, HIGH);
delay(50);
NewPing sonar(TrigPin, EchoPin, 100);
digitalWrite(RelayPin, LOW);
delay(50);
void setup() {
}
pinMode(RelayPin, OUTPUT);
else{
Serial.begin(9600);
digitalWrite(RelayPin, HIGH);
}
}
}
Challenge

● Build an application using a relay, ultrasonic sensor, a piezo sounder (buzzer),


and two LEDs (red and green).
● As you get closer to the ultrasonic sensor, the buzzer beeps faster.
● Define two distances:
○ Distance one (safe distance) turns on the green LED.
○ Distance two (danger zone) turns on the red LED.
○ The two LED’s must be controlled by the relay. This automatically should
take care of one or the other LED switching between on and off.
Physical Computing and Robotics
(ITS310)

Monday & Wednesday


9:45 am - 11:15 am
A-B1-03 (IT Research Lab)
Berzy Bahzad
Lecturer
The American University of Iraq, Sulaimani

You might also like