You are on page 1of 53

Topic PIR SENSORS

Class Kids will understand how a PIR sensor detects the motion and
Description activates the connected devices based on the signal received.

Class ADV-C281

Class Time 60 mins

Goals
1. Understanding the working of PIR sensor and Servo Motor
2. Create a circuit and write a Program to Glow the LED bulb and
Stimulate the Servo Motor as the PIR motion sensor senses the
Motion in Wokwi platform.

Resources ● Teacher Resources:


Required ○ Use Gmail login credentials.
○ Laptop with camera
○ Earphone with mic
○ Notepad and Pen

● Student Resources:
○ Use Gmail login credentials.
○ Laptop with camera
○ Earphone with mic (optional)
○ Notepad and Pen

Class Warm Up 5 Mins


Structure Teacher-Led Activity 15 Mins
Student-Led Activity 30 Mins
Wrap Up 5 Mins
Project Pointers and Cues 5 Mins

Start the video call from H2H

Class Steps Say Do


© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

1
Step 1: In the last class, we created a circuit
Warm up and coded for blinking LED and
(5 mins) ringing Buzzer which is controlled by
a potentiometer in the Wokwi
platform.

Why do we need to use the


delay(value) function?

delay(value) function was used


to delay the rest of the code as per
the value mentioned.

What is diagram.json used for?

diagram.json consists of
components and circuit information.
In this we can change the properties
of components used in the circuit.

Well done!!

Teacher Initiates Screen Share

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

2
Step 2: NOTE: class outcomes are the
Teacher-Led activities which will give a idea
Activity of concept to be implemented so
(15 mins)
precisely convey it to learners
before the Teacher Activity
delivery

SAY: Kids will understand how


to write the code for detecting
signals received by PIR motion
sensors to activate the Servo
motor and to turn ON the LED.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

3
In the previous class we used PIR sensor
As you have seen in previous classes, we have implemented a circuit to control the Buzzer
ringing and LED blinking using a Potentiometer using Arduino and Buzzer.

In Tinkercad classes we used a PIR sensor.


Do you remember why a PIR sensor is used?
Basically PIR sensor is a type of sensor which senses the nearby object's motion and sends
the output as the motion detected to the connected devices.

Example of PIR sensor: We might have observed in our day to day life or in some of the
movies or even in houses the IoT based automatic Gates were implemented. Which
automatically gets open as the motion or object gets detected nearby.

These automatic Gates use a PIR sensor for detecting the motion in front of the gate and
after an object is detected sends the signal to Open the Gate.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

4
Similarly, in Tinkercad classes we had used Servo Motor as well.
Do you remember why a Servo Motor is used?

Servo Motor is a motor which actually helps in creating the devices which can perform
multiple actions by using its properties, such as Servo Motor can be used for rotating
operations like in DVD players.

Example of Servo Motor:

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

5
So here in the above example you can see how the servo motors can be implemented in a
machine for working with angle and position for picking up a ball.
Similarly servo motor can be used in many other machines like cranes, robotics, Industries
and many more.
We will be using these 2 components PIR sensor and servo motor in today's activity.

So now let's start creating a circuit and performing the programming on Arduino on Wokwi.

Code & Explanation

Open the url given Teacher Activity - 1 and login by following the below mentioned steps:
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

6
1. After opening Teacher Activity - 1 you will see the following interface as shown
below.

2. Now click on option and sign in with your gmail account.

3. You will see the interface as shown below.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

7
4. As we are going to work with the Arduino Uno board, we need to open the Arduino
Uno Circuit from the Wokwi platform. To go to the Circuit section click on Circuits Tab
located on the Left Side of the page as shown below.

5. As you click on Arduino Uno, You will get the interface as shown below.
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

8
Before we start to perform the below mentioned tasks lets understand the basic electronic
components which we use in today's class and its working.

The components are:


a. Arduino Uno R3 (IoT Switchboard With Power Supply)
b. PIR Motion Sensor
c. LED Bulb
d. Servo Motor

1. Arduino Uno R3: Arduino is used to supply power means, giving power to the
connected devices. And the working of Arduino will be the same as we saw in
Arduino in Tinkercad.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

