0% found this document useful (0 votes)
35 views56 pages

Iot Lab Manual

The document outlines practical exercises involving NodeMCU and Arduino with ESP8266, covering installation, GPIO interfacing, sensor programming, and remote device control using Blynk. It includes detailed steps for setting up the Arduino IDE, interfacing various sensors (IR, PIR, DHT11), and uploading data to ThingSpeak. Each practical concludes with successful learning outcomes related to the respective topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views56 pages

Iot Lab Manual

The document outlines practical exercises involving NodeMCU and Arduino with ESP8266, covering installation, GPIO interfacing, sensor programming, and remote device control using Blynk. It includes detailed steps for setting up the Arduino IDE, interfacing various sensors (IR, PIR, DHT11), and uploading data to ThingSpeak. Each practical concludes with successful learning outcomes related to the respective topics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

PRACTICAL-1

Aim: Getting started with node MCU, Arduino with an esp8266 in Arduino IDE software.
Theories:
Node MCU:

NodeMCU is an open source platform based on ESP8266 which can connect objects and let
data transfer using the Wi-Fi protocol. In addition, by providing some of the most important
features of microcontrollers such as GPIO, PWM, ADC, and etc., it can solve many of the
project’s needs alone.

The general features of this board are as follows:

 Easy to use
 Programmability with Arduino IDE or IUA languages
 Available as an access point or station
 practicable in Event-driven API applications
 Having an internal antenna
 Containing 13 GPIO pins, 10 PWM channels, I2C, SPI, ADC, UART, and 1-Wire

Node MCU pin structure: -

Page 1
Installing Arduino IDE :

Step 1: install Arduino IDE software from website or Microsoft store:-

Figure 1: installing Arduino ide from Microsoft store

Step 2: open Arduino IDE the interface will look like as shown in the figure: -

Page 2
Installing esp8266 board:

Step 3: click on file icon and select on preference button:-

Step 4: paste esp. 8266 library from Arduino IDE website as shown:-

Page 3
Step 5: now select on tools and click on board manager:-

Step 6: install esp8266 board from board manager as shown: -

Page 4
Step 7: again go to boards and you can see a board of node MCU: -

Conclusion:

In this practical we have learnt about node MCU and installed esp 8266 board in Arduino IDE
software.

Page 5
PRACTICAL 2

Aim: To learn GPIO Interfacing & Programming.

GPIO:

 Stands for "General Purpose Input/output." GPIO is a type of pin found on an integrated
circuit that does not have a specific function.
 They are also used by system-on-chip (SOC) circuits, which include a processor, memory,
and external interfaces all on a single chip.
 A popular device that makes use of GPIO pins is the Raspberry Pi, a single-board computer
designed for hobbyists and educational purposes.

Arduino GPIO:

 Arduino Uno board has various digital IO pins which can be used for input/output devices.
 Arduino analog pins can also be used as digital input/output pins.
 The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect
the Arduino sensors, actuators, and other ICs.

Fig.1 Arduino GIPO


Digital Signals:
Unlike analog signals, which may take on any value within a range of values, digital signals have
two distinct values: HIGH (1) or LOW (0). You use digital signals in situations where the input
or output will have one of those two values.

Page 6
Digital Output:
Arduino (ATmega) digital pins can be configured as output to drive output devices. We have to
configure these pins to use as output.
To configure these pins, pinMode () function is used which set direction of pin as input or
output.
 pinMode(pin no, Mode)
This function is used to configure GPIO pin as input or output.
pin no number of pin whose mode we want to set.
Mode INPUT, OUTPUT or INPUT_PULLUP
E.g. pinMode (3, OUTPUT) //set pin 3 as output
These Arduino (ATmega) pins can source or sink current up to 40 mA which is sufficient to
drive led, LCD display but not sufficient for motors, relays, etc.
Note: While connecting devices to Arduino output pins use resistor. If any connected device to
Arduino withdraw current more than 40 mA from the Arduino then it will damage the Arduino
pin or IC.
These pin produce output in terms of HIGH (5 V or 3.3 V) or LOW (0 V). We can set output on
these pins using digitalWrite () function.

 digitalWrite (pin no, Output value)


