Rudra Iot Practical
Rudra Iot Practical
1
Government Engineering College, Gandhinagar
Department of Computer Engineering
CERTIFICATE
satisfactorily completed the Practical / Tutorial work for the subject IoT and
Place:
Date:
Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant competencies
in psychomotor domain. By keeping in view, GTU has designed competency focused outcome-
based curriculum for engineering degree programs where sufficient weightage is given to
practical work. It shows importance of enhancement of skills amongst the students and it pays
attention to utilize every second of time allotted for practical amongst students, instructors and
faculty members to achieve relevant outcomes by performing the experiments rather than having
merely study type experiments. It is must for effective implementation of competency focused
outcome-based curriculum that every practical is keenly designed to serve as a tool to develop
and enhance relevant competency required by the various industry among every student. These
psychomotor skills are very difficult to develop through traditional chalk and board content
delivery method in the classroom. Accordingly, this lab manual is designed to focus on the
industry defined relevant outcomes, rather than old practice of conducting practical to prove
concept and theory.
By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which creates an interest and students can have basic idea prior to
performance. This in turn enhances pre-determined outcomes amongst students. Each experiment
in this manual begins with competency, industry relevant skills, course outcomes as well as
practical outcomes (objectives). The students will also achieve safety and necessary precautions
to be taken while performing practical.
This manual also provides guidelines to faculty members to facilitate student centric lab activities
through each experiment by arranging and managing necessary resources in order that the
students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.
This manual is designed to accompany your practical exploration of the exciting and rapidly
evolving field of Internet of Things (IoT) and its practical applications. IoT is revolutionizing the
way we interact with and utilize technology, and this manual will guide you through hands-on
exercises to deepen your understanding of the subject.
Utmost care has been taken while preparing this lab manual however always there is chances of
improvement. Therefore, we welcome constructive suggestions for improvement and removal of
errors if any.
DTE’s Vision
Institute’s Vision
Institute’s Mission
Department’s Vision
Department’s Mission
Sign. of
Sr. Page Date of Date of Assessment
No.
Objective(s) of Experiment No. performance submission Marks
Teacher Remarks
with date
Total
IOT and Application 3160716
Experiment No: 1
Aim: Understanding Arduino UNO, Node MCU and Raspberry Pi and Arduino IDE.
Date:
Objectives:
1. Differentiate between Arduino UNO, Node MCU, and Raspberry Pi in terms of hardware
and applications.
2. Identify and handle the key components of each platform.
3. Install and configure the Arduino IDE for microcontroller programming.
4. Write and upload a basic "Hello, World!" program to Arduino UNO.
5. Understand the basic structure of Arduino code, including setup () and loop () functions.
6. Describe the significance of GPIO pins in microcontroller programming.
7. Explore the Node MCU board and its compatibility with IoT applications.
8. Gain familiarity with the Raspberry Pi as a versatile single-board computer.
9. Describe the role of Raspberry Pi in IoT projects and applications.
10. Recognize the significance of choosing the appropriate hardware platform for specific IoT
projects.
Equipment/Instruments:
Explanation:
Arduino UNO:
Arduino has been used in thousands of different projects and applications. The Arduino software
is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows,
and Linux. Teachers and students use it to build low cost scientific instruments, to prove chemistry
and physics principles, or to get started with programming and robotics. Designers and architects
build interactive prototypes, musicians and artists use it for installations and to experiment with
new musical instruments. Makers, of course, use it to build many of the projects exhibited at the
Maker Faire, for example. Arduino is a key tool to learn new things. Anyone - children, hobbyists,
artists, programmers - can start tinkering just following the step by step instructions of a kit, or
sharing ideas online with other members of the Arduino community.
There are many other microcontrollers and microcontroller platforms available for physical
computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handy board, and many
others offer similar functionality. All of these tools take the messy details of microcontroller
programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of
working with microcontrollers, but it offers some advantage for teachers, students, and interested
amateurs over other systems:
➢ Inexpensive - Arduino boards are relatively inexpensive compared to other
microcontroller platforms.
➢ Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
➢ Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well. For
teachers, it's conveniently based on the Processing programming environment, so students
learning to program in that environment will be familiar with how the Arduino IDE works.
The key features are −
➢ Arduino boards are able to read analog or digital input signals from different sensors and
turn it into an output such as activating a motor, turning LED on/off, connect to the cloud
and many other actions.
➢ You can control your board functions by sending a set of instructions to the microcontroller
on the board via Arduino IDE (referred to as uploading software).
➢ Unlike most previous programmable circuit boards, Arduino does not need an extra piece
of hardware (called a programmer) in order to load a new code onto the board. You can
simply use a USB cable.
➢ Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn
to program.
➢ Finally, Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.
NodeMCU :
NodeMCU is an open-source Lua based firmware and development board specially targeted for
IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif
Systems, and hardware which is based on the ESP-12 module.
Fig 3: Raspberry Pi
The Raspberry Pi launched in 2012, and there have been several iterations and variations released
since then. All over the world, people use the Raspberry Pi to learn programming skills, build
hardware projects, do home automation, implement Kubernetes clusters and Edge computing,
and even use them in industrial applications.
The Raspberry Pi is a very cheap computer that runs Linux, but it also provides a set of GPIO
(general purpose input/output) pins, allowing you to control electronic components for physical
computing and explore the Internet of Things (IoT).
Arduino IDE:
The source code for the IDE is released under the GNU General Public License, version 2. The
Arduino IDE supports the languages C and C++ using special rules of code structuring. The
Arduino IDE supplies a software library from the Wiring project, which provides many common
input and output procedures. User-written code only requires two basic functions, for starting the
sketch and the main program loop, that are compiled and linked with a program stub main() into
an executable cyclic executive program with the GNU toolchain, also included with the IDE
distribution.The Arduino IDE employs the program avrdude to convert the executable code into
a text file in hexadecimal encoding that is loaded into the Arduino board by a loader program in
the board's firmware. By default, avrdude is used as the uploading tool to flash the user code onto
official Arduino boards.
Arduino IDE is a derivative of the Processing IDE, however as of version 2.0, the Processing IDE
will be replaced with the Visual Studio Code-based Eclipse Theia IDE framework.
With the rising popularity of Arduino as a software platform, other vendors started to implement
custom open source compilers and tools (cores) that can build and upload sketches to
other microcontrollers that are not supported by Arduino's official line of microcontrollers.
Observation:
The Arduino Uno is a popular microcontroller board known for its simplicity and versatility in electronic
projects. It's often used for prototyping and DIY electronics due to its ease of use and large community support.
NodeMCU is a development board based on the ESP8266 WiFi module. It's widely used for Internet of Things
(IoT) projects due to its built-in WiFi capabilities, making it suitable for applications requiring wireless
communication.
Raspberry Pi is a credit-card-sized single-board computer that runs on Linux. It's capable of performing tasks
similar to a desktop computer, such as web browsing and playing videos, making it suitable for a wide range
of projects from home automation to media centers.
Conclusion:
In conclusion, the question reveals a curiosity about the exciting world of electronics and programming,
particularly in the realm of building projects. It specifically inquires aboutpopular development platforms like
Arduino UNO, NodeMCU, Raspberry Pi, and the Arduino IDE software used to program them. This suggests
you're on the lookout for a beginner-friendly platform to embark on a learning journey that equips you with the
skills to bring your creative ideas to life. Whether you envision tinkering with sensor-based projects using an
Arduino UNO, exploring the world of IoT with a NodeMCU, or delving into projects demanding the processing
power of a Raspberry Pi, these platforms offer a springboard for your maker pursuits
Quiz:
1. Which hardware platform is known for its versatility and use as a single-board computer in IoT
applications?
Raspberry PI
2. What is the primary function of the Arduino Integrated Development Environment (IDE)?
Writing code: The IDE offers a text editor with syntax highlighting and code completion features specifically
suited for writing Arduino programs (often called sketches).
Compiling code: The IDE compiles the code you write into a machine-readable format that the Arduino board
can understand.
Uploading code: The IDE facilitates transferring the compiled code from your computer to the Arduino board's
memory.
3. In the context of Arduino programming, what is the purpose of the setup () function?
Initializing variables: You can assign initial values to variables used throughout your program. This ensures
they start in a known state.
Setting pin modes: You specify whether each pin on the Arduino board will function as an input (receiving
signals from sensors) or an output (sending signals to control lights, motors, etc.) using functions like
pinMode().
Configuring hardware components: If your project involves external components like sensors, actuators, or
communication modules (like Bluetooth or Wi-Fi), you'll typically use the setup() function to initialize them
and establish communication protocols.
4. Which hardware platform is typically used to create web servers and Wi-Fi-enabled IoT applications?
The NodeMCU is typically used to create web servers and Wi-Fi-enabled IoT applications. It's based on the
ESP8266 Wi-Fi module, which makes it well-suited for projects that require wireless connectivity, such as
IoT devices that need to communicate over a network or serve web pages. With its built-in Wi-Fi capabilities
and relatively low cost, the NodeMCU is a popular choice for developing internet-connected projects and
applications.
5. Which of the following IoT hardware platforms is primarily based on the use of GPIO pins for interfacing
with sensors and devices?
Arduino Uno and Raspberry Pi
References:
https://www.tinkercad.com/
Experiment No: 2
Date:
Objectives:
1. Identify the key components of an Arduino UNO microcontroller board.
2. Establish a connection between an Arduino UNO and an LED.
3. Write and upload an Arduino sketch (program) to control the LED's state (ON or OFF).
4. Understand the concept of digital output and how to use it for controlling external devices.
5. Experiment with modifying the code to change the LED's behaviour (e.g., blinking
patterns).
6. Troubleshoot common issues related to hardware connections and code errors.
7. Recognize the relevance of this fundamental skill in various IoT and embedded systems
applications.
Components:
1. Arduino UNO Microcontroller: This is the central component of the lab session. The
Arduino UNO is a microcontroller board that will be used to control the LED.
2. LED (Light-Emitting Diode): An LED is used as the output device. LEDs come in
various colours and types, but a basic one will suffice for this exercise.
3. Resistor (220-330 ohms): A current-limiting resistor is necessary to prevent excessive
current from flowing through the LED and potentially damaging it.
4. Breadboard: A breadboard is used for easy prototyping and making temporary
connections. It simplifies the setup and makes it easier to modify the circuit.
5. Jumper Wires: These wires are used to make connections between the components on
the breadboard, ensuring electrical continuity.
6. USB Cable: A USB cable is required to connect the Arduino UNO to a computer for
programming.
7. Computer with Arduino IDE: You'll need a computer with the Arduino Integrated
Development Environment (IDE) installed. The Arduino IDE is used to write, compile,
and upload code to the Arduino UNO.
8. Power Source (optional): In some cases, an external power source may be required if
you are working with multiple LEDs or components that draw more current than the
Arduino can provide.
Configuration:
Procedure:
void loop() {
// Turn on the LED by setting Pin 13 (or LED_BUILTIN) to HIGH.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1 second (1000 milliseconds).
Observation:
Conclusion:
In conclusion, Tinkercad offers a valuable platform to explore controlling LEDs with Arduino UNO in
a simulated environment. It eliminates the need for physical components, allowing you to learn the
fundamentals of circuit building and Arduino programming virtually.
Quiz:
1. In the circuit setup to control an LED with an Arduino Uno, which pin is connected to the anode (long
pin) of the LED?
Digital pin (pin no:8)
3. In the provided Arduino code, what is the purpose of the pin Mode (LED_BUILTIN, OUTPUT); line in
the setup () function?
pinMode Function: This built-in Arduino function allows you to define how a particular pin on the
Arduino board will be used.
LED_BUILTIN: This is a constant variable pre-defined in the Arduino environment that typically refers
to pin 13 on the Arduino UNO. It provides a convenient way to access the builtin LED without needing
to remember the exact pin number. (You can also use the actual pin number, 13, in this case.)
OUTPUT: This argument specifies that the LED_BUILTIN pin will be configured as an output pin. This
means the Arduino can send a digital signal (HIGH or LOW) through this pin to control external devices
like an LED.
4. How long does the LED stay on in the provided Arduino code before turning off in the loop () function?
The LED stays on for 1 second in the provided Arduino code before turning off in the loop function.
References:
https://www.tinkercad.com/
Experiment No: 3
Aim: Measuring Temperature and Humidity using Sensor DHT-11 and Arduino UNO.
Date:
Objectives:
1. Identify the components of the DHT-11 sensor, including the temperature and humidity
sensing elements.
2. Build a circuit to connect the DHT-11 sensor to an Arduino UNO.
3. Write Arduino code to read temperature and humidity data from the sensor.
4. Display the sensor data on a connected display (e.g., a serial monitor or an LCD).
5. Understand the calibration and limitations of the DHT-11 sensor.
6. Recognize the importance of temperature and humidity measurements in IoT applications.
Components:
1. Arduino UNO Microcontroller: This is the central component for interfacing with the
DHT-11 sensor and processing data.
2. DHT-11 Sensor: A sensor module that can measure temperature and humidity.
3. Breadboard: Used for easy prototyping and making temporary connections.
4. Jumper Wires: These wires are used to make connections between the components on the
breadboard.
5. Display (e.g., Serial Monitor on a computer or an LCD): Used to display the temperature
and humidity data.
6. Power Source: The Arduino UNO may require a power source to operate the circuit.
Configuration:
Procedure:
connections.
Step 3: Adding the DHT Library
• In the Arduino IDE, go to "Sketch" > "Include Library" > "Add ZIP file."
• Locate and select the "DHT_Library.zip" file and add it to the IDE.
Code:
#include <dht.h>
#define dht_11_PIN 7
dht DHT;
void setup(){
Serial.begin(9600);
delay(500); // Delay to let the system boot
Serial.println("DHT11 Humidity & Temperature Sensor\n\n");
delay(1000); // Wait before accessing the sensor
}
void loop(){
DHT.read11(dht_11_PIN);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);
}
Step 4: Uploading and Monitoring Data
• Upload the provided code to the Arduino UNO.
• After uploading, open the Arduino IDE's serial monitor by clicking the magnifying
glass button in the top right corner.
• The sensor data (humidity and temperature) should be displayed and updated every 5
seconds in the serial monitor.
Output:
Conclusion:
The provided Arduino sketch is designed to interface with a DHT11 humidity and temperature sensor
connected to pin 7 of the Arduino board. It initializes serial communication, reads data from the sensor
in a continuous loop, and prints the humidity and temperature readings to the serial monitor every 5
seconds. This sketch serves as a basic example of how to use the DHT11 sensor with an Arduino Uno
to monitor environmental conditions.
Quiz:
1. When placing the DHT-11 sensor on the breadboard, which part of the sensor should be facing you?
When placing the DHT-11 sensor on the breadboard, the side with the sensor component should be facing
you. This is the part of the sensor that contains the humidity and temperature sensing elements. Ensure
that the sensor's pins align with the breadboard's rows and are properly inserted to make electrical
connections for proper functionality.
2. Which of the following correctly identifies the pins on the DHT-11 sensor?
3. How do you add the DHT library to the Arduino IDE? Open the Arduino IDE on
your computer.
Go to the "Sketch" menu at the top of the IDE.
Navigate to the "Include Library" submenu.
Select "Manage Libraries..." from the dropdown menu. This will open the Library Manager.
In the Library Manager, you can search for libraries by typing into the search bar. Type "DHT" into the
search bar.
The search results will display libraries related to the DHT sensor family. Look for the "DHT sensor
library by Adafruit" or similar. It's one of the popular libraries for interfacing with DHT sensors.
Click on the library you want to install, and an "Install" button will appear. Click on the "Install" button
to install the library.
Once the installation is complete, close the Library Manager.
Now, the DHT library is added to your Arduino IDE, and you can include it in your sketches by going
to the "Sketch" menu, then selecting "Include Library", and finally selecting the "DHT sensor library by
Adafruit" (or similar) from the list.
5. In the serial monitor, how often (In seconds) does the sensor data update in the provided code?
5 seconds (5000 milliseconds).
References:
https://www.tinkercad.com/dashboard
Code
Sensor Connection Understanding
Quiz Performance Ethics
Placement Setup &
Data Display
Goo Averag Good Averag Good Average Good Average Good Averag
d (2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)
Experiment No: 4
Aim: Measuring object presence using IR Sensor and when present, use buzzer for
notification.
Date:
Objectives:
1. Identify the key components of an IR sensor, buzzer, and the necessary connections.
2. Build a circuit to connect an IR sensor and a buzzer to an Arduino or microcontroller.
3. Write Arduino code to detect the presence of an object using the IR sensor.
4. Implement logic in the code to activate the buzzer when an object is detected.
5. Understand the practical applications of object detection and notification systems in IoT
and automation.
Components:
1. IR Sensor: A sensor module designed to detect the presence of objects by emitting and
receiving infrared signals.
2. Buzzer: An audible notification device that produces sound when activated.
3. Arduino or Microcontroller: The central control unit used to process sensor data and
control the buzzer.
4. Breadboard: Used for easy prototyping and making temporary connections.
5. Jumper Wires: These wires are used to make connections between the components on the
breadboard.
6. Power Source (if required): Depending on the components used, an external power source
may be needed to operate the circuit.
Configuration:
Procedure:
void setup() {
Serial.begin(9600);
pinMode(irSensor, INPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
int value = digitalRead(irSensor);
Serial.println("");
Serial.print("Sensor Value = ");
Serial.print(value);
if (value == 0) {
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
delay(50);
}
Code Explanation:
• The code initializes two variables irSensor (connected to pin 12) and buzzer
(connected to pin 7) to represent the IR sensor and buzzer pins, respectively.
• In the setup () function, it sets up the serial communication for debugging,
configures the IR sensor pin as an input, and the buzzer pin as an output.
• The loop () function reads the value of the IR sensor using digitalRead(irSensor)
and stores it in the value variable.
• It then prints the sensor value to the serial monitor for monitoring.
• If the sensor value is 0 (indicating the presence of an object), it sets the buzzer pin
to HIGH to activate the buzzer. If there is no object detected, it sets the buzzer pin
to LOW to turn off the buzzer.
• There's a delay (50) to introduce a small delay between readings.
Step 3: Test the Circuit
• Upload the code to your Arduino or microcontroller.
• Open the serial monitor in the Arduino IDE.
• Observe the sensor value being printed and listen for the buzzer activation
when an object is detected (sensor value is 0).
Observation:
Conclusion:
In this Arduino sketch, an IR sensor connected to pin 12 is utilized to detect the presence of an object.
When the sensor detects an object (indicated by a LOW value), a buzzer connected to pin 7 is activated
to provide a notification. Conversely, when no object is detected (indicated by a HIGH value), the buzzer
is deactivated.
Quiz:
1. In the provided procedure, which pin is connected to the IR sensor for reading its output value?
Pin No: 12
2. In the provided code, what is the purpose of the digitalWrite(buzzer, HIGH); line?
In the provided code, the line digitalWrite(buzzer, HIGH); is responsible for activating the buzzer.
When executed, this line sets the digital pin connected to the buzzer (as specified by the variable buzzer)
to a HIGH state, which supplies voltage to the buzzer and causes it to produce sound. This line of code
is triggered when the IR sensor detects an object, indicating that the buzzer should be activated to provide
a notification.
5. In the procedure, what is the purpose of opening the serial monitor in the Arduino IDE?
In the provided procedure, opening the serial monitor in the Arduino IDE serves the purpose of monitoring
the output of the Arduino board.
When the serial monitor is opened, it displays the data sent by the Arduino board through the Serial.println()
statements in the code. This allows you to observe the sensor readings and any other debug information
printed by the Arduino sketch in real-time.
References:
https://www.tinkercad.com/lDashboard
https://wokwi.com/projects/new/arduino-uno
Circuit Setup
Code Sensor and Buzzer
and Quiz Performance Ethics
Understanding Activation
Connections
Goo Averag Good Averag Good Average Good Average Good Averag
d (2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)
Experiment No: 5
Aim: Measuring object distance using Ultrasonic Sensor and Arduino Uno.
Date:
Objectives:
1. Identify the key components of an Ultrasonic sensor and the necessary connections.
2. Build a circuit to connect an Ultrasonic sensor to an Arduino Uno.
3. Write Arduino code to measure object distance using the Ultrasonic sensor.
4. Interpret the distance data and display it on a connected output device (e.g., LCD or serial
monitor).
5. Understand the practical applications of distance measurement in IoT, robotics, and
automation.
Components:
Configuration:
Procedure:
Step 1: Setup the Circuit
1. Place the Ultrasonic sensor on one end of the breadboard so that none of the pins
are connected to each other.
2. Connect the "trigger" pin on the Ultrasonic sensor to pin 10 on the Arduino.
3. Connect the "echo" pin on the Ultrasonic sensor to pin 9 on the Arduino.
4. Connect the Ultrasonic Sensor's 5V pin to the 5V pin on the Arduino.
5. Complete the circuit by connecting the Ultrasonic Sensor's ground pin to the
Arduino's ground pin.
Step 2: Understanding the Ultrasonic Sensor
• The Ultrasonic sensor is capable of non-contact distance measurements in the
range of 2cm to 400cm, with a ranging accuracy of up to 3mm.
• It operates by emitting ultrasonic sound waves and measuring the time it takes for
the waves to bounce back after hitting an object, similar to how bats use
echolocation.
Step 3: Write and Upload the Arduino Code
• Open the Arduino Integrated Development Environment (IDE) on your computer.
• Write the following code:
Code:
const int trigger = 9;
const int echo = 10;
long duration;
int distance;
void setup() {
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
duration = pulseIn(echo, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
}
Code Explanation:
• The code initializes two constants, trigger (connected to pin 9) and echo
(connected to pin 10) to represent the trigger and echo pins of the Ultrasonic
sensor.
• In the setup () function, it sets the trigger pin as an OUTPUT and the echo pin as
an INPUT. It also initializes serial communication for monitoring.
• The loop() function sends a trigger signal, measures the echo response, calculates
the distance based on the time it takes for the signal to bounce back, and then prints
the distance to the serial monitor.
Step 4: Testing the Circuit
• Upload the code to your Arduino Uno.
• Open the serial monitor in the Arduino IDE to observe the measured distance
values.
Observation:
Conclusion:
In this Arduino sketch, an ultrasonic sensor (HC-SR04) is used to measure the distance of an object from
the sensor. The trigger pin of the sensor is connected to digital pin 9, and the echo pin is connected to
digital pin 10 of the Arduino Uno.
During the setup phase, the pins are configured appropriately, and serial communication is initialized at
a baud rate of 9600 baud.
In the loop function, the trigger pin is set LOW initially. Then, a short trigger pulse is sent by briefly
setting the trigger pin HIGH and then LOW again. The duration of the pulse received by the echo pin is
measured using the pulseIn function.
Quiz:
1. In the provided procedure, which pins on the Arduino are connected to the "trigger" and "echo" pins of
the Ultrasonic sensor?
For trigger, pin no: 9
For echo, pin no: 10
3. What is the purpose of the "trigger" pin on the Ultrasonic sensor in the code?
In the provided code, the Arduino sends a short pulse to the trigger pin, which prompts the ultrasonic
sensor to transmit an ultrasonic sound wave. This sound wave then travels to the object in front of the
sensor and reflects back. The sensor uses the echo pin to detect the reflected sound wave, and the time it
takes for the echo to return is measured.
4. In the code, what value is used to calculate the distance based on the time it takes for the echo signal to
return?
In the provided code, the distance is calculated based on the time it takes for the echo signal to return
using the formula:
~ Distance = duration × 0.034/2
5. What is the purpose of opening the serial monitor in the Arduino IDE when using the Ultrasonic sensor?
Real-time Distance Monitoring: The ultrasonic sensor measures the distance to an object, and the
Arduino board communicates this distance information to the serial monitor. Opening the serial monitor
allows you to view the distance readings in real-time as they are received from the sensor.
Debugging and Troubleshooting: If there are any issues with the sensor or the code, viewing the output
in the serial monitor can help with debugging and troubleshooting. You can observe the sensor readings
and identify any anomalies or unexpected behavior.
Calibration and Adjustment: By observing the distance readings in the serial monitor, you can calibrate
and adjust the sensor placement or code parameters as needed to achieve accurate distance
measurements. This iterative process can help fine-tune the sensor's performance for specific
applications.
References:
https://www.tinkercad.com/lDashboard
https://wokwi.com/projects/new/arduino-uno
Circuit Setup
Code Distance
and Quiz Performance Ethics
Understanding Measurement
Connections
Goo Averag Good Averag Good Average Good Average Good Averag
d (2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)
Experiment No: 6
Aim: Measuring moving object using PIR Sensor and Arduino Uno.
Date:
Objectives:
1. Identify the key components of a PIR sensor and the necessary connections.
2. Build a circuit to connect a PIR sensor to an Arduino Uno.
3. Write Arduino code to detect and respond to moving objects using the PIR sensor.
4. Interpret the motion data and trigger appropriate actions (e.g., turning on an LED or
sending a notification).
5. Understand the practical applications of motion detection in security systems and
automation.
Components:
Configuration:
The design of the PIR Motion Sensor using Arduino is very simple. The PIR Sensor Module has
three pins: VCC, Digital Out and GND. Connect VCC and GND to +5V and GND respectively.
Then connect the Digital Out Pin of the PIR sensor to the digital I/O pin 8 of Arduino.
As we need to indicate the detection of motion by the sensor, connect a buzzer to Pin 11 of the
Arduino.
Procedure:
1. When the system is powered on, the Arduino enters a calibration phase for the PIR sensor.
During this 10-second calibration period, the PIR sensor should not detect any motion.
2. After the calibration period, the PIR sensor is ready to detect any movement in front of it.
3. If the PIR sensor detects motion, its digital output pin (connected to Arduino Pin 8)
becomes HIGH.
4. Arduino detects the HIGH signal from the PIR sensor and activates the buzzer.
5. The buzzer remains active for 3 seconds (3000 milliseconds).
6. After the buzzer has been activated, it turns off when motion is no longer detected by the
PIR sensor.
Code:
int buzzer = 11;
int sensor = 8;
int led = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
digitalWrite(buzzer,LOW);
digitalWrite(sensor,LOW);
digitalWrite(led,LOW);
while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,HIGH);
}
void loop()
{
if(digitalRead(sensor)==HIGH)
{
digitalWrite(buzzer,HIGH);
delay(3000);
digitalWrite(buzzer,LOW);
while(digitalRead(sensor)==HIGH);
}
}
Code Explanation:
• The code initializes three variables: buzzer (connected to pin 11), sensor (connected
to pin 8), and led (connected to pin 13).
• In the setup() function, the code sets the pinMode for the buzzer as OUTPUT, the
sensor as INPUT, and the LED as OUTPUT. It also initializes these components with
LOW states.
• During the calibration period, the LED blinks every 100 milliseconds for 13 seconds.
• In the loop() function, the code continuously checks the state of the PIR sensor. If the
PIR sensor detects motion (HIGH signal), it activates the buzzer for 3 seconds and
then turns it off when motion is no longer detected.
Observation:
Conclusion:
In conclusion, the provided Arduino code aims to utilize a PIR sensor to detect motion and trigger a
buzzer along with an LED indicator. While the code structure appears functional for its intended purpose,
several areas could be improved for enhanced performance and clarity. Firstly, the timing mechanism
implemented with while(millis()<13000) to flash the LED for 13 seconds may cause unintended delays
in the execution of subsequent code. Replacing it with a more straightforward delay() function could
streamline the code and ensure consistent timing.
Secondly, the duration of the buzzer activation (3 seconds) might not be optimal for all applications.
Adjusting this duration to better suit specific requirements could improve the usability of the system.
Additionally, the code could benefit from comments to provide clarity on the purpose and functionality
of each section. Clear and concise comments can aid in understanding, debugging, and modifying the
code in the future.
Quiz:
1. In the provided project, how long is the calibration period for the PIR sensor?
In the provided project, the calibration period for the PIR sensor lasts for approximately 13 seconds. This
is achieved using a `while` loop combined with the `millis()` function to wait until 13 seconds have
elapsed before proceeding with the main operation of the system. During this calibration period, an LED
connected to pin 13 is flashed on and off as an indication that the system is initializing.
2. What happens when the PIR sensor detects motion in front of it in the provided project?
The PIR sensor's digital output pin, which is connected to pin 8 on the Arduino, goes HIGH, indicating
that motion has been detected.
As a result, the Arduino's code detects the HIGH signal from the PIR sensor in the loop() function.
The code then activates the buzzer connected to pin 11 by setting its output to HIGH, causing the buzzer
to emit a sound.
The buzzer remains active for a duration of 3 seconds, as specified in the code using the delay(3000)
function.
After the 3-second duration elapses, the buzzer's output is set LOW, turning off the buzzer.
The code enters a while loop to wait until the PIR sensor's output returns to LOW, indicating that motion
has ceased. During this time, the Arduino continuously checks the state of the PIR sensor.
Once the PIR sensor's output goes LOW, signifying the end of the motion event, the while loop is exited,
and the code returns to continuously monitor for further motion events.
3. Which pin on the Arduino is used to connect the PIR sensor's digital output pin in the project?
In the provided project, the PIR sensor's digital output pin is connected to pin 8 on the Arduino Uno. This
pin is configured as an input in the setup() function using the pinMode() function.
4. During the calibration period, how often does the LED connected to Pin 13 blink in the code?
The loop runs until 13 seconds have elapsed (millis() < 13000), toggling the LED state every 50
milliseconds. Therefore, within the 13-second calibration period, the LED connected to pin 13 will blink
approximately 13000/50 times, which is around 260 times.
5. In the project's code, for how many milliseconds is the buzzer activated when motion is detected by the
PIR sensor?
In the project's code, the buzzer is activated for a duration of 3000 milliseconds (3 seconds) when motion is
detected by the PIR sensor. This duration is specified in the delay(3000) function call within the if statement
that checks for motion detection.
References:
https://www.tinkercad.com/lDashboard
https://wokwi.com/projects/new/arduino-uno
PIR Sensor
Circuit Setup Activation
Code
and & Quiz Performance Ethics
Understanding
Connections Buzzer Activation
Duration
Goo Averag Good Averag Good Average Good Average Good Averag
d (2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)
Experiment No: 7
Aim: Measure temperature using DHT-11 sensor and send it to cloud ThingSpeak
using NodeMCU.
Date:
• Gain competency in working with DHT-11 sensors for temperature and humidity
measurements.
• Develop practical skills in interfacing a NodeMCU with sensors and cloud
platforms for IoT applications.
• Understand the application of IoT in real-world scenarios, including
environmental monitoring and data sharing in the cloud.
Objectives:
Components:
Configuration:
Code:
#include <DHT.h> // Including library for dht
#include <ESP8266WiFi.h>
String apiKey = "H38TEGNC0XKW43BB"; // Enter your Write API key from
ThingSpeak
const char *ssid = "how2electronics"; // replace with your wifi ssid and wpa2 key
const char *pass = "alhabibi";
const char* server = "api.thingspeak.com";
#define DHTPIN 0 //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates
delay(1000);
}
Code Explanation:
• The code includes libraries for the DHT sensor and ESP8266 WiFi.
• It defines the API key, WiFi credentials, and the ThingSpeak server.
• The DHT sensor is set up to read from pin D0 (NodeMCU's pin 0).
• The program establishes a connection to the Wi-Fi network using the provided credentials.
• In the loop, it reads temperature and humidity data from the DHT sensor.
• If the data is valid (not NaN), it connects to ThingSpeak and sends the data using an HTTP
POST request.
• The program prints the temperature and humidity data to the serial monitor.
• A delay of 15 seconds (or more) is added between updates, as ThingSpeak requires a
minimum delay.
Observation:
Conclusion:
The code continuously measures temperature and humidity using the DHT11 sensor and sends the data
to the ThingSpeak platform over Wi-Fi. It ensures that the data is sent in the correct format and respects
the minimum update interval required by ThingSpeak.
Quiz:
1. In the provided project, which pin is used to connect the DHT-11 sensor to the NodeMCU?
n the provided project, the DHT-11 sensor is connected to pin D3 (GPIO 0) of the NodeMCU, which is
defined as DHTPIN in the code.
3. According to the provided code, what is the minimum delay required between data updates when sending
data to ThingSpeak?
According to the provided code, the minimum delay required between data updates when sending data to
ThingSpeak is set to 15 seconds. This delay is enforced to comply with ThingSpeak's minimum update
interval requirement.
4. What should be edited in the code to specify your Wi-Fi network credentials?
Replace "your_wifi_ssid" with the SSID (name) of your Wi-Fi network, and "your_wifi_password"
with the password of your Wi-Fi network. This will allow the NodeMCU to connect to your Wi-Fi
network using the provided credentials.
5. In the code, what method is used to send data to ThingSpeak for cloud storage?
In the provided code, data is sent to ThingSpeak for cloud storage using an HTTP POST request. Here's the
relevant portion of the code
References:
https://www.tinkercad.com/lDashboard
https://wokwi.com/projects/new/arduino-uno
Circuit Setup
Code ThingSpeak
and Quiz Performance Ethics
Understanding Integration
Connections
Goo Averag Good Averag Good Average Good Average Good Averag
d (2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)
Experiment No: 8
Aim: Controlling Led ON/OFF by giving command from mobile phone. (Use cloud
ThingSpeak)
Date:
Objectives:
1. Identify the key components required for cloud-based IoT control using ThingSpeak.
2. Build a circuit that connects an LED to a microcontroller (e.g., Arduino) and configure
the microcontroller for cloud-based control.
3. Set up a ThingSpeak channel to receive control commands from a mobile phone.
4. Write code to receive commands from the ThingSpeak channel and control the LED based
on the commands sent from a mobile phone.
5. Use a mobile phone to send commands to ThingSpeak and observe the real-time control
of the LED.
Components:
Configuration:
Procedure:
4. Enter the channel name, description, and select Field 1. Click the checkbox and save
the channel.
5. Make a note of the Channel ID for later use in the Arduino code.
Step 2: Firmware
1. Write code in the Arduino IDE, selecting the NodeMCU 12E board.
2. Use the provided code to configure the NodeMCU for connecting to ThingSpeak.
3. Replace the SSID and password with your Wi-Fi network credentials.
4. Enter the ThingSpeak Channel ID in the code.
Channel ID: 1070593, it’s written in code.
5. Upload the code to the NodeMCU.
Code :
#include<ThingSpeak.h>
#include<ESP8266WiFi.h>
#include<ESP8266WebServer.h>
unsigned long channel_num=1070593;
HTML :
String SendHTML(void){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-
scale=1.0, user-scalable=no\">\n";
ptr +="<title>LED Control</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto;
text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3
{color: #444444;margin-bottom: 50px;}\n";
ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border:
none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px
auto 35px;cursor: pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: #1abc9c;}\n";
ptr +=".button-on:active {background-color: #16a085;}\n";
ptr +=".button-off {background-color: #34495e;}\n";
ptr +=".button-off:active {background-color: #2c3e50;}\n";
ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<h1>ESP8266 with ThingSpeak Server</h1>\n";
ptr +="<h3>Using Station(STA) Mode</h3>\n";
ptr +="<h4>Control status For D1</h4>\n";
ptr +="<a class=\"button button-on\"
href=\"https://api.thingspeak.com/update?api_key=MOHD33LYGVXTG5UF&field1=1\
">ON</a>\n";
ptr +="<a class=\"button button-off\"
href=\"https://api.thingspeak.com/update?api_key=MOHD33LYGVXTG5UF&field1=0\
">OFF</a>\n";
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
➢ That is my HTML code if you are an embedded engineer then do not learn the HTML
and CSS, but knowledge abut the how it work we press the any url.
➢ https://api.thingspeak.com/update?api_key=MOHD33LYGVXTG5UF&field1=
0 this url is copy from the thingserver here api_key is different in your case last one
&field1=0 mean we we press this url then send the 0 on your thingspeak server to the
field1 and &field1=1 mean when we press this url then send the 1 on your thingspeak
server to the field1. but we don't press the url using HTML code we only clink on the
ON button to turn on the led and OFF button for turn off the led.
➢ Now go to the thingspeak server click on the API KEYS and copy the Write API
KEY and paste the HTML code code which highlighted on the upper HTML code pic.
Step 5: Testing
1. Upload the code to the NodeMCU.
2. Verify that the NodeMCU connects to Wi-Fi, and note the local IP address.
3. Access the local IP address in a web browser.
4. Use the web interface to control the LED by clicking the ON and OFF buttons.
Observation:
Strengths:
It establishes a connection to Wi-Fi and ThingSpeak.
It reads data from ThingSpeak and controls the LED based on the received value.
It includes basic functionalities like pin setup and serial communication.
Overall:
The code is a good starting point for controlling an LED with ThingSpeak. By addressing the mentioned
points and customizing it based on your chosen mobile app approach, you can achieve a functional
remote LED control system.
Conclusion:
The provided code lays a solid foundation for controlling an LED via ThingSpeak and a mobile app. It
connects to WiFi, reads data from ThingSpeak, and controls the LED accordingly. However, there's
room for improvement:
Quiz:
3. In the HTML code for mobile control, what is the purpose of the "ON" and "OFF" buttons?
"ON" button sends a command (e.g., 1) to ThingSpeak (via mobile app).
ThingSpeak updates its field (e.g., "LED_State") with the new value (1).
Microcontroller code reads the update and turns on the LED.
Similarly, the "OFF" button sends a different command (e.g., 0) to turn the LED off.
4. Which component is responsible for handling HTTP requests and controlling the LED based on those
requests?
In the provided code, the component responsible for handling HTTP requests (not directly used in this
case) and controlling the LED is the microcontroller.
Mobile App: Sends control commands (not via HTTP in this code).
References:
https://thingspeak.com/
https://www.arduino.cc/en/software
Circuit Setup
Code
and HTML Interface Quiz Performance Ethics
Understanding
Connections
Good Averag Good Averag Good Average Good Average Good Averag
(2) e (2) e (1) (2) (1) (2) (1) (2) e (1)
(1)
Experiment No: 9
Aim: Controlling Led ON/OFF by giving commands using Google Assistant from a
mobile phone. (Use cloud Adafruit)
Date:
Objectives:
Components:
Configurations:
Procedure:
Step 1: Setting up Adafruit IO Account for IOT controlled LED
1. Visit https://io.adafruit.com and create an account.
2. After creating an account, you'll be taken to your home screen. Click on "Feeds" from the
menu.
3. Create a new feed by clicking on "New Feed." Name your feed (e.g., "LED_Control"),
provide a description if desired, select "Field 1," and save the channel.
4. Create a new dashboard by going to "Dashboards" from the menu. Give it a name (e.g.,
"LEDSwitch") and create the dashboard.
5. Open your new dashboard by clicking on it. Click the blue "+" button to add new UI
components to the dashboard.
6. Add a button to the dashboard by selecting the first option. Choose the feed you created
7. During programming, you will require your unique AIO key. Click on the key button at
the right-hand corner of your window to generate your active key for this project.
7. Create another applet for turning the LED "OFF" by following the same steps.
2. The code provided in the project can be used to connect the ESP32 to Adafruit IO. Modify
the WLAN_SSID, WLAN_PASS, AIO_USERNAME, and AIO_KEY in the code with
your credentials.
3. After modifying the code, upload it to the ESP32.
Code:
#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WLAN_SSID "Ashish"
#define WLAN_PASS "12345678"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "DURGESH_SINGH"
#define AIO_KEY "aio_OQrD206pQvpMfzJhKcPPXBnw79DL"
int output=2;
WiFiClient client; // Create an ESP8266 WiFiClient class to connect to the MQTT
server.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT,
AIO_USERNAME, AIO_KEY); // Setup the MQTT client class by passing in the
WiFi
client and MQTT server and login details.
Adafruit_MQTT_Subscribe LED_Control = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/LED_Control");
void MQTT_connect();
void setup() {
Serial.begin(115200);
delay(10);
pinMode(2,OUTPUT);
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
mqtt.subscribe(&LED_Control);
}
uint32_t x=0;
void loop() {
MQTT_connect();
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &LED_Control) {
Serial.print(F("Got: "));
Serial.println((char *)LED_Control.lastread);
if (!strcmp((char*) LED_Control.lastread, "ON"))
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
}
}
void MQTT_connect() {
int8_t ret;
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
4. The ESP32 will connect to Adafruit IO, and you'll be able to control the LED using Google
Assistant via the applets created in IFTTT.
5. After uploading of code open your serial monitor and your serial monitor should look like
this:
6. Now open Google assistant in your Android and give voice command like “Turn LED on”
or “Turn LED off” and it will respond you like you defined earlier and you will observe
change of LED state also.
Observation:
Pin Numbering: The code uses GPIO.BOARD mode for pin numbering, which means the pin numbers
refer to the physical pin numbers on the Raspberry Pi board.
LED Connection: The LED is connected to pin 8 of the Raspberry Pi. Make sure to connect it to the
correct pin physically.
Infinite Loop: The code utilizes an infinite loop (while True:) to continuously blink the LED on and off.
GPIO Output: The GPIO pin is set to high (GPIO.HIGH) to turn on the LED and low (GPIO.LOW) to
turn it off.
Timing: Each state (on/off) of the LED lasts for 1 second, as controlled by the sleep(1) function calls.
GPIO Cleanup: The code does not include GPIO cleanup. It's generally a good practice to clean up GPIO
resources using GPIO.cleanup() at the end of the script, especially if you plan to run multiple scripts or
interact with GPIO pins in other ways.
Overall, the code is concise and effectively accomplishes the task of blinking an LED using Raspberry
Pi GPIO pins.
Conclusion:
Based on your code and questions, it's clear that you're working on a project to control an LED using
Google Assistant commands via Adafruit IO and an ESP8266 device. Your code demonstrates the setup
for connecting to Wi-Fi, subscribing to an MQTT feed, and toggling the LED based on messages
received from Adafruit IO.
Overall, your code shows a good understanding of the necessary steps involved in setting up the
hardware and software components for this project. However, there are areas where you could further
improve the code, such as adding more comments for clarity, enhancing error handling, and
implementing a feedback mechanism to confirm LED state changes.
Quiz:
1. Trigger: The "If This" part of the applet is triggered by a specific event, which in this case, is a voice
command issued to Google Assistant. For example, you might set up a trigger that activates when you
say "Turn on the LED" to Google Assistant.
2. Action: The "Then That" part of the applet defines the action to be taken when the trigger event occurs.
In this project, the action is to send a request to Adafruit IO to update the LED control feed with the
corresponding command (e.g., "ON" to turn the LED on or "OFF" to turn it off).
3. Integration: Through IFTTT's platform, you can create an applet that links Google Assistant as the trigger
service and Adafruit IO as the action service. You'll need to provide authentication credentials for both
services to enable communication between them.
4. Execution: When you issue the voice command to Google Assistant, the applet is triggered, and IFTTT
sends a request to Adafruit IO with the appropriate command. Adafruit IO then forwards the command
to your ESP8266 device, which interprets it and controls the LED accordingly.
3. Which service is used to set up voice commands for Google Assistant in this project?
In this project, the service used to set up voice commands for Google Assistant is IFTTT (If This Then
That). IFTTT provides a platform where users can create conditional statements, called applets, that
trigger actions based on specific events. In this case, the trigger event is a voice command issued to
Google Assistant, such as "Turn on the LED."
By creating an applet on IFTTT, users can define the trigger event as a specific phrase or command
spoken to Google Assistant. When Google Assistant recognizes this trigger, it activates the
corresponding applet, which then executes the defined action. In this project, the action is sending a
request to Adafruit IO to update the LED control feed based on the voice command received.
4. What is the role of the unique AIO key generated in the Adafruit IO setup?
The unique AIO key generated in Adafruit IO setup serves as a secure authentication mechanism for allowing
authorized access to Adafruit IO services from your IoT device. It ensures secure communication, authorizes
specific actions, and enables tracking and management of usage and access rights.
References:
https://www.adafruit.com/category/17
https://www.arduino.cc/en/software
Experiment No: 10
Date:
Objectives:
Components:
• Raspberry Pi (any model with GPIO pins)
• MicroSD card (for Raspbian OS)
• Power supply for Raspberry Pi
• LED
• Resistor (appropriate value to limit LED current)
• Jumper wires
• Breadboard (optional, for easier circuit connections)
Configuration:
Circuit Setup:
1. Create a simple LED circuit, consisting of an LED and a current-limiting resistor.
2. Calculate the resistor value to limit current based on LED specifications (forward
voltage and forward current) and Raspberry Pi output voltage.
3. Round up the resistor value (e.g., 100 ohms) and use a resistor with the appropriate
color code.
4. Connect the LED and resistor in series with GPIO pin 8 on the Raspberry Pi.
5. Pay attention to the LED's polarity – the long lead (anode) connects to the resistor, and
the short lead (cathode) connects to ground (pin 6 on the Raspberry Pi).
Python Code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW)
while True:
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1)
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1)
Observation:
Pin Numbering: The code uses GPIO.BOARD mode for pin numbering, which means the pin numbers
refer to the physical pin numbers on the Raspberry Pi board.
LED Connection: The LED is connected to pin 8 of the Raspberry Pi. Make sure to connect it to the
correct pin physically.
Infinite Loop: The code utilizes an infinite loop (while True:) to continuously blink the LED on and off.
GPIO Output: The GPIO pin is set to high (GPIO.HIGH) to turn on the LED and low (GPIO.LOW) to
turn it off.
Timing: Each state (on/off) of the LED lasts for 1 second, as controlled by the sleep(1) function calls.
GPIO Cleanup: The code does not include GPIO cleanup. It's generally a good practice to clean up GPIO
resources using GPIO.cleanup() at the end of the script, especially if you plan to run multiple scripts or
interact with GPIO pins in other ways.
Overall, the code is concise and effectively accomplishes the task of blinking an LED using Raspberry
Pi GPIO pins.
Conclusion:
Based on the provided code and its execution, the experiment demonstrates a simple yet effective way
to control an LED using a Raspberry Pi and its GPIO pins. The observations indicate that the code
successfully achieves the desired functionality of blinking the LED on and off at regular intervals.
However, to draw a comprehensive conclusion, it's important to consider a few additional points:
1. Verification of Physical Setup: While the code provides instructions on how to connect the LED to the
Raspberry Pi, it's crucial to physically verify that the connections are made correctly to avoid any issues
or potential damage.
2. Error Handling and Robustness: The provided code lacks error handling mechanisms, such as handling
unexpected exceptions or GPIO errors. Incorporating error handling would enhance the robustness of
the code, making it more reliable in diverse operating conditions.
3. GPIO Resource Management: Although not explicitly mentioned in the provided code, it's imperative to
manage GPIO resources properly, especially when running multiple scripts or interacting with GPIO
pins in various applications. This includes cleaning up GPIO resources using `GPIO.cleanup()` to release
resources after the script execution.
4. Documentation and Comments: While the code is relatively straightforward, including detailed
comments and documentation would improve its readability and facilitate understanding, especially for
beginners or individuals unfamiliar with Raspberry Pi GPIO programming.
In conclusion, the experiment effectively demonstrates the basic concept of interfacing hardware with
the Raspberry Pi using GPIO pins and provides a foundation for more advanced projects and
explorations in physical computing and embedded systems.
Quiz:
2. What is the forward voltage (VF) and forward current (IF) of a typical red LED?
Forward Voltage (Vf): The forward voltage of a red LED typically ranges from around 1.8 to 2.2 volts.
This is the voltage required for the LED to turn on and begin conducting current.
Forward Current (If): The forward current of a red LED is typically in the range of 10 to 20 milliamps
(mA). This is the current that flows through the LED when it is forward-biased and emitting light at its
specified brightness level.
3. In the Raspberry Pi GPIO setup code, what does GPIO.BOARD refer to?
In the Raspberry Pi GPIO setup code, GPIO.BOARD refers to one of the numbering schemes used to
identify the GPIO pins on the Raspberry Pi.
When you set the mode to GPIO.BOARD, it means you're using physical pin numbers to reference the
GPIO pins. Each GPIO pin on the Raspberry Pi has a corresponding physical pin number on the GPIO
header. This numbering scheme provides a straightforward way to identify and reference the GPIO pins
based on their physical location on the Raspberry Pi board.
In contrast, the other numbering scheme is GPIO.BCM, which stands for Broadcom SOC channel. When
using GPIO.BCM, you reference the GPIO pins by their Broadcom SOC channel numbers, which are
assigned by the Broadcom processor manufacturer. This numbering scheme is often preferred for its
consistency across different Raspberry Pi models.
References:
https://www.raspberrypi.com/documentation/
https://www.magpi.com/
https://www.adafruit.com/category/17
Understanding Command
Python Script Quiz Performance Ethics
of LED Circuit Execution
Good Averag Good Averag Good Average Good Average Good Averag
(2) e (1) (2) e (1) (2) (1) (2) (1) (2) e (1)