9
2. PIR Motion Sensor : This is also called a motion sensor which detects motion.

3. Led Bulb: This is the LED bulb which we are going to use to emit the light in Wokwi.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

10
4. Servo Motor :Servo motor is the most precise and accurate motor which actually
helps to control the speed, rotation and angle.

The servo motor in Wokwi looks a little different as compared to Tinkercad, but both
functionalities are the same.

Today we will be performing the below mentioned tasks:

Task :
Create a circuit and write a Program to blink the LED bulb and activate the Servo Motor as
the PIR motion sensor senses the Motion in Wokwi platform.

Note: Open Teacher-Activity-2, it has the complete code for Task.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

11
- You need to first create the circuit for Task (Be very careful while making the
connection) and also explain the same to the student.
- Then explain the complete code to the student.

Task : Components
1. We already have an Arduino in our work area so Now you will make a
connection of the Servo Motor, LED Bulb and PIR sensor with the Arduino Uno
and have a look how it will work.

2. So now we are going to get the PIR Motion Sensor.

To get the PIR Motion Sensor we need to click on a symbol from the
circuit connection workspace.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

12
3. And search for “PIR Motion Sensor” then click on the PIR Motion Sensor as
shown below.

4. Once you click on PIR Motion Sensor, you will get the PIR Motion Sensor in
the workspace.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

13
5. Now we are going to get the LED.

To get the LED bulb we need to click on a symbol from the circuit
connection workspace.

6. Then click on the LED from the below drop down.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

14
7. Once you click on LED, you will get the LED in the workspace

8. And at last, we are going to get the Servo Motor.

To get the Servo Motor we need to click on a symbol from the circuit
connection workspace.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

15
9. And search for “Servo” then click on the Servo Motor as shown below.

10. Once you click on Servo Motor, you will get the Servo Motor in the workspace.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

16
Task : Connections
PIR Motion Sensor Connections:

Note: As we are going to make the connection with all components you
can change the Color of Wire. For changing the color of the wire follow
the below steps:

a. Click on diagram.json file.


diagram.json consists of components and circuit information. In
this we can change the properties of components and circuits.

b. In the diagram.json file you can see the properties of the


arduino. Now our goal is to change the color of the required
components. You can look for the component name for example
led2 on line number 11, in which the color attribute of led2 is
mentioned.

c. So change the color from red to any color, Here we have


changed to ‘’yellow’.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

17
d. Here you can see the wire color got changed to Yellow.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

18
e. Similarly, change the color of other wires' connections as per
your choice.)

1. First, we will make the connection between PIR Motion Sensor and Arduino
Uno R3 and have a look how it will work.
a. Click on pir1: VCC terminal of the PIR Motion Sensor and connect it to
pin number 13 by clicking on it on Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

19
pir1 : VCC terminal of PIR Sensor act as?

pir1: VCC terminal of the PIR sensor acts as a positive


terminal.

Why Pin no 13 of Arduino is used to connect with the PIR


Sensor?

Pin number 13 will act as Output terminal(also known as


positive terminal) which means it will provide the power supply to
the connected PIR Sensor and set the functionalities as per the
code written for this pin no. 13 which we are going to write later.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

20
b. Similarly, Now Click on pir1: OUT terminal of the PIR Motion Sensor and
connect it to pin number 12 of Arduino Uno.

This connection will pass the signal once motion is detected.

- pir1: OUT : Which will pass the Signals from the PIR Motion
Sensor as it detects the motion to arduino.
- uno : 12 : Pin number 12 will store the signals coming from
pir1:OUT signal.
..

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

21
c. Click on pir1: GND terminal of the PIR Motion Sensor and connect it to
the GND pin terminal of Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

22
This connection will complete the circuit and maintain the flow
of current within the PIR Motion Sensor from Arduino Uno.

- Here I will be using a different color wire for this connection which is
black.
NOTE: Teacher needs to change the color wire from diagram.json
file

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

23
LED Bulb Connection:

2. Now we will make the connection between LED Bulb and Arduino Uno :
a. Click on led1: A terminal of the LED bulb and connect it to pin number
11 of Arduino Uno.