This function is used to set output as HIGH (5 V) or LOW (0 V)
pin no number of a pin whose mode we want to set.
Output value HIGH or LOW
E.g. digitalWrite (3, HIGH)

NodeMCU Pinout Configuration:

Fig.2 NodeMCU

Page 7
GIPO Pins Configuration with NodeMCU:

Figure 3. Configuration table

 The GPIO’s shown in the blue box (1, 3, 9, 10) are not commonly used for GPIO purpose
on Dev Kit
 ESP8266 is a system on a chip (SoC) design with components like the processor chip. The
processor has around 16 GPIO lines, some of which are used internally to interface with
other components of the SoC, like flash memory.
 Since several lines are used internally within the ESP8266 SoC, we have about 11 GPIO
pins remaining for GPIO purposes.
 2 pins out of 11 are generally reserved for RX and TX in order to communicate with a host
PC from which compiled object code is downloaded. Hence finally, this leaves just 9
general-purpose I/O pins i.e. D0 to D8.
 As shown in the above figure of NodeMCU Dev Kit. We can see RX, TX, SD2, SD3 pins
are not commonly used as GPIOs since they are used for other internal processes. But we
can try with SD3 (D12) pin which mostly likes to respond for GPIO/PWM/interrupt like
functions.
 Note that the D0/GPIO16 pin can be only used as GPIO read/write; no special functions
are supported on it.

Page 8
hardware requirements:

1x Node MCU ESP8266


1x Breadboard
.1x Ohm Resistoor
1x Through hole LED
2x Female to male jumper wire

Sketch for LED Blinking using node MCU:

void setup ()
{
pinMode(13, OUTPUT);// sets the digital pin 13 as output
}

voidloop()
{
digitalWrite (13, HIGH); // sets the digital pin 13 on
delay (1000); // waits for a second
digitalWrite (13, LOW); // sets the digital pin 13 off
delay (1000); // waits for a second
}

Page 9
Output:

Conclusion:

We have successfully leant about GPIO interfacing and blinking led using Arduino ide software.

P a g e 10
PRACTICAL 3

Aim: Digital ON/OFF sensor (PIR and IR) interfacing programming

1. IR sensor:
The active sensor consists of a receiver and a transmitter, the transmitter is nothing but an IR
LED or a simple LED source that produces light and, on the other hand, the receiver receives the
signals transmitted by the IR transmitter.

as you can see in the following image, the module has three output pins GND, VCC and signal.
Out of which GND and VCC are explicitly used to power the module and we get output at the
signal pin.
So, to get the output from the sensor, you have to power the module through an Arduino or
Raspberry Pi board and get the output on its output pin.

Hardware requirements:

1x NodeMCU ESP8266
1x Bread Board
1x IR sensor
Jumper Wires

P a g e 11
Sketch for IR sensor using node MCU:-

void setup()
{
Serial.begin(115200);
}
void loop()
{
if(digitalRead(5)==LOW)
{
Serial.println("Obstacle");
}
Else
{
Serial.println("Clear");
}
delay(100);
}

P a g e 12
Connection:

Output window:

P a g e 13
2. PIR sensor:

PIR sensor detects a human being moving around within approximately 10m from the
sensor. This is an average value, as the actual detection range is between 5m and 12m.PIR
are fundamentally made of a pyro electric sensor, which can detect levels of infrared
radiation. For numerous essential projects or items that need to discover when an individual
has left or entered the area. PIR sensors are incredible, they are flat control and minimal
effort, have a wide lens range, and are simple to interface with.

P a g e 14
Most PIR sensors have a 3-pin connection at the side or bottom. One pin will be ground, another
will be signal and the last pin will be power. Power is usually up to 5V. Sometimes bigger
modules don’t have direct output and instead just operate a relay which case there is ground,
power and the two switch associations. Interfacing PIR with microcontroller is very easy and
simple. The PIR acts as a digital output so all you need to do is listening for the pin to flip high
or low. The motion can be detected by checking for a high signal on a single I/O pin. Once the
sensor warms up the output will remain low until there is motion, at which time the output will
swing high for a couple of seconds, then return low. If motion continues the output will cycle in
this manner until the sensors line of sight of still again. The PIR sensor needs a warm-up time
with a specific end goal to capacity fittingly. This is because of the settling time included in
studying nature’s domain. This could be anyplace from 10-60 seconds.

Hardware Components:

 NodeMCU

 PIR Sensor / HC-SR501

 Breadboard

 Jumper Wires

 Micro USB Cable

 LED

Circuit connections:

P a g e 15
Connecting PIR sensors to a NodeMCU is really simple. The PIR acts as a digital output so all
you need to do is operate the pin to flip high (detected) or low (not detected). Check out the
images for more details.
Most PIR modules have a 3-pin connection at the side or bottom. The pinout may vary between
modules so check the pinout carefully! Power is usually 3-5v DC input.
The circuit connections are made as follows :
Vcc pin of the HC-SR501 is connected to +3v of the NodeMCU.
Output pin of the HC-SR501 is connected to Digital pin D7 of the NodeMCU.
GND pin of the HC-SR501 is connected to Ground pin (GND) of the NodeMCU.
In this example we'll connect Anode pin of the LED to Digital pin D6 and Cathode pin
to GND pin of NodeMCU.
Before you get started with coding you need Arduino IDE.To download Arduino IDE and for
NodeMCU setup, you can check my previous instructacle.

Sketch for PIR Sensor

Sketch for PIR sensor using Arduino:-

intledPin = 12; // LED


intpirpin = 13; // PIR Out pin
intpirStat = 0; // PIR status
void setup() {

P a g e 16
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop() {
pirstatdigitalRead(pirpin);
if (pirStat == HIGH) {
digitalwrite(ledPin, HIGH);
Serial.println("Motion detect");
}
else
{
digitalwrite(ledPin, LOW);
Serial.println("Motion absent");
}

P a g e 17
Connections:

Output:

Conclusion:
We have successfully learned about Digital ON/OFF sensor (PIR and IR) interfacing
programming.

P a g e 18
PRACTICAL 4

AIM: NodeMCU Temperature, Humidity data upload on Thingspeak on Arduino IDE.

Introduction:
This practical explains how to log weather data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor DHT11 will be used to measure temperature and humidity data.
Hardware required

 Node MCU
 DHT 11 temperature sensor
 Jumper cables

Building Circuit
Make connection as mentioned ahead.

S.NO. NodeMCU DHT11

1. Vin VCC

2. GND GND

3. D3 Data Out

P a g e 19
Circuit Layout:

Procedure:

1. Go to thingspeak.com website and click on get started for free.

P a g e 20
2. create your new thingspeak account and enter necessary details.

3. verify your account.

P a g e 21
4. click on create new channel.

5. enter required details.

P a g e 22
6. after creating channel this window will pop up. Store this channel id for future reference.

7. for getting api key click on api keys. And save this api key.

P a g e 23
Sketch for DHT 11 using node MCU:-

#include <DHT.h>
#include <ESP8266WiFi.h>
String apiKey = "21HAIADU0ZJAFQER";
const char *ssid = "shikhar";
const char *pass = "0532269sv";
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");

P a g e 24
}

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());

P a g e 25
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...");

delay(10000);
}

P a g e 26
P a g e 27
Connections:

Output:

1. On Arduino ide:

P a g e 28
2. On thingspeak:

Conclusion:
We have successfully learned about NodeMCU Temperature, Humidity data upload on
Thingspeak on Arduino IDE.

