IOT Lab 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

IOT Lab 4 Enrollment No: IU2141050017

Lab 4: Interfacing PIR Sensor with Arduino Uno Board.

Connection Diagram:

Fig. 1 Interfacing PIR Sensor with Arduino Uno Board

Fig. 2 Serial Monitor Readings

Program:

void setup() {
pinMode(2, INPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600);
}

Page No 1
IOT Lab 4 Enrollment No: IU2141050017

void loop()
{

int x = digitalRead(2);
if(x==HIGH){
Serial.println("Motion detected");
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
}
else
{
Serial.println("Motion not detected");
digitalWrite(5,LOW);
digitalWrite(4,LOW);
}
}

Function Description:

• Serial.begin(): Sets the data rate in bits per second (baud) for serial data transmission. For
communicating with Serial Monitor, make sure to use one of the baud rates listed in the menu at the
bottom right corner of its screen. You can, however, specify other rates - for example, to communicate
over pins 0 and 1 with a component that requires a particular baud rate.
• Serial.println(): Prints data to the serial port as human-readable ASCII text followed by a carriage return
character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same
forms as Serial.print().
• digitalRead: digitalRead() is basically an in-built function used by Arduino to read values from sensors,
buttons, etc.
• pinMode: The pinMode() function is used to configure a specific pin to behave either as an input or an
output.
• digitalWrite: The digitalWrite() function is used to write a HIGH or a LOW value to a digital pin. If the
pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding
value.
• setup(): The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start
using libraries, etc. The setup() function will only run once, after each powerup or reset of the Arduino
board.
• loop(): After creating a setup() function, which initializes and sets the initial values, the loop() function
does precisely what its name suggests, and loops consecutively, allowing your program to change and
respond. Use it to actively control the Arduino board.

Faculty Signature

Page No 2
IOT Lab 4 Enrollment No: IU2141050017

Page No 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy