Lecture 28 To 30 - Unit 4 - ECE249 - Introduction To Arduino and Sensors
Lecture 28 To 30 - Unit 4 - ECE249 - Introduction To Arduino and Sensors
Lecture 28 To 30 - Unit 4 - ECE249 - Introduction To Arduino and Sensors
And the second function is delay() which is used to provide a delay to the
upper instruction so that the next instruction will wait till the delay time gets
completed. In delay, we pass one parameter that is time to be delayed in
milliseconds. Here we want to delay the pin number high state for 1000
milliseconds or 1 second.
So, the known parameters are time and speed (constant). Using these
parameters, we can calculate the distance traveled by the sound wave.
// defines variables
long duration;
int distance;
• In the setup we have to define the trigPin as an output and the echoPin as an Input and
also start the serial communication for showing the results on the serial monitor.
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
• In the loop first we have to make sure that the trigPin is clear so you have to set that pin
on a LOW State for just 2 µs. Now for generating the Ultra sound wave we have to set the
trigPin on HIGH State for 10 µs.
Using the pulseIn() function we 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 is the state of the pulse
we are reading, either High or Low.
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
For getting the distance we will multiply the duration by 0.034 and divide it by 2
The temperature sensors TMP 35, TMP 36, and TMP 37 are the
sensors with the same features.
For Example: If the reading from the A0 pin is 248V then Vout will be
~800mV or ~0.8V.
For Example: If the output voltage is 0.8V then the temperature will be
approx. to 30°C.
In this article, We will learn how can we make a Motion Detection System
using Arduino. When the PIR Sensor will detect any motion, it will show
that on the Serial Monitor and the buzzer will start.