r22 Iot Lab Manual Final1
r22 Iot Lab Manual Final1
r22 Iot Lab Manual Final1
INTRODUCTION TO RASPBERRY PI
RASPBERRY PI:
• Raspberry Pi 1 Model A
• Raspberry Pi 1 Model A+
• Raspberry Pi 1 Model B
• Raspberry Pi 1 Model B+
• Raspberry Pi 2 Model B
• Raspberry Pi 3 Model B
• Raspberry Pi 4 Model B
Department of Information & Technology Page 2
INTERNET OF THINGS LAB
• Raspberry Pi Zero
The Processor
USB Ports
Raspberry Pi comes with four (TWO 3.0 + TWO 3.0) ports. The USB ports on
Raspberry Pi can provide a current up to 100mA. The VLI VL805 which
provides a USB 3.0 Hub over a PCI Express bus.
Ethernet Ports:
The Raspberry Pi 4 board has both ‘real’ Gigabit Ethernet and two USB 3.0
ports as well as a couple more ‘legacy’ USB 2 ports.
Wireless Support
The Memory
For completeness the final big bit of silicon—located just to the right of the
main processor package—is the LPDDR4 SDRAM for the board which comes
in the shape of a Micron FBGA-packaged chip
Power Input:
HDMI Output:
The HDMI port on Raspberry Pi provides both video and audio output. We
can connect the Raspberry Pi to a monitor using an HDMI cable. For
monitors that have a DVI (Digital Video interface) port but no HDMI port, we
can use an HDMI to DVI adapter/cable.
The RCA jack can be used to connect old televisions that have an RCA input
only.
GPIO Pins:
The DSI interface can be used to connect an LCD panel to Raspberry Pi.
StatusLED Function
ACT SDcard access
PWR 3.3VPowerispresent
FDX FullduplexLAN connected
LNK Link/Networkactivity
100 100MbitLANconnected
SD Card Slot:
Raspberry Pi does not have a built-in operating system and storage. SD card
slot on the Raspberry Pi 3 is located just below the Display Serial Adapter on
the other side. We can plug-in an SD card loaded with a Linux image to the
SD card slot.
Raspberry Pi 4 has come up with more advanced features than the previous
Raspberry Pi model. It was launched in June 2019 and has come up with a
much-improved processing speed of about 90% as compared to the previous
version due to the inclusion of 4GB and 8GB RAM memory. Its General-
Purpose Input Output (GPIO) pins have also maintained the previous
standard set by the Raspberry Pi models, and are now more functional and
performing flawlessly.
The Raspberry Pi 4 has 40 GPIO pins that can be configured to read inputs
or write outputs.
Here, we will be able to learn the functioning of each pin, which helps you to
do things on Raspberry Pi 4. There are 40 pins in this model and among
them, 26 are GPIO pins.
The Raspberry Pi model includes two 5V pins, two 3.3V pins, eight ground
pins and two reserved pins.
5V pins: The 5V pins are used to output the 5V power supply provided by
the Type-C port. The pins are numbered 2 and 4 on the Raspberry Pi 4
device.
3.3V pins: The 3.3V pins provide a 3.3V power supply to the external
components, numbered 1 and 17.
Department of Information & Technology Page 6
INTERNET OF THINGS LAB
Ground pins: The ground pins are used to close the electric circuits. The
ground pins help you to protect your board from burning and play an
important part in a circuit. The ground pins are numbered
6,9,14,20,25,30,34 and 39.
Reserved Pins: These pins are used to perform communication between I2C
and EEPROM. If you are new to Raspberry Pi, you are advised not to
connect anything with these pins, which are 27 and 28 number pins.
GPIO Pins
These are the pins on your Raspberry Pi that perform various functions and
each pin is assigned a different task. Some pins are used as inputs, while
others are used as outputs. Input voltages ranging from 1.8V to 3V are
considered high voltage, while voltages less than 1.8V are considered low
voltage. You need to keep the voltage of the power supply below 3V to
protect your Raspberry Pi from burning.
The GPIO pins are used for Pulse Width Modulation (PWM), which is the
process of converting a Digital signal to an Analog signal. All pins can
perform software PWM, but only a few can perform hardware PWM,
including GPIO pins 12, 13, 18, and 19.
You can use Serial Peripheral Interface (SPI) pins to communicate between
devices such as sensors or actuators on the Raspberry Pi. The Raspberry Pi
sends data to a device via the Master Out Slave Pin (MOSI), and the same
device communicates with the Raspberry Pi via the Master In Slave Out
(MISO) pin. SP communication necessitates using five GPIO pins for GND,
SCLK, MOSI, MISO, and CE. The CE pin is used to enable or disable circuit
integration, whereas the SCLK pin serves as a clock for SPI communication.
The Raspberry Pi’s SPI communication pins are listed below.
For SPIO select GPIO9 as MISO, GPIO10 as MOSI, GPIO11 as SCLK, GPIO8
as CE0 and GPIO7 as CE1.
For the case of SPI1 pins, select GPIO19 as MISO, GPIO20 as MOSI, GPIO21
as SCLK, GPIO18 as CE0, GPIO17 as CE1, and GPIO16 as CE2.
Using the Inter-Integrated Circuit (I2C) pins, the Raspberry Pi can control
other peripheral devices attached to it. The communication is possible using
the pins Serial Data (SDA) and Serial Clock (SCL). The data is forwarded
using the SDA pin and the processing speed of data is controlled using the
SCL pin. There is another type of data called “Electrically erasable
programmable read-only memory (EEPROM)” data, which is in small
quantities
In Raspberry Pi, the GPIO2 pin is responsible for transferring data using
SDA, and GPIO3 controls data speed by working as SCL. For the case of
EEPROM, the GPIO0 pin is used for data transferring while the GPIO1 pin is
used as a clock to control the speed of data.
There are four more additional pins you can use for UART communication.
However, you should need to enable them to use them. Among these pins,
three are of type PL011 (main UART for models without Bluetooth) while the
UART1 is of type mini UART (UART for models with Bluetooth). The following
is the list of pins that are using UART communication:
• One of the famous libraries in launching input and output pins is the
RPi.GPIO libraryin python programming.
• Use the RPi.GPIO module as the driving force behind our Python GPIO
examples. This set of Python files and source is included with
Raspbian OS –NOOBS, (Linux based)
Example:
Note: Both the import and setmode lines of code are required, if you want to
use Python.
Note: Remember that the pin number will change if you're using the board
numbering system (instead of 18, it'd be 12).
Basic Commands
Components required:
• Raspberry Pi 4
• Micro SD Card
• Power Supply
• HC-SR04 Ultrasonic Sensor
• 1k OHM Resistor
• 2k OHM Resistor
• Breadboard
• Jumper Wires
Working Process:
The only slightly complicated part of wiring the device to the Raspberry Pi is
the voltage divider that connect for the echo pin.
The reason for adding a voltage divider is to drop the voltage going to the
GPIO pins down to 3.3v from 5v. To achieve this by utilizing a 1k Ω resistor
and a 2k Ω resistor.
Connections:
• Run a wire from the ground pin (Pin 6) to the ground/negative rail on
the breadboard.
• Run a wire from 5v pin (Pin 2) to the VCC pin on the HC-SR04
distance sensor.
• Run a wire from pin 7 to the TRIG pin on the distance sensor.
• Run a 1k Ω resistor from the ECHO pin on the distance sensor to a
spot on the breadboard.
• Run a 2k Ω resistor from the 1k Ω resistor to the ground/negative rail
on the Raspberry Pi.
• Run a wire from between the 1k Ω resistor and the 2k Ω resistor to
pin 11 on the Raspberry Pi.
Source Code:
import time
try:
GPIO.setmode(GPIO.BOARD)
PIN_TRIGGER = 7
PIN_ECHO = 11
GPIO.setup(PIN_TRIGGER, GPIO.OUT)
GPIO.setup(PIN_ECHO, GPIO.IN)
GPIO.output(PIN_TRIGGER, GPIO.LOW)
time.sleep(2)
GPIO.output(PIN_TRIGGER, GPIO.HIGH)
time.sleep(0.00001)
GPIO.output(PIN_TRIGGER, GPIO.LOW)
pulse_start_time = time.time()
pulse_end_time = time.time()
print "Distance:",distance,"cm"
finally:
GPIO.cleanup()
OUTPUT:
Calculating distance
Distance: 29.69 cm
Required Components:
Procedure:
Source Code:
import RPi.GPIO as G
import time
G.setmode(G.BOARD)
Department of Information & Technology Page 14
INTERNET OF THINGS LAB
G.setup(8, G.OUT)
while True:
G.output(8, True)
time.sleep(2)
G.output(8, False)
time.sleep(2)
OUTPUT:
2. INTRODUCTION TO ARDUINO
Arduino:
key features:
• 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.
• Able to control the board functions by sending a set of instructions to
the microcontroller on the board via Arduino IDE (referred to as
uploading software).
• 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.
• The Arduino IDE uses a simplified version of C++, so making it easier
to learn to program.
Arduino Boards:
There are entry level boards like the UNO, LEONARDO, NANO etc; boards
with enhanced feature like the MEGA, PRO, ZERO etc; boards for Internet of
Things like the YUN, TIAN etc; and wearable boards like the LILYPAD,
GEMMA etc.
• A USBcable
• An external AC-DC adapter (output voltage of the adapter must be
fixed and within the range of 7V to 12V). Adapter needs to be plugged
into the power jack.
• A battery (Fixed voltage, the voltage must be in the range of 7V to
12V). Battery terminals must be connected between VIN and GND
pins on the board.
Microcontroller:
Voltage Regulator:
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and
other elements.
Crystal Oscillator
Ceramic Resonators
Arduino Reset
To reset Arduino board, i.e., start the program from the beginning or when
uploading new program. Reset can work in two ways. First, by using the
Reset button on the board, second, you can connect an external reset
button to the Arduino pin labeled as RESET.
Most of the components used with Arduino board works fine with 3.3 volt
and 5 volts.
• GND (Ground) − There are several GND pins on the Arduino, any of
which can be used to ground your circuit. The ground pin acts as a
pin with zero voltage.
• Vin − It is the input voltage. This pin also can be used to power the
Arduino board from an external power source, like AC mains power
supply.
Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These
pins can read the signal from an analog sensor like the humidity sensor or
temperature sensor and convert it into a digital value that can be read by
the microprocessor. The analog pins can be used as digital I/O pins as well
if there is no analog input to be measured.
ICSP pin
The In-Circuit Serial Programming pin allows the user to program using the
firmware of the Arduino board. Is a tiny programming header for the
Arduino consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often
referred to as an SPI (Serial Peripheral Interface), which could be considered
as an "expansion" of the output. Means, for slaving the output device to the
master of the SPI bus.
The ON status of LED should light up when plug the Arduino into a power
source to indicate that the board is powered up correctly. If this light does
not turn on, then there is something wrong with the connection.
TX and RX
On the board, you will find two labels: TX (transmit) and RX (receive). They
appear in two places on the Arduino UNO board. First, at the digital pins 0
and 1, to indicate the pins responsible for serial communication
Second, the TX and RX led. The TX LED flashes with different speed while
sending the serial data. The speed of flashing depends on the baud rate
used by the board. RX flashes during the receiving process.
Digital I/O
The Arduino UNO board has 14 digital I/O pins (of which 6 provide PWM
(Pulse Width Modulation) (pins 3,5,6,9,10 and 11) output. These pins can be
configured to work as inputdigital pins to read logic values (0 or 1) or as
digital output pins to drive different modules like LEDs, relays, etc. The pins
labeled “~” can be used to generate PWM.
AREF
USB
The following steps shown how to set up the Arduino IDE on our computer
and prepare the board to receive the program via USB cable.
Step 1 − First you must have Arduino board and a USB cable. For Arduino
UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or Diecimila, you
will need a standard USB cable (A plug to B plug), as shown in the following
image.
You can get different versions of Arduino IDE from the Download page on
the Arduino Official website. You must select your software, which is
compatible with your operating system (Windows, IOS, or Linux). After your
file download is complete, unzip the file.
The Arduino UNO automatically draw power from either, the USB
connection to the computer or an external power supply. Connect the
Arduino board to your computer using the USB cable. The power LED
(labeled ON) should glow.
After your Arduino IDE software is downloaded, you need to unzip the
folder. Inside the folder, you can find the application icon with an infinity
label (application.exe). Double-click the icon to start the IDE.
Here, we are selecting just one of the examples with the name Blink. It turns
the LED on and off with some time delay.
To avoid any error while uploading your program to the board, you must
select the correct Arduino board name, which matches with the board
connected to your computer.
Select the serial device of the Arduino board. Go to Tools → Serial Port
menu. This is likely to be COM3 or higher (COM1 and COM2 are usually
reserved for hardware serial ports). To find out, you can disconnect your
Arduino board and re-open the menu, the entry that disappears should be
of the Arduino board. Reconnect the board and select that serial port.
Before going to know how to upload the program to the board, we must
know the function of each symbol appearing in the Arduino IDE toolbar.
F − Serial monitor used to receive serial data from the board and send the
serial data to the board.
Now, simply click the "Upload" button in the environment. Wait a few
seconds; you will see the RX and TX LEDs on the board, flashing. If the
upload is successful, the message "Done uploading" will appear in the status
bar.
2. USING ARDUINO
Hardware Requirements
Software requirements
• Arduino software
Arduino
Ultrasonic Sensor
We know that the speed of sound in air is nearly 344 m/s or 0.034 cm/µs,
So, the known parameters are time and speed (constant). Using these
parameters, we can calculate the distance traveled by the sound wave.
the “duration” variable stores the time taken by the sound wave traveling
from the emitter to the receiver. That is double the time to reach the object,
whereas the sensor returns the total time including sender to object and
object to receiver. Then, the time taken to reach the object is half of the time
taken to reach the receiver.
Setup:
• Connect the Echo pin of the sensor to the D2 pin of the Arduino.
• Connect the Trig pin of the sensor to the D3 pin of the Arduino.
• Navigate to Tools and select board and port.
• Verify and compile the code, then upload the code to the Arduino Uno
R3 board.
• Monitor the output in the Serial monitor (Set the baud rate as 9600).
To open Serial monitor Tools>Serial Monitor
Source Code
void setup ()
delay (500);
void loop ()
// If pulse reached the receiver echoPin become high Then pulseIn() returns
the time taken by the pulse to reach the receiver
delay (100);
OUTPUT:
Components Required
• 1 X LED
• 1 X Resistor, 330 Ohm
• Breadboard
• Arduino UNO R4 or earlier versions.
• Jumper wires
LED
Blinking an LED
Setup:
• LED Connections: Connect the LED to the breadboard. The LED has
two legs, the longer of which is the anode (positive) and the shorter of
which is the cathode (negative).
• Resistor Connection: Insert one end of the resistor into the same row
of the breadboard as the LED’s Anode. The resistor’s other end should
be connected to the Arduino’s digital output pin.
• Ground (GND) Connection: Connect a jumper wire from the same row
as the LED’s cathode to any Arduino board GND (Ground) pin. This
connects the circuit to the ground of the Arduino.
Source Code
void setup() {
pinMode(LEDpin, OUTPUT);
void loop() {
digitalWrite(LEDpin, HIGH);
delay(2000);
digitalWrite(LEDpin, LOW);
delay(2000);
OUTPUT:
Components Required
• 1 X DHT11 Sensor
• 1 X Resistor, 330 Ohm
• Breadboard
• Arduino UNO R4 or earlier versions.
• Jumper wires
DHT11 Sensor
The DHT11 module has a total of 3 pins. In which two are for power and one
is for communication. The pinout of a DHT11 Sensor module is as follows:
+(VCC)pin provides power to the sensor. Despite the fact that the supply
voltage of the module ranges from 3.3V to 5.5V, a 5V supply is
recommended. With a 5V power supply, the sensor can be placed up to 20
meters away. With 3.3V supply voltage, the sensor can be placed just 1
meter away; otherwise, the line voltage drop will cause measurement errors.
The DHT sensors has their own proprietary single-wire data transfer
protocol. This protocol requires precise timing. using the DHT library, which
handles almost everything.
To install the library, navigate to Sketch > Include Library > Manage
Libraries… Wait for the Library Manager to download the libraries index and
update the list of installed libraries.
Filter your search by entering ‘DHT sensor library’ then find DHT Sensor
Library by Adafruit. Click on that and then choose Install all.
SOURCE CODE
#include <dht11.h>
#define DHT11PIN 4
void setup ()
Serial.begin(9600);
dht11.begin();
void loop()
delay(2000);
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(tempC);
Serial.println("0C ");
Serial.print(tempF);
Serial.println("0F"); }
OUTPUT:
Component’s Required
Connecting the Trig pin to GPIO 5 and the Echo pin to GPIO 18, but you can
use any other suitable pins.
There’s an add-on for the Arduino IDE that allows to program the ESP32
using the Arduino IDE and its programming language.
• Copy and paste the following line to the Additional Boards Manager
URLs field.
o https://raw.githubusercontent.com/espressif/arduino-
esp32/gh-pages/package_esp32_index.json
Note: if you already have the ESP8266 boards URL, you can separate the
URLs with a comma, as follows:
o http://arduino.esp8266.com/stable/package_esp8266com_i
ndex.json,
• Open the Boards Manager. You can go to Tools > Board > Boards
Manager… or you can simply click the Boards Manager icon in the
left-side corner
• Search for ESP32 and press the install button for esp32 by Espressif
Systems
You should select your ESP32 board model and the COM port. In our
example, we’re using the DOIT ESP32 DEVKIT V1 board. Click OK when
you’re done.
SOURCE CODE
long duration;
float distanceCm;
float distanceInch;
void setup() {
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
// Convert to inches
Serial.println(distanceCm);
Serial.println(distanceInch);
delay(1000);
OUTPUT
Components Required
• 1 X LED
• 1 X 100Ω Resistor
• Breadboard
• ESP32 Development Board.
• Jumper wires
LED
ESP32
Blinking an LED
Setup:
• Connect the negative pin (cathode) of the LED, indicated as the flat
edge of the LED to ground, shown as the blue wire.
• Connect the positive pin (anode) of the LED, indicated as the rounded
edge of the LED to a 100Ω resistor.
• Connect the free end of the resistor to pin D5 on the ESP32, shown as
the red wire
SOURCE CODE
void setup() {
Department of Information & Technology Page 42
INTERNET OF THINGS LAB
void loop() {
OUTPUT:
Components Required
• 1 X DHT11 Sensor
• 1 KΩ Pullup Resistor
• Breadboard
• ESP32 DevKit Development Board
• Jumper wires
• Micro USB Cable
DHT11 Sensor
The DHT11 module has a total of 3 pins. In which two are for power and one
is for communication. The pinout of a DHT11 Sensor module is as follows:
+(VCC) pin provides power to the sensor. Despite the fact that the supply
voltage of the module ranges from 3.3V to 5.5V, a 5V supply is
recommended. With a 5V power supply, the sensor can be placed up to 20
meters away. With 3.3V supply voltage, the sensor can be placed just 1
meter away; otherwise, the line voltage drop will cause measurement errors.
DATA pin is used for communication between the sensor and the
microcontroller.
Setup:
The DHT sensors has their own proprietary single-wire data transfer
protocol. This protocol requires precise timing. using the DHT library, which
handles almost everything.
In the search bar, enter ‘DHT’. Scroll through the options and install ‘DHT
sensor library’ by Adafruit.
• The next library is associated with the Adafruit itself. Search for
‘adafruit unified’, scroll down and install ‘Adafruit Unified Sensor’
library.
SOURCE CODE:
#include "DHT.h"
#define DHT11PIN 16
DHT dht(DHT11PIN, DHT11);
void setup()
{
Serial.begin(115200);
/* Start the DHT11 Sensor */
dht.begin();
}
void loop()
{
float humi = dht.readHumidity();
float temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("ºC ");
Serial.print("Humidity: ");
Serial.println(humi);
delay(1000);
}
OUTPUT:
4. INSTALLING OS ON RASPBERRY PI
Required Components:
• Raspberry Pi Board
• USB power adapter like the official Raspberry Pi 4 power supply
• microSD card (at least 8GB, but preferably 16 or 32GB)
• USB card reader
• Keyboard (wired or perhaps one of the best wireless keyboards)
• Mouse
• Monitor or TV
• Micro HDMI to HDMI cable
• Click on the link for the Raspberry Pi Imager that matches your
operating system
• If this pops up, click on More info and then Run anyway
• Follow the instructions to install and run the Raspberry Pi Imager
• Insert your SD card into the computer or laptop SD card slot
•
Department of Information & Technology Page 49
INTERNET OF THINGS LAB
• In the Raspberry Pi Imager, select the OS that you want to install and
the SD card you would like to install it on
Note: You will need to be connected to the internet the first time for the
Raspberry Pi Imager to download the OS that you choose. That OS will then
be stored for future offline use. Being online for later uses means that the
Raspberry Pi imager will always give you the latest version.
• Fill in settings fields as follows and then hit Save. All of these fields
are technically optional, but highly recommended so that can get your
Raspberry Pi set up and online as soon as you boot it. If you don't set
a username and password here, you'll have to go through a setup
wizard that asks you to create them on first boot.
• Set hostname: the name of your Pi. It could be "raspberry pi" or
anything you like.
• Enable SSH: Allow SSH connections to the Pi. Recommended.
• Use password authentication / public key: method of logging in via
SSH
• Set username and password: Pick the username and password you'll
use for the Pi
Department of Information & Technology Page 51
INTERNET OF THINGS LAB
• Configure wireless LAN: set the SSID and password of Wi-Fi network
• Wireless LAN country: If you're setting up Wi-Fi, you must choose
this.
• Set locale settings: Configure keyboard layout and time zone (probably
chosen correctly by default)
• Once you get the following message, you can eject your SD card
After you're done writing the Raspberry Pi OS to a microSD card, it's time for
the moment of truth.
• Set your country and language and click Next. The default choices
may already be the correct ones
• Enter a username and password you wish to use for your primary
login. Click Next
• Select the appropriate Wi-Fi network on the screen after, provided that
you are connecting via Wi-Fi. If you don't have Wi-Fi or are using
Ethernet, you can skip this.
• Enter your Wi-Fi password (unless you were using Ethernet and
skipped)
• Click Next when prompted to Update Software. This will only work
when you are connected to the Internet, and it can take several
minutes. If you are not connected to the Internet, click Skip.
• Click Restart
If you wish to change these settings later, you can find the region and
password settings, along with many other options, by clicking on the Pi icon
in the upper left corner of the screen and navigating to Preferences ->
Raspberry Pi Configuration. You can configure Wi-Fi by clicking on the Wi-Fi
/ network icon on the taskbar
Required Components:
Procedure:
Using apt:
Using pip:
AIM: Blinking an LED connected to one of the GPIO Pin using GPIO-
Zero
Required Components:
Procedure:
Source Code:
while True:
led.on()
sleep(1)
led.off()
sleep(1)
OUTPUT
Required Components:
• Raspberry Pi 4 controller.
• Monitor/Laptop.
• And other connecting wires such as (Ethernet Cable, HDMI Cable, &
powering cable for both Raspberry Pi and Monitor, etc.)
• LED of any color.
• Jumper Wire.
• Bread-board.
• Resistor 100 Ohm
Process:
Connection:
SOURCE CODE:
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
p = GPIO.PWM(11, 100) //11 is pin number and 100 is max range of PWM.
p.start(0) //Starting point of PWM signal you can select any value between 0
to 100.
while True:
p.ChangeDutyCycle(x)
time.sleep(0.1)
p.ChangeDutyCycle(x)
time.sleep(0.1)
OUTPUT:
Components Required
• 1 X DHT11 Sensor
• Breadboard
• Raspberry Pi 4 Model B
• Jumper wires
• Power Supply
• Computer
DHT11 Sensor
The DHT11 module has a total of 3 pins. In which two are for power and one
is for communication. The pin-out of a DHT11 Sensor module is as follows:
+(VCC) pin provides power to the sensor. Despite the fact that the supply
voltage of the module ranges from 3.3V to 5.5V, a 5V supply is
recommended. With a 5V power supply, the sensor can be placed up to 20
meters away. With 3.3V supply voltage, the sensor can be placed just 1
meter away; otherwise, the line voltage drop will cause measurement errors.
DATA pin is used for communication between the sensor and the
microcontroller.
SETUP:
Connect the VCC and GND pins of the DHT11 Sensor to +5V and GND of
Raspberry Pi and then connect the Data OUT of the Sensor to the GPIO4 i.e.
Physical Pin 7 of the Raspberry Pi.
• First step is to download the library from GitHub. Enter the following
command to download the files related to the Adafruit_DHT library
• In that folder, there is file called ‘setup.py’. We need to install this file
using the following command.
SOURCE CODE
import sys
import Adafruit_DHT
import time
while True:
time.sleep(1)
OUTPUT:
ADDITIONAL EXPERIMENTS
Components Required
• Jumper wires
• 5 mm LED: Red
• 5 mm LED: Green
• Breadboard (generic)
• Arduino UNO
• 5 mm LED: Yellow
• Arduino IDE
Working
The LED have been powered by Arduino UNO (Board). It contains a code
which uploaded to the board. And once it simulated LED Start's blinking
like a traffic light. In this 15 Second will for Red Light 6 Second for Yellow
Light (In my Project Blue) and 20 Second for Green Light.
Connections
• Hook the GND pin (Negative Pin) of all led to Pin GND of Arduino.
• Connect Red LED VCC Pin (Positive Pin) to Pin 9 of Arduino.
• Connect Yellow LED VCC Pin (Positive Pin) to Pin 8 of Arduino.
• Connect Green LED VCC Pin (Positive Pin) to Pin 7 of Arduino
SOURCE CODE:
int red = 9;
int yellow = 8;
int green = 7;
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
void loop(){
digitalWrite(red, HIGH);
delay(15000);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(green, HIGH);
delay(20000);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
OUTPUT:
SERVO MOTOR
Servo motors are devices that can turn to a specified position. Usually, they
have a servo arm that can turn 180 degrees. Using the Arduino, if we specify
a servo to go to a specified position and it will go there.
Servo motors were first used in the Remote Control (RC) world, usually to
control the steering of RC cars or the flaps on a RC plane. With time, they
found their uses in robotics, automation
A servo motor has everything built in: a motor, a feedback circuit, and most
important, a motor driver. It just needs one power line, one ground, and one
control pin
CONNECTIONS
• The servo motor has a female connector with three pins. The darkest
or even black one is usually the ground. Connect this to the Arduino
GND.
• Connect the power cable that in all standards should be red to 5V on
the Arduino.
• Connect the remaining line on the servo connector to a digital pin on
the Arduino
The following code will turn a servo motor to 0 degrees, wait 1 second, then
turn it to 90, wait one more second, turn it to 180, and then go back.
SOURCE CODE
void setup () {
Department of Information & Technology Page 70
INTERNET OF THINGS LAB
void loop () {
delay (1000);
delay (1000);
delay (1000);
OUTPUT