- led1 : A : Here this terminal A acts as Anode of led 1 i.e Positive


terminal.
- uno : 11 : Pin number 11 will act as Output terminal(also known
as positive terminal) which means it will provide the power supply
to the connected LED and set the functionalities as per the code
written for this pin no. 11 which we are going to write later.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

24
b. Now connect the led1: C terminal of the LED bulb and connect it to the
GND pin terminal of Arduino Uno.

This connection will complete the circuit and maintain the flow of the
current within the LED bulb from Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

25
Servo Motor Connection:
3. Now at last, we will make the connection between Servo Motor and Arduino
Uno R3 and have a look how it will work.
a. Click on servo1: GND terminal of the Servo Motor and connect it to the
GND pin terminal of Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

26
- Basically, This connection will help in maintaining the flow of the
current within Servo Motor and Arduino Uno.

b. Now Click on servo1: V+ terminal of the Servo Motor and connect it to


pin number 10 of Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

27
- servo1: V+ : Which will get the signals from the PIR Motion
Sensor as it detects the motion and then this motor will start
working.
- uno : 10 : Pin number 10 will be used to control the activation
and deactivation of servo motor as per the code.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

28
d. Now click on servo1: PWM terminal of the Servo Motor and connect it
to pin number 9 by clicking on it in Arduino Uno.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

29
- This connection will get the input signal, which will rotate the arm.

- servo1: PWM : Here this terminal of the Servo Motor acts as a


Signal terminal. Which receives the signal and performs the
action given to it.
- uno : 9 :Pin number 9 will act as Output terminal(also known as
positive terminal) which means it will provide the power supply to
the connected Servo Motor and set the functionalities as per the
code written for this pin no. 9 which we are going to write later.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

30
The circuit connection is completed but if you run the simulation, it will not run
as it was working in Tinkercad. Because we need to add the code to make this
circuit functional. So now let's write the code.

Coding:

1. So as the connection between PIR Motion Sensor, Servo Motor, LED and
Arduino Uno is done now we will write the code to detect the motion by PIR
sensor and according to that the Servo Motor will run and LED will flow, For
this functionality we will code inside sketch.ino file.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

31
What is void setup()

void setup() function is used to define the pins for all the
components which we have connected with arduino.

What is the void loop()?

void loop() function we will write the code which will act on the
defined pins. The main logic of the code will be written inside this
function..

Complete Code:

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

32
2. So now write the code in the coding section inside sketch.ino

a. At line no 1, You will have to import <Servo.h> library which will be


required to perform the action of servo motor by using #include
method.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

33
- #include - It is the keyword of C programming which is used to
import outside libraries in our program.
Similarly, in python we used to use keyword include for importing
the new libraries.
- <servo.h> - It is the name of the external library which will be
used to set functionalities of the Servo motor.

b. Now, At line no. 2, we will have to call the myservro functions from
Servo library.

c. Now at line no. 3, we will have to declare a variable as servo_motor by


defining the Int data type and store the Pin no 10 in it.

- servo_motor - It is a variable which is used to store the output


pin number of a servo motor in it.
- 10 - It is the Pin number of Arduino Uno at which the Servo Motor
output terminal is connected.

d. Similarly, at line no. 4, we will have to declare a variable as led by


defining the Int data type and store the Pin no 11 in it.

- led - It is a variable which is used to store the output (Positive


Terminal) pin number of a LED bulb in it.
- 11 - It is the Pin number of Arduino Uno at which the LED bulb’s
anode terminal (Positive terminal) is connected.

e. Again, at line no. 5, we will have to declare a variable as pir for PIR
sensor by defining the Int data type and store the Pin no 12 in it.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

34
- pir - It is a variable which is used to store the pin number of a Pir
Motion Sensor in it.
- 12 - It is the Pin number of Arduino Uno at which the PIR
Sensor’s Signal terminal is connected.

f. Now, At line no. 10, We will declare the pin inside the void setup() by
using the pinMode() for setting the PIR Sensor pin.

- pinMode(): pinMode() function is used to set the mode of the pin


as input or output.
- pinMode takes 2 parameters which are:
- The pin number at which the component is connected
- Another is Input/Output.
- Hence we have passed the following parameters:
- pir : It is a variable which holds the signal data
which is collected by the PIR sensor.
- INPUT : Here we have mentioned INPUT, as we
want to get the motion detection data from the pin
stored in the pir variable.

g. Similarly, At line no. 11, We will declare the pin inside the void setup()
by using the pinMode() for setting the red LED pin.

- pinMode(): pinMode() function is used to set the mode of the pin


as input or output.
- pinMode takes 2 parameters which are:
- The pin number at which the component is connected
- Another is Input/Output.
- Hence we have passed the following parameters:
- led : led is the variable which holds the pin number
at which the LED is connected.
- OUTPUT : Here we have mentioned OUTPUT as
we want to supply power to the pin stored in the led
variable.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

35
h. Now, At line no. 12, we will define the myservo function followed by a
dot and then define the attach() method and pass pin number 9 in it at
which the Servo motor is connected in the Arduino Uno.

- myservo : It is the function of Servo library which uses its


functions to control a Servo motor.
- attach() :It is the method to define the pin number at which the
Servo motor is connected.
- 9: We had written 9 as the Servo Motor is connected to pin
number 9.

i. Now , at line no. 13, We will define the Serial.begin(9600) which will
help to communicate with other connected devices and arduino. This
Serial.begin() command actually helps to communicate between the
devices.

- Serial.begin() - It is the method which is actually used to transfer


the data from one device to the other connected device.
For example as you can see the communication occurs between
PIR sensor and Arduino Uno, to transfer the sensed motion data
by PIR sensor.
- 9600 - It is the transfer rate(speed), means at 9600 rate
transferring of data will happen between the connected devices

3. Now you will use the void loop() function in which we will define the action to
be performed by the variable and pins which is declared above in void setup()
funcion.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

36
a. At line no. 19, we will have to declare a variable as value_of_pir which
will hold the data which is collected by PIR Sensor.

- value_of_pir - It is a variable that holds the input data collected


by a PIR motion sensor.
- digitalRead() is the function which is used to read the motion
detected by the PIR sensor.
- pir - It is the variable that holds the pin number where PIR sensor
is connected

b. Now at line no. 21, Define the if statement and set the condition that if
the motion gets detected by the PIR sensor then the code written inside
the If statement will run.

- value_of_pir - It is a variable that holds the input data collected


by a PIR motion sensor.
- HIGH - It will check the value stored in the value_of_pir variable
is HIGH If yes then this condition satisfies and will execute the
code inside if condition.
HIGH means the motion is detected.

● Now at line no. 23, Inside the if statement we will write a


digitalWrite() function for turning the LED ON. This statement
will help to glow the LED as the motion gets detected by PIR
Sensor.

- digitalWrite() is the function which is used to control the


components.It takes 2 parameters:
- The pin on which the component is connected
- The action needs to be taken on those
components.
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

37
- So we will be passing parameters like:
- led - It is a variable which is used to store the
output (Positive Terminal) pin number of a LED bulb
in it.
- HIGH - We are setting the power supply as HIGH,
defining, as we want to turn ON the LED

● Now at line no. 24, We will define the myservo function followed
by a dot defining the write() method and pass the rotation angle
value as 180 in it. This statement will rotate the arm of Servo
Motor to 180 Degrees.

- myservo - It is the function of Servo library which uses its


functions to control a Servo motor.
- write() - It is the method which is used to set the action to
be performed by the connected Servo motor.
- 180 - It is the rotation angle in degrees, how much the
Servo Motor arm should rotate.

● Now at line no. 25, We will define the Serial.println() to print the
“Motion Detected” statement. This statement will print the
Motion Detected in the wokwi console as the motion detected by
PIR sensor.

- Serial.println() - It is the function of C language which is


used to print the statement in wokwi console.

c. Now, at line no. 28, we will define the else statement which will get
executed if the condition defined is not satisfied. In this else statement
we are going to turn off the led and get the servo motor back to its
original position.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

38
● Now within the else statement we will write a digitalWrite()
function for turning the LED turned OFF.This function will turn off
the LED light.