P a g e 29
PRACTICAL: 5

AIM: Controlling devices remotely using Bluetooth link, Wi-Fi link.

Introduction:
Blynk is a Platform with IOS and Android apps to control Arduino, Raspberry Pi and the
likes over the Internet. It’s a digital dashboard where you can build a graphic interface for
your project by simply dragging and dropping widgets.

How It Works:

1. Connect in seconds to approved computers, machines, devices, or even unattended


servers or other equipment.
2. Access system, data, files, and applications.
3. Control the equipment, system, machine, computer, phone, or IoT device, as though you
were the primary user handling it in person.

Sketch for blinking led using blue link:

#include <Blynk.h>

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_TEMPLATE_ID "TMPLdfcKXwAC"
#define BLYNK_DEVICE_NAME "iot exp 5"
#define BLYNK_AUTH_TOKEN "WUTcAB8ZKtJwrsAAv9RxPfLRBdlndByL"
char auth[] = "WUTcAB8ZKtJwrsAAv9RxPfLRBdlndByL";
char ssid[ ] = "Shikhar 5g";
char pass[ ] = "shikhar420";
WidgetLED led1(V1);
BlynkTimer timer;
void blinkLedWidget()
{

P a g e 30
if (led1.getValue()) {
led1.off();
Serial.println("LED on V1: off");
} else {
led1.on();
Serial.println("LED on V1: on");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, blinkLedWidget);
}
void loop()
{
Blynk.run();
timer.run();
}

P a g e 31
P a g e 32
Connection:

Output:

1. OFF in Blynk

P a g e 33
2. ON in Blynk

Conclusion:
We have successfully learned about Controlling devices remotely using Bluetooth link, Wi-
Fi link.

P a g e 34
PRACTICAL 6

AIM: Write a program to monitor Heartbeat in node MCU.

What is Heartbeat Sensor?


Heartbeat Sensor is an electronic device that is used to measure the heart rate i.e. speed of
the heartbeat. Monitoring body temperature, heart rate and blood pressure are the basic
things that we do in order to keep us healthy.
In order to measure the body temperature, we use thermometers and a sphygmomanometer
to monitor the Arterial Pressure or Blood Pressure.

Working of the Circuit:

Upload the code to node mcu and Power on the system. The node mcu asks us to place our
finger in the sensor and press the switch.
Place any finger (except the Thumb) in the sensor clip and push the switch (button). Based
on the data from the sensor, board calculates the heart rate and displays the heartbeat in bpm.
While the sensor is collecting the data, sit down and relax and do not shake the wire as it
might result in a faulty values.

Sketch for heartbeat sensor using note MCU:

intPulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG


PIN 0
int LED13 = 13; // The on-board Arduion LED
int Signal; // holds the incoming raw data. Signal value can range from 0-
1024
int Threshold = 550; // Determine which Signal to "count as a beat", and which to
ingore.
// The SetUp Function:
void setup() {
pinMode(LED13,OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(9600); // Set's up Serial Communication at certain speed.
}
// The Main Loop Function
void loop() {

P a g e 35
Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
// Assign this value to the "Signal" variable.
Serial.println(Signal); // Send the Signal value to Serial Plotter.
if(Signal > Threshold){ // If the signal is above "550", then "turn-on"
Arduino's on-Board LED.
digitalWrite(LED13,HIGH);
}
else {
digitalWrite(LED13,LOW); // Else, the sigal must be below "550", so "turn-
off" this LED.
}
delay(10);
}

P a g e 36
Connection diagram:

Output:

Conclusion:
We have successfully learned to write a program to monitor Heartbeat in node MCU.

P a g e 37
PRACTICAL:7

AIM: Experiments on Agriculture IOT (Soil moisture ,PH monitor).

In agriculture IoT applications include farm vehicle tracking, livestock monitoring, storage
monitoring and other farm operations. The diagram on the right provides a visual of this
application.
In this IoT model, sensors can be deployed in the farm – to the ground, in water, in vehicles
etc. to collect data. The collected data is stored in the cloud system or server and accessed
by the farmer via the internet or their mobile phones.

What is Soil moisture Sensor?


Soil moisture sensors measure the volumetric water content in soil. Since the direct
gravimetric measurement of free soil moisture requires removing, drying, and weighing of
a sample, soil moisture sensors measure the volumetric water content indirectly by using
some other property of the soil, such as electrical resistance, dielectric constant, or
interaction with neutrons, as a proxy for the moisture content.

What is PH monitor Sensor?


A pH sensor is one of the most essential tools that's typically used for water measurements.
This type of sensor is able to measure the amount of alkalinity and acidity in water and other
solutions.

Sketch:

1. Sensor:

P a g e 38
2. Code:

Connection:

P a g e 39
Output:

1. Output of soil moisture:

2. Output of ph sensor monitor:

Conclusion:
We have successfully learned about experiments on Agriculture IOT (Soil moisture ,PH
monitor).

P a g e 40
PRACTICAL: 8

AIM: IoT based home automation.

The Internet of Things (or commonly referred to as IoT) based Home Automation system,
as the name suggests aims to control all the devices of your smart home through internet
protocols or cloud based computing.
The IoT based Home Automation system offer a lot of flexibility over the wired systems s
it comes with various advantages like ease-of-use, ease-of-installation, avoid complexity of
running through wires or loose electrical connections, easy fault detection and triggering
and above and all it even offers easy mobility.

Sketch:

P a g e 41
Output of Blynk:

Conclusion:

We have successfully learned about IoT based home automation.

P a g e 42
PRACTICAL: 9

AIM: Familiarization with Raspberry Pi and its architecture. Perform necessary software
installation.

What is Raspberry PI?

It is a cheap, credit-card-sized device that uses a daily keyboard and mouse and joins to a TV or
computer monitor. It is a thin weighable computer that let every person of all ages to discover
programming and gain how to programme in variant languages like Python and Scratch.

What we will need?

SD card

We recommend a class 4 or class 10 microSD card of at least 8 GB. People can get a card which
is pre-existed with NOOBS or Raspberry Pi OS to save the time but it's easy to establish self-
card.

Display and connectivity cable

Any HDMI/DVI monitor or TV can work as a display for the Pi. Use a monitor with an HDMI
input for the best results; other link types are also available for older devices.

Keyboard and mouse

Any regular USB keyboard and mouse will work with Raspberry Pi. If already paired, wireless
keyboards and mice can run. For configuration options for keyboard configurations, see raspi-
config.

Power supply

Pi is represented by a USB Micro or USB Type-C for power supply.

P a g e 43
Like Model 4B, 2A at 5V for 3B and 3B+, or 700mA at 5V for the earlier, low-powered Pi
versions, we require good-quality power connection that can facilitate legit 3A at 5V. We suggest
that one must use the real Raspberry Pi power supply that is specifically made for Raspberry Pi.

Low-current power supplies can work for normal, but if it gets too much supply, it might cause
the Pi to restart. For work with the Pi 3 or 4, they are not comfortable.

Wireless USB dongle

Required only if we require wireless connectivity and operating an older model without wireless
qualities pre-installed.

Install Raspberry Pi OS using Raspberry Pi Imager

Raspberry Pi Imager is the quick and easy way to install Raspberry Pi OS and
other operating systems to a microSD card, ready to use with your Raspberry
Pi. Watch our 45-second video to learn how to install an operating system
using Raspberry Pi Imager.

Download and install Raspberry Pi Imager to a computer with an SD card


reader. Put the SD card you'll use with your Raspberry Pi into the reader and
run Raspberry Pi Imager.

Download for WindowsDownload for macOSDownload for Ubuntu for x86

To install on Raspberry Pi OS, type


sudo apt install rpi-imager
in a Terminal window.

Prerequisites:

Raspberry Pi — any version

 microSDHC card (with SD adapter)— at least 8GB although 32GB can be used which allows
for more software to be loaded.

 Micro HDMI to HDMI cable — you can also use a Micro HDMI to HDMI adapter with a
regular HDMI cable.

 5V DC via USB-C connector — this is for power.

P a g e 44
 Keyboard

 Mouse

 Monitor

 A way to write from your computer to your microSDHC card

 Basic technology knowledge

Once you meet all of the prerequisites you are ready to move on to installing Raspberry Pi OS.

Step 1 — Download and Install Raspberry Pi Imager

The first step is to download the Raspberry Pi Imager from the official Raspberry Pi website. This
tool will allow you to choose an OS, have it downloaded automatically, and write it to the SD
card of your choice.

The imager tool is available on Windows, macOS, and Ubuntu. Images shown will be from a
Mac, but the tool will work the same across the supported platforms.

Raspberry Pi Imager from the Raspberry Pi Foundation

Download the Raspberry Pi Imager for your operating system and follow the installation

instructions.

Launch Raspberry Pi Imager

Step 2: Choose OS

P a g e 45
Several operating systems are available for selection within the Raspberry Pi Imager, but we
will focus on Raspberry Pi OS.

There are 3 versions of Raspberry Pi OS available. We will briefly touch on each one but we
will be using Raspberry Pi OS (32-bit) for this guide.

Select CHOOSE OS

OS Selection within Raspberry Pi Imager

Raspberry Pi OS (32-bit) Lite: This version provides the bare essentials to get you up and running.
There is no Graphical User Interface (GUI) with this image and the size is around 0.4 GB.

Raspberry Pi OS (32-bit): This version includes a GUI and has basic software installed. The size
of this image is around 1.1 GB.

Raspberry Pi OS Full (32-bit): This version includes a GUI and more software installed than the
non-full version. The size of this image is around 2.5 GB

Select Raspberry Pi OS (32-bit)

P a g e 46
OS Selected in Raspberry Pi Imager

Step 3: Choose SD Card

You’ll now need your SD card connected to your computer to copy over the OS you chose.

Select CHOOSE SD CARD and select the SD card you have connected to your computer.

Select SD Card

You’re now ready to begin writing the OS to your SD card.

P a g e 47
OS and SD Card selected

Step 4: Write to SD Card:- This step will write the selected OS to the SD card and run a
verification that the copy was successful.

Write Process Started

The writing process will vary depending on the OS you selected. Typically, this will only take a
few minutes.

Verifying Write

The verify process only takes about a minute to complete.

P a g e 48
Write Successful

The OS has now been copied to your SD card. You are now ready to move on to booting your

Raspberry Pi.

Select CONTINUE

Step 5: Booting Your Raspberry Pi

Insert your microSDHC card into your Raspberry Pi. Then, hook up your Raspberry Pi to power,
keyboard, mouse, and monitor.

Select Next

Welcome to Raspberry Pi

The next screen will be to set your country

P a g e 49
Choose Your Country

Choose Your Language

Choose Your Timezone

Select the checkboxes if you are using the English language and an English keyboard

Click Next

Set Country

The next screen will prompt you to change your password. The default username is “pi” and the
default password is “raspberry”

It is best practice to enable strong passwords for your accounts.

Enter a new password

Confirm the new password

Press Next

P a g e 50
Change Password

The next screen will ask you if there is a black border around the desktop. The desktop should
take up the entire screen. If it doesn’t, Raspberry Pi OS can make the adjustment to fill the black
space. This change will take effect when the Raspberry Pi is restarted.

Select the checkbox if the screen shows a black border around the desktop.

Press Next

Set Up Screen

The next screen will prompt you to connect the Raspberry Pi to a wireless network. If no internet

connection is available you can press the skip button to proceed past this step. If you have a wired

connection you will not see this step.

P a g e 51
Select a Wireless Network

Press Next

Select Wireless Network

The next screen will prompt you to enter the wireless network password. You can uncheck “hide
characters” to see the characters you are typing.

Enter Wireless Network Password

Press Next

Wireless Network Password

P a g e 52
The next screen will ask you if you’d like to have the operating system and applications checked
and updated if necessary. An internet connection is required to complete this step. Press “Skip” if
you’d like to continue without checking.

Update Software
A popup will indicate when your system is up to date.

System is up to date

The last screen will let you know that setup is complete and your Raspberry Pi is good to go.
Feel free to restart your Raspberry Pi for any system changes to take effect.

Setup complete.
Conclusion: we have successfully learned about familiarization with Raspberry Pi and its
architecture. Perform necessary software installation.

P a g e 53
PRACTICAL: 10

AIM: To interface LED with Raspberry Pi and write Python programming to turn ON/ OFF
LED using Raspberry Pi.

The features of the Raspberry Pi’s GPIO Pins before proceeding with the further step of
how to Blink an LED using Raspberry Pin and its GPIO Pins.

Components Required:

 Raspberry Pi 3 Model B (any Raspberry Pi would do fine)


 5mm LED x 1
 1KΩ Resistor (1/4 Watt) x 1
 Mini Breadboard x 1
 Connecting wires
 Miscellaneous (Computer, Ethernet cable, Power Supply for Raspberry Pi etc.)

Circuit Diagram of Blinking LED with Raspberry Pi:

In order to Blink an LED using Raspberry Pi, we need to first connect the LED to the
Raspberry Pi. There are two ways you can connect your LED to the Raspberry Pi. I’ll show
both ways of connecting the LED.
Circuit 1
In the first circuit, the anode of the LED is connected to GPIO25 (Physical Pin 22) through
a 1KΩ current limiting resistor. The cathode of the LED is connected to the GND Pin.

In this circuit, the anode of the LED is connected to the 3.3V supply pin of the Raspberry
Pi through the 1KΩ resistor. The cathode of the LED is connected to GPIO25 (Physical Pin
22).

In this circuit, the GPIO pin acts as the sink (GND).

P a g e 54
NOTE: I’ll be concentrating on the first circuit, where the GPIO pin GPIO25 acts as the
source. The code explained in the further sections will be specific to this circuit. The code
can also be used for second circuit with slight or no modifications.

Sketch:
importRPi.GPIOas GPIO # Import Raspberry Pi GPIO library
fromtime import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin ,set initial
value to low (off)
whileTrue: # Run forever
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second

Code for Blinking an LED with Raspberry Pi:


#!/usr/bin/env python
importRPi.GPIOasGPIO# RPi.GPIO can be referred as GPIO from now
Importtime
ledPin=22# pin22
defsetup():
GPIO.setmode(GPIO.BOARD) # GPIO Numbering of Pins
GPIO.setup(ledPin, GPIO.OUT) # Set ledPin as output
GPIO.output(ledPin, GPIO.LOW) # Set ledPinto LOW to turn Off the LED
defloop():
whileTrue:
print'LED on'
GPIO.output(ledPin, GPIO.HIGH) # LED On
time.sleep(1.0) # wait 1 sec
print'LED off'
GPIO.output(ledPin, GPIO.LOW) # LED Off
time.sleep(1.0) # wait 1 sec
defendprogram():
GPIO.output(ledPin, GPIO.LOW) # LED Off
GPIO.cleanup() # Release resources
if__name__=='__main__': # Program starts from here
setup()
try:
loop()
exceptKeyboardInterrupt: # When 'Ctrl+C' is pressed, the destroy() will be executed.
endprogram()

P a g e 55
Connection diagram:

Output of led:

Conclusion:
We have successfully about interface LED with Raspberry Pi and write Python
programming to turn ON/ OFF LED using Raspberry Pi.

P a g e 56

You might also like