Professional Documents
Culture Documents
© 2022 - BYJU'S Future School. Please Don't Share, Download or Copy This File Without Permission
© 2022 - BYJU'S Future School. Please Don't Share, Download or Copy This File Without Permission
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
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.
● Student Resources:
○ Use Gmail login credentials.
○ Laptop with camera
○ Earphone with mic (optional)
○ Notepad and Pen
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.
diagram.json consists of
components and circuit information.
In this we can change the properties
of components used in the circuit.
Well done!!
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
To get the PIR Motion Sensor we need to click on a symbol from the
circuit connection workspace.
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.
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.
14
7. Once you click on LED, you will get the LED in the workspace
To get the Servo Motor we need to click on a symbol from the circuit
connection workspace.
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.
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:
17
d. Here you can see the wire color got changed to Yellow.
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.
19
pir1 : VCC terminal of PIR Sensor act as?
20
b. Similarly, Now Click on pir1: OUT terminal of the PIR Motion Sensor and
connect it to pin number 12 of Arduino Uno.
- 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.
..
21
c. Click on pir1: GND terminal of the PIR Motion Sensor and connect it to
the GND pin terminal of Arduino Uno.
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
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.
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.
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.
26
- Basically, This connection will help in maintaining the flow of the
current within Servo Motor and Arduino Uno.
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.
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.
29
- This connection will get the input signal, which will rotate the arm.
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.
31
What is void setup()
void setup() function is used to define the pins for all the
components which we have connected with arduino.
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:
32
2. So now write the code in the coding section inside sketch.ino
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
● 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.
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.
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.
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.
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.
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:
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.
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.
43
Now it’s your turn to execute the same!
● 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.
Login to Wokwi:
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.
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:
45
Output:
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.
As you complete the Circuit creation and Testing now to share the project link you need
to perform the below mentioned task.
d. As you copy the link, you will get the Wowki link which contains the created
circuit design.
48
e. Now share and submit this copied link in the Student Dashboard panel against the
correct class number.
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 myservo() Press the Hats Off Icon for
function? “Strong Concentration”.
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.
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.
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
52
Student Reference Wokwi Documentation https://docs.wokwi.com/?utm_source=wo
Activity 1 kwi
53