What is the use of the digitalWrite() function?

digitalWrite() function is used to control the


connected components .

What are the 2 parameters required in digitalWrite()


function?

The 2 parameters required in digitalWrite() function


are
- The pin on which the component is connected
- The action needs to be taken on those
components.

- So we will be passing parameters like:


- led - It is a variable which is used to store the
output (Positive Terminal) pin number of a LED in it.
- LOW - We are setting the power supply as LOW, to
turn OFF the LED.

● Now at line no. 31, We have to define the myservo function


followed by a dot defining the write() method and pass the
rotation angle value as 0 in it. This statement will rotate the arm
of Servo Motor to its original position i.e 0 Degrees.

- myservo - It is the function of Servo library which uses its


functions to control a Servo motor.
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

39
- write() - It is the method which sets the action to be
performed by the connected Servo motor.
- 0 - It is the rotation angle in degrees, how much the Servo
Motor arm should rotate.

● Now at line no. 32, We will define the Serial.println() to print the
“Motion Detected” statement. This statement will print the
Motion completed in the wokwi console as the motion detected
completed by PIR sensor.

- Serial.println() - It is the function of C language which is


used to print the statement in wokwi console.

4. As the connection and Coding both between the PIR Motion sensor, Servo
Motor, Arduino Uno and LED Bulb has been successfully made, now we need
to test that all the connection coding is working properly.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

40
5. Now to test the Connection, you need to start the Simulation. So to start the

Simulation you need to click on the button which is located on the Top
side of Wokwi webpage.

Output:

Before starting the Simulation:

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

41
After Starting Simulation:
Here as you run the Simulation, Click on PIR Motion sensor,
- The pir sensor will detect the motion by clicking on "Stimulate Motion” button
- As the Motion gets detected the LED bulb will glow.
- And the Arm of servo Motor will rotate by 180 degree along with the Statement will be
printed on Console.
- As the Motion detection is completed, the LED bulb gets dimmed.
- And the Servo motor will get back to its original Position i.e 0 degree.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

42
Here we did this task to understand how PIR sensors work with a Servo motor on Arduino
Uno R3 and how connections are made to create Smart Door in which the PIR sensor
detects the motion and passes the signal to LED to glow and servo motor to start.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

43
Now it’s your turn to execute the same!

Teacher Stops Screen Share

Now it is your turn.

● Ask the Student to press the ESC key to come back to the panel.
● Guide the Student to start Screen Share.
● The Teacher gets into Fullscreen.

Step 3: Student-Activity-1- WOKWI


Student-Led
Activity Student Activity 2 - CODE
(30 mins) DIAGRAM

Login to Wokwi:

1. Open the URL given in Student Activity - 1.

2. After opening click on Sign In with your gmail account.

3. As we are going to work with the Arduino Uno board, click on the Arduino Uno board.

4. As you click on Arduino Uno, You will get the interface as shown below.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

44
Now perform the below mentioned task:

Task : Create a circuit and write a Program to Glow the LED bulb and Stimulate the
Servo Motor as the PIR motion sensor senses the Motion in Wokwi platform:

Complete Code:

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

45
Output:

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

46
Well Done…! You have created and tested successfully your circuit by coding to rotate the
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

47
arm of Servo Motor as per the PIR sensor detects the motion, which can be implemented in
IoT Based Smart Home appliances i.e a creating Smart Door which will open as the motion
is detected.

Submitting the Wokwi Circuit Link

As you complete the Circuit creation and Testing now to share the project link you need
to perform the below mentioned task.

a. Click on button to save the project.

b. Now At Top Left Corner, Click on the Button.

c. Now click on option to get the Link.

d. As you copy the link, you will get the Wowki link which contains the created
circuit design.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

48
e. Now share and submit this copied link in the Student Dashboard panel against the
correct class number.

Teacher Guides Student to Stop Screen Share

Step 4: You did great today as well. (Give at least 2 hats offs)
Wrap-Up Great! You have two hats off. Press the Hats Off Icon for
(5 mins) Creatively Solving Activities.

What is the use of the


Serial.begin() function?
Press the Hats Off Icon for Great
Serial.begin() command Question.
actually helps to communicate
between the devices.

What is the use of myservo() Press the Hats Off Icon for
function? “Strong Concentration”.

myservo() is the function of


Servo library which uses its functions
to control a Servo motor.
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

49
If you don’t have time to
perform additional activities,
ask the student to perform all
the additional activities after
the class. Additional activities
are VERY important for kids, so
that they are ready for the next
module. And some challenging
concepts are coming ahead.

Also remind the student to refer


to the Student Reference activity
for increasing his/her
knowledge. This should also be
done.

Teacher Initiates Screen Share

Step 5: MOTION DETECTION Open the Project Solution link


Project and showcase the output.prin
Pointers and Goals of the Project:
Cues In today’s class we learned how
(5 mins) motion sensors detect the motion
and then activate the connected
devices based on the signal
received.

MOTION DETECTION:
In this project, we want you to
create a circuit by using Arduino
Uno board and PIR Motion Sensor,
Buzzer and write a program to
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

50
activate buzzer for 3 sec as the
motion is detected by PIR Sensor.

Story:
Domson Secure is the Smart
Security based IoT firm. They do
build smart IoT based Electrical
security devices. But they want such
a platform on which they can create
a circuit along with some
functionality to the circuit, and they
can test it. As the issues which they
were facing, while creating and
testing the security based circuits
are damaging the builded circuit
due to some error in connection.
So can you help them build such a
circuit which will detect the motion
of nearby objects and ring the
Buzzer.

Good Luck!

For the solution of all the Additional Activity, open Teacher-Activity-4 and navigate to
class number C281

Additional Activity 1 -
Run Additional-Activity-1 from the panel.
The TASK and HINTS are mentioned on the website itself.

Additional Activity 2 -
Run Additional-Activity-2 from the panel.
The TASK and HINTS are mentioned on the website itself.

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

51
Additional Activity 3 -
Run Additional-Activity-3 from the panel.
The TASK and HINTS are mentioned on the website itself.

Additional Activity 4 -
Run Additional-Activity-4 from the panel.
The TASK and HINTS are mentioned on the website itself.

Additional Activity 5 -
Run Additional-Activity-5 from the panel.
The TASK and HINTS are mentioned on the website itself.

Teacher Clicks

Activity Activity Name Links

Teacher Activity 1 WOKWI LOGIN https://wokwi.com/

Teacher Activity 2 TASK https://wokwi.com/arduino/projects/32056


9788876194386

Teacher Activity 3 CODE DIAGRAM https://docs.google.com/document/d/e/2P


ACX-1vS_yPLvFegRx8-q6jnay7OFiBjGL
sS9sVG6QqZ2ipWEEw9uzwkb0r7rlmGc
pQ-_bU6_Vc59uZsxsL1e/pub

Teacher Activity 4 ADDITIONAL ACTIVITY https://mahdihat791.github.io/v2/addition


al_activities_solution.html

Student Activity 1 WOKWI LOGIN https://wokwi.com/

Student Activity 2 CODE DIAGRAM https://docs.google.com/document/d/e/2P


ACX-1vS_yPLvFegRx8-q6jnay7OFiBjGL
sS9sVG6QqZ2ipWEEw9uzwkb0r7rlmGc
pQ-_bU6_Vc59uZsxsL1e/pub
© 2022 - BYJU’S Future School.
Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

52
Student Reference Wokwi Documentation https://docs.wokwi.com/?utm_source=wo
Activity 1 kwi

Student Reference Arduino https://docs.arduino.cc/cloud/iot-cloud/tut


Activity 2 orials/iot-cloud-getting-started

Project Showcase MOTION DETECTION https://docs.google.com/document/d/e/2P


ACX-1vQ-Z8acU5mPkCp6su61u3f-eL-ep
uZ3h2sQg626_LVipndAobpE4NWkvhAIn
pw1jV6UKXzLtfUwjsFo/pub

© 2022 - BYJU’S Future School.


Note: This document is the original copyright of BYJU’S Future School.
Please don't share, download or copy this file without permission.

53

You might also like