0% found this document useful (0 votes)
98 views46 pages

IOT Practical File KOT 551

The document is a practical file from the Department of Computer Science and Engineering at Raj Kumar Goel Institute of Technology in Ghaziabad, India. It contains two experiments analyzing the anatomy of ARDUINO UNO and RASPBERRY Pi 4 boards. The first experiment discusses the various components of the ARDUINO UNO board including the microcontroller, pins, power supply and voltage regulator. The second experiment provides specifications of the RASPBERRY Pi 4 board and describes components such as the processor, memory, ports, and GPIO pinout.

Uploaded by

qz5jq94yh2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views46 pages

IOT Practical File KOT 551

The document is a practical file from the Department of Computer Science and Engineering at Raj Kumar Goel Institute of Technology in Ghaziabad, India. It contains two experiments analyzing the anatomy of ARDUINO UNO and RASPBERRY Pi 4 boards. The first experiment discusses the various components of the ARDUINO UNO board including the microcontroller, pins, power supply and voltage regulator. The second experiment provides specifications of the RASPBERRY Pi 4 board and describes components such as the processor, memory, ports, and GPIO pinout.

Uploaded by

qz5jq94yh2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY,

GHAZIABAD (U.P.)
Recognized by AICTE and Approved by Dr. APJ AKTU, Lucknow

(AN ISO 9001:2015 CERTIFIED INSTITUTE)


NBA Accredited Programs (ECE & Pharmacy)

DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING(IOT)

PRACTICAL FILE
Name: Session:

Roll No: Branch (Sec):

Subject: INTERNET OF THINGS LAB Subject Code: (KOT-551)


Raj Kumar Goel Institute of Technology, Ghaziabad
Department of Computer Science & Engineering (IOT)

Subject: Internet of Things Lab (KOT-551)

INDEX
Program
No. Program Name Date Signature
Experiment No.1

Aim: Analyse and explain ARDUINO UNO board anatomy

ARDUINO UNO PIN DIAGRAM


Arduino Uno (R3)

Arduino is a project, open-source hardware, and software platform used to design and build electronic devices. It
designs and manufactures microcontroller kits and single-board interfaces for building electronics projects. The
Arduino boards were initially created to help the students with the non-technical background. The designs of Arduino
boards use a variety of controllers and microprocessors. It also provides an IDE (Integrated Development
Environment) project, which is based on the Processing Language to upload the code to the physical board.

Technical Specifications of Arduino UNO

o There are 20 Input/output pins present on the Arduino UNO board. These 20 pins include 6 PWM pins, 6
analog pins, and 8 digital I/O pins.

o The PWM pins are Pulse Width Modulation capable pins.

o The crystal oscillator present in Arduino UNO comes with a frequency of 16MHz.

o It also has a Arduino integrated WiFi module. Such Arduino UNO board is based on the Integrated WiFi
ESP8266 Module and ATmega328P microcontroller based on AVR architecture.

o Flash memory is 32 KB ( 2KB of this used by boot loader), SRAM is 2KB. EEPROM is 1KB

o Operating Voltage is 5V. The input voltage of the UNO board varies from 7V to 20V.
o Arduino UNO automatically draws power from the external power supply. It can also draw power from the
USB.

Let's discuss each component in detail.

o ATmega328 Microcontroller- It is a single chip Microcontroller of the ATmel family. The processor code
inside it is of 8-bit. It combines Memory (SRAM, EEPROM, and Flash), Analog to Digital Converter, SPI
serial ports, I/O lines, registers, timer, external and internal interrupts, and oscillator.

o ICSP pin - The In-Circuit Serial Programming pin allows the user to program using the firmware of the
Arduino board. The ICSP header consists of 6 pins. The structure of the ICSP header is shown below, it is the
top view of the ICSP header.

o SDA: It stands for Serial Data. It is a line used by the slave and master to send and receive data. It is
called as a data line, while SCL is called as a clock line.

o SCL: It stands for Serial Clock. It is defined as the line that carries the clock data. It is used to
synchronize the transfer of data between the two devices. The Serial Clock is generated by the device and
it is called as master.

o SPI: It stands for Serial Peripheral Interface. It is popularly used by the microcontrollers to
communicate with one or more peripheral devices quickly. It uses conductors for data receiving, data
sending, synchronization, and device selection (for communication).
o MOSI: It stands for Master Output/ Slave Input. The MOSI and SCK are driven
by the Master.

o SS: It stands for Slave Select. It is the Slave Select line, which is used by the master. It acts as the enable
line.

o I2C: It is the two-wire serial communication protocol. It stands for Inter Integrated Circuits. The I2C is a
serial communication protocol that uses SCL (Serial Clock) and SDA (Serial Data) to receive and send
data between two devices. 3.3V and 5V are the operating voltages of the board.

o Power LED Indicator- The ON status of LED shows the power is activated. When the power is OFF, the
LED will not light up.

o Digital I/O pins- The digital pins have the value HIGH or LOW. The pins numbered from D0 to D13 are
digital pins.

o TX and RX LED's- TXD and RXD pins are used for serial communication. The TXD is used for transmitting
the data, and RXD is used for receiving the data. It also represents the successful flow of data.

o AREF- The Analog Reference (AREF) pin is used to feed a reference voltage to the Arduino UNO board from
the external power supply.

o Reset button- It is used to add a Reset button to the connection.

o USB- It allows the board to connect to the computer. It is essential for the programming of the Arduino UNO
board.

o Crystal Oscillator- The Crystal oscillator has a frequency of 16MHz, which makes the Arduino UNO a
powerful board.

o Voltage Regulator- The voltage regulator converts the input voltage to 5V.

o GND- Ground pins. The ground pin acts as a pin with zero voltage.

o Vin- It is the input voltage.

o Analog Pins- The pins numbered from A0 to A5 are analog pins. The function of Analog pins is to read the
analog sensor used in the connection. It can also act as GPIO (General Purpose Input Output) pins.
Experiment No.2

Aim: Analyse and explain RASPBERRY Pi board anatomy

RASPBERRY Pi 4 PIN DIAGRAM


Introduction to Raspberry Pi 4:

The Raspberry Pi 4 Model B is the latest board launched by the Raspberry Pi Foundation in June 2019. This model has
the latest high-performance quad-Core 64-bit Broadcom 2711, Cortex A72 processor clocked at 1.5GHz speed.This
processor uses 20% less power and offers 90% greater performance than the previous model. Raspberry Pi 4 model
comes in three different variants of 2 GB, 4 GB, and 8 GB LPDDR4 SDRAM.The other new features of the board are
dual-display support up to 4k resolutions via a pair of micro-HDMI ports, hardware video decodes at up to 4Kp60,
dual-channel 2.4/5.0GHz wireless LAN, true Gigabit Ethernet, two USB 3.0 ports, Bluetooth 5.0, and PoE capability.

Raspberry Pi 4 Specs:

 Broadcom BCM2711 chip consist of Quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
 2GB, 4GB, and 8GB of LPDDR4 SDRAM (depending on the version of the board)
 Dual-channel 2.4/5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE
 Gigabit Ethernet
 Two USB 3.0 ports and two USB 2.0 ports.
 Raspberry Pi standard 40 pin GPIO header
 Two micro-HDMI ports (support up to 4kp60 resolution)
 2-lane MIPI DSI display port
 2-lane MIPI CSI camera port
 4-pole stereo audio and composite video port
 265 (4k@60 decode), H264 (1080@60 decode and 1080@30 encode)
 OpenGL ES 3.0 graphics
 Micro-SD card slot for loading operating system and data storage
 1V/3A DC via USB-C connector
 Power over Ethernet (PoE) enabled (requires PoE HAT board)
 Operating temperature: 0 – 50oC

Raspberry Pi 4 Board Layout:

CPU: It consists of a Broadcom BCM2711 chip which contains a 1.5GHz 64-bit quad-core ARM Cortex-A72
processor (using an ARMv8-architecture core).

GPU: Broadcom VideoCore VI @ 500 MHz was released in 2009. It is capable of BluRay quality video playback,
H.265 (4Kp60 decode); H.264 (1080p60 decode, 1080p30 encode); OpenGL ES, 3.0 graphics.

RAM: It comes with 2GB, 4GB, and 8GB (depends on different versions) variants of LPDDR4 SDRAM.
USB port: It consists of two USB 3.0 and two USB 2.0 ports to connect it to an external keyboard, mouse, or other
peripheral devices.

USB power port: It consists of a 5.1V, 3A USB type-C power port.

HDMI port: Two micro HDMI ports capable of supporting up to 4k@60HZ resolution.

Ethernet Port: It comes with true Gigabit Ethernet capable of sending Ethernet frames at a rate of one gigabit per
second (1 billion bits per second).

Composite Video Output: Both the audio output socket and the video composite socket reside in a single 4-pole
3.5mm socket.

SD card Slot: A micro-SD card slot is used for booting up the operating system and storage purposes. The SD card
slot is given at the back of the Raspberry Pi 4 board

Raspberry Pi 4 GPIO Pinout:

Raspberry Pi GPIO stands for General Purpose Input Output pins. These pins are used to connect the Raspberry pi
board to external input/output peripheral devices.
This model B consists of a 40-pin GPIO header. Out of these 40 pins, 26 pins are GPIO pins.
Power Pins on Raspberry Pi 4:

The raspberry pi 4 model B board consists of two 5V pins, two 3V3 pins, and 7 ground pins (0V).

5V: The 5v pin outputs the 5 volts coming from the USB Type-C port.

3.3V: The 3v pin is used to provide a stable 3.3v supply to external components.

GND: The ground pin is commonly referred to as GND.

R-Pi 4 Global Input/Outputs pins:

A GPIO pin set as input allows the signal transmitted by any external device (connected to this pin) to be received by
the Raspberry Pi.

Input voltage between 1.8V and 3.3V is read as HIGH by the Raspberry pi. And when the input voltage is lower than
1.8V, it is read as LOW.

Note: Do not connect an external device with an output voltage above 3.3V to any of the GPIO pins, or else it will fry
your Raspberry Pi board.

A GPIO pin set as output delivers HIGH/3.3V or LOW/0V.

Apart from Input/Output, the GPIO pins can also perform a variety of other functions like PWM. Some of these
functions/pins are:
PWM (pulse-width modulation) pins:

PWM stands for “Pulse Width Modulation”. It means that an analog value is being modulated on a digital signal.

Software PWM is available on all pins.

Hardware PWM is available on these pins only: GPIO12, GPIO13, GPIO18, GPIO19

SPI pins on RPi 4:

SPI (Serial Peripheral Interface) is a type of serial communication protocol. It is used by the Raspberry Pi for master-
slave communication to quickly communicate between one or more peripheral devices.

The data is synchronized using a clock (SCLK at GPIO11) from the master (RPi). The Pi sends this data to an SPI
device using MOSI (Master Out Slave In) pin. And when the SPI device needs to communicate back to the Raspberry
Pi, it sends the data back through the MISO (Master In Slave Out) pin.

5 pins are required for SPI communication:

 GND: Connect the GND pin from all the slave components and the Raspberry Pi 4 board together.
 SCLK: Clock for SPI communication.
 MOSI: It stands for Master Out Slave In. This pin is used to send data from the master to a slave.
 MISO: It stands for Master In Slave Out. This pin is used to receive data from a slave to the master.
 CE: It stands for Chip Enable. We need to connect one CE pin per slave (or peripheral devices) in our circuit.
By default, we have two CE pins but we can configure more CE pins from the other available GPIO pins.

SPI pins on Raspberry Pi:

SPI0: GPIO9 (MISO), GPIO10 (MOSI), GPIO11 (SCLK), GPIO8 (CE0), GPIO7 (CE1)

SPI1: GPIO19 (MISO), GPIO20 (MOSI), GPIO21 (SCLK), GPIO18 (CE0), GPIO17 (CE1), GPIO16 (CE2)

I2C Pins on RPi 4:

I2C pins on the Raspberry Pi board are used to communicate with peripheral devices that are compatible with Inter-
Integrated Circuit (a low-speed two-wire serial communication protocol).

This serial communication protocol requires master-slave roles between both, the board and the peripheral devices.

I2C protocol requires two connections: SDA (Serial Data) and SCL (Serial Clock). They work by transmitting data
using the SDA connection, and the speed of data transfer is controlled via the SCLK pin.

Data: (GPIO2), Clock (GPIO3)

EEPROM Data: (GPIO0), EEPROM Clock (GPIO1)


UART pins on RPi 4:

The UART (Universal Asynchronous Receiver / Transmitter) is an asynchronous protocol that provides a way to
communicate between two microcontrollers or devices.

TX pin transmits the serial data to the RX pin of another device and RX pin receives the serial data coming from TX
pin of the other device.

TX : GPIO14

RX : GPIO15
Experiment No.3

Aim: Start Raspberry Pi and try various Linux commands in command terminal
window: ls, cd, touch, mv, rm, man, mkdir, rmdir, tar, gzip, cat, more, less, ps, sudo,
cron, chown, chgrp, ping etc.

List content of current directory:


Ls

Update Raspberry OS:


sudo apt-get update
sudo apt-get
upgrade

Check Raspberry OS Version:


cat /proc/version

Access Raspberry Pi Configuration:


sudo raspi-config

Start GUI from Command Line on Raspberry Pi:


startx

Network Configuration Details:


ifconfig

Open and Edit a Text File:


sudo nano filename

Restart Your Raspberry Pi:


sudo reboot

Power Off Raspberry Pi:


shutdown -h now
shutdown -h 01:22: To shutdown at 1:22 AM.

Run a Script:
chmod a+x filename.sh
./filename.sh

View Background Tasks:


htop

Install a Program:
sudo apt-get install programname

Find the IP Address of Raspberry Pi:


hostname -I
Download a File:
wget URL

Create Directory:
mkdir foldername

Remove empty directory:


rmdir foldername

Copies the file or directory X and pastes it to a specified location:


cp X <destination>

Moves the file or directory X and pastes it to a specified location:


mv X <destination>

Change to Root Directory:


cd ..

Change to specific path:


cd <path>

Delete Files or Folder:


rm foldername

Check Files by Extension:


cat *.txt

Change File Ownership:


sudo chown pi:root filename

Extract Files:
unzip filename

Extract TAR Files:


tar -cvzf filename.tar.gz

Show the contents of the file:


cat <name>

Creates a new, empty file named example.txt in the current directory:


touch example.txt

display the user manual of any command that we can run on the terminal:
man <command_name>
eg: man printf

Compresses files:
gzip mydoc.txt
gzip -f
myfile1.txt
This will forcefully compress a file named myfile.txt even if there already exists a file named as myfile.txt.gz

Using more:
more is one of the oldest terminal pagers in the UNIX ecosystem. Originally, more could only scroll down, but now
we can use it to scroll up one screen-full at a time, and scroll down either one line or one screen-full:
more filename.txt
An example output would be:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet
--More--(1%)
On its status bar, more shows the percentage of the file read. It automatically closes when it reaches the end of the file
without having to press a button.

One of the reasons why less was introduced was to allow backward movement line by line:
if we try to read a png, jpeg, or jpg file with more, it would just print its binary data, whereas less would print
its metadata:
less picture.jpg
picture.jpg JPG 743x533 743x533+0+0 8-bit sRGB 45.6KB

most :
It allows us to view multiple files simultaneously and switch between them. It’s very useful for viewing large data sets
because most does not wrap lines that have more characters than the terminal page. Instead, it truncates them and
offers column-by-column horizontal scrolling.
We can display multiple files and switch between them by passing files as arguments to most:
most text.txt file.txt
-- MOST: text.txt (18,4) 5%
By default, while reading a file, the status bar displays the file name, the percentage that we’ve viewed so far, the
current line number, and current position horizontally since we can scroll left and right by pressing left and right
keys. We can switch between files by pressing :n. Then, we can use up/down arrow keys to change file names, and
press enter to switch to the selected file:
-- MOST: text.txt (18,4) 5%
Next File (1): file.txt

ps : Process Status:
list the currently running processes and their PIDs along with some other information depends on different options.
Simple process selection : Shows the processes for the current shell –
[root@rhel7 ~]# ps
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.

View Processes:
[root@rhel7 ~]# ps -
A [root@rhel7 ~]# ps
-e

sudo (Super User DO) :


It is used as a prefix of some command that only superuser are allowed to run.
before any command we can write sudo, it means you are executing that command as superuser/admin

cron:
It automates the scheduled task at a predetermined time. It is a daemon process, which runs as a background process
and performs the specified operations at the predefined time when a certain event or condition is triggered without
the
intervention of a
user. Syntax:
cron [-f] [-l] [-L loglevel]

Options:
-f : Used to stay in foreground mode, and don’t daemonize.
-l : This will enable the LSB compliant names for /etc/cron.d files.
-n : Used to add the FQDN in the subject when sending mails.
-L loglevel : This option will tell the cron what to log about the jobs with the following values:
1 : It will log the start of all cron jobs.
2 : It will log the end of all cron jobs.
4 : It will log all the failed jobs. Here the exit status will not equal to zero.
8 : It will log the process number of all the cron jobs.
The crontab (abbreviation for “cron table”) is list of commands to execute the scheduled tasks at specific time. It
allows the user to add, remove or modify the scheduled tasks.

Permitting users to run cron jobs:


The user must be listed in this file to be able to run cron jobs if the file exists.
/etc/cron.allow
If the cron.allow file doesn’t exist but the cron.deny file exists, then a user must not be listed in this file to be able to
run the cron job.
/etc/cron.deny

Sample commands:
Run /home/folder/code.sh every hour, from 9:00 AM to 6:00 PM,
everyday. 00 09-18 * * * /home/folder/code.sh

Run /usr/local/bin/backup at 11:30 PM, every weekday.


30 23 * * Mon, Tue, Wed, Thu, Fri
/usr/local/bin/backup

Run sample-command.sh at 07:30, 09:30, 13:30 and 15:30.


30 07, 09, 13, 15 * * * sample-command.sh

chgrp:
It is a command in Linux is used to change the group ownership of a file or directory. All files in Linux belong to an
owner and a group. You can set the owner by using “chown” command, and the group by the “chgrp” command.
Syntax:
chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE…
First we need to have administrator permission to add or delete groups. We can Login as root for this purpose or using
sudo. In order to add a new group we can use:
sudo addgroup groupName

Example : To change the group ownership of a file.


sudo chgrp groupName abc.txt

Example 2: To change the group ownership of a folder.


sudo chgrp groupName FolderName

PING (Packet Internet Groper):


It is a command is used to check the network connectivity between host and server/host. This command takes as
input the IP address or the URL and sends a data packet to the specified address with the message “PING” and get a
response from the server/host this time is recorded which is called latency.

PING Version:
To get ping version installed on your
system. sudo ping -v

Using PING:
ping www.brain-mentors.com

Controlling the number of pings:


Earlier we did not define the number of packets to send to the server/host by using -c option we can do so.
ping -c 5 www.brain-mentors.com

Controlling the size of packets send:


Earlier a default sized packets were sent to a host but we can send light and heavy packet by using
-s option.
ping -s 40 -c 5 www.brain-mentors.com

Changing the time interval:


By default ping wait for 1 sec to send next packet we can change this time by using -i option.
ping -i 2 www.brain-mentors.com

To Timeout PING:
To stop pinging after sometime use -w option.
ping -w 3 www.brain-mentors.com
Experiment No.4

Aim: Run some python programs on Pi

Program (a): Read your name and print Hello message with name.
Program (b): Read two numbers and print their sum, difference, product and
division.
Program (c): Word and character count of a given string.
Program (d): Area of a given shape (rectangle, triangle and circle) reading shape
and appropriate values from standard input.
Experiment No.5

Aim: Run some python programs on Pi

Program(a): Print a name ‘n’ times, where name and n are read from standard
input, using for and while loops.
Program(b): Handle divided by Zero exception.
Experiment No.6

Aim: Running some programs.

Program(a): Light an LED on Arduino Uno.


Experiment No.7
Aim: Study of System on Board Platform and interface the analog sensors with it:
a) Study the concept of ADC
b) Study the concept of serially bit transmission
Introduction:
MCU are the processors which process the instruction to carry out a task. The MCUs need various other devices to
make it work. As an alternate to do it easy is to use a custom board like Arduino.

Before building any circuit, the parameters of the components in the circuit, such as their operating voltage, operating
circuit, etc. Connecting a current-limiting resistor when an LED is used will be useful or else the LED can become
burned due to excessive current.
Ex: The operating voltage of the LED is between 1.5V and 2.0V and the operating current is between 10mA and
20mA. The Arduino Uno board can supply 5V power, the LED we choose works at 1.7V, 15mA. The current-limiting
resistance equals total voltage subtracted by LED voltage, then divided by current. In this case, that would be (5-
1.7)/0.015. Thus, the current-limiting resistance equals 220Ω.
To download Arduino IDE just google Arduino IDE download and visit Arduino official site. Go to software section
in top menu bar and click on downloads. From there you can download the IDE as per your system configuration. You
can click on My computer properties to check for your system configurations.

1) After your Arduino IDE software is downloaded, you need to unzip the folder. Inside thefolder, you can find the
application icon with an infinity label (application.exe).

Note: Very important point before getting started: You should first plug in your board using a USB cable that comes
with board and then doubleclickthe icon to start the IDE.
Doing so the IDE automatically discover your board. Check whether the machine has been detected using tools-->
Boards and Ports in top Menu Bar.

Since there are many types of Boards, you have be sure if you got correct boards selected and also that the port has
been recognized. If the port is not recognized then unplug and plug your board again.
2) Open your first project.
Once the software starts, you have two
options: Create a new project.
Open an existing project example.
To create a new project, select File --> New.

For look how programs get executed, there are few examples build in Arduino IDE. You can refer to these examples.
The most basic one is Blink. Refer this program and make one by yourself.
To open an existing project example, select File -> Example -> Basics -> Blink.
There are few built in functions like void setup () which has instructions that needed to be executed once and another
important is void loop() that has instructions which needed to be executed repeatedly. Instructions like digitalWrite,
digitalRead, analogRead, analogWrite and pinMode that will be used for input/output operations.

Code:
int sensor= A0;
float svoltage;//voltage coming from sensor to ADC as input
float tempc;// temp in degree celcius to be display on serial monitor
void setup(){
Serial.begin (9600);
}
void loop(){
float xval= analogRead(sensor);
// Output of ADC in digital form but we need analog input
//therefore it will be
resolution*xval. svoltage =
(xval*5000.0)/1023;
tempc= svoltage/10; // conversion factor from
datasheet. Serial.print ("Temperature in degree celsius:
"); Serial.println(tempc);
delay (1500);}
Experiment No.8

Aim: Study of System on Board Platform and interface the digital sensors with it:
a) Interfacing of IR sensor module.
b) Interfacing optical transmitter for fading operation.
Introduction:
The IR Sensor Module or infrared (IR) sensor is a basic and most popular sensor in electronics. It is used in wireless
technology like remote controlling functions and detection of surrounding objects/ obstacles. IR sensors mainly consist
of an Infrared(IR) LED and a Photodiode, this pair is generally called IR pair. An IR LED is a special purpose LED, it
is can emitting infrared rays ranging from 700 nm to 1 mm wavelength. These types of rays are invisible to our eyes.
In contrast, a photodiode or IR Receiver LED detects the infrared rays.

Arduino is a prototype platform (open-source) based on an easy-to-use hardware andsoftware. It consists of a circuit
board, which can be programed (referred to asa microcontroller) and a ready-made software called Arduino IDE
(IntegratedDevelopment Environment), which is used to write and upload the computer code to thephysical board.
Interfacing of Arduino with IR module:
Code:
// Code for digital sensor:

void setup()
{
pinMode(8, OUTPUT);
//pinMode(LED_BUILTIN, OUTPUT);

digitalWrite(8, HIGH);
}

void loop()
{
digitalWrite(8, HIGH);
delay(1000); // Wait for 1000
millisecond(s) digitalWrite(8, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

// Code for IR module:

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}

// the loop function runs over and over again


forever void loop() {
int sensorpin= digitalRead (2);

if (sensorpin==LOW)
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage
level) delay(1000); // wait for a second
}
else
{
digitalWrite(13, LOW); // turn the LED off by making the voltage
LOW delay(1000); // wait for a second
}
}

//Code for Fading optical transmitter

Questions:
 Why do we needed an Arduino?
 Can't Atmega IC alone do the work of Arduino?
 What are functions? Name the functions used in Arduino IDE?
 What do you mean by IDE?
Experiment No.9
Aim: Study the cloud platform of Thingspeak and learn its IoT functionality.
a) Learn to use API keys
b) Learn to use url path for code
Introduction:
ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams
in the cloud. You can send data to ThingSpeak from your devices, create instant visualization of live data, and send
alerts.

It is used for:

1) Send sensor data privately to the cloud.


2) Analyze and visualize your data with MATLAB.
3) Trigger a reaction.
Experiment No.11

Aim: To connect and upload the data of the dht11 sensor on Thingspeak cloud .

Introduction:

ThingSpeak.com is to be used as a cloud service provider and sensor DHT11 will be used to measure temperature and
humidity data.DHT11 will work on two perimeter Temperature and humidity.

Hardware required:

S.No.Item Quantity

1 NodeMCU 1

2 DHT11 Temperature and Humidity sensor 1

3 Jumper Male to female 3

Building Circuit:
Make connections as mentioned ahead.

S.NO. DHT11
NodeMCU

1. Vin VCC

2. GND GND

3. D2 Data Out
Programming:

#include <DHT.h> // Including library for dht

#include <ESP8266WiFi.h>

String apiKey = "OAM1ZJRDAN49H0DX"; // Enter your Write API key from ThingSpeak

const char *ssid = "Jaideep"; // replace with your wifi ssid and wpa2 key
const char *pass = "32@128082";
const char* server = "api.thingspeak.com";

#define DHTPIN 2 //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);
}

Output
Output of this project is seen on Thingspeak and serial monitor. Open your channel at Thingspeak and output will be
shown as mentioned ahead.
Humidity:
Experiment No.12

Aim: To connect the ultrasonic Sensor (HC-SR04) with Arduino and measure distance
using it.

Introduction:

Ultrasonic Sensor HC-SR04 is a sensor that can measure distance. It emits an ultrasound at 40 000 Hz (40kHz) which
travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering
the travel time and the speed of the sound you can calculate the distance.

Hardware required:
1. Arduino UNO R3 CH340 (you can use any Arduino Boards)

2. Ultrasonic Sensor HC-SR04

3. Male to Male Jumper Wires

4. Breadboard

Working:

In order to generate the ultrasound we need to set the Trigger Pin on a High State for 10 µs. That will
send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo
Pin. The Echo Pin will output the time in microseconds the sound wave traveled.
Code:

#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04

#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04

// defines variables

long duration; // variable for the duration of sound wave travel

int distance; // variable for the distance measurement

void setup() {

pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT

pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

Serial.begin(9600); // // Serial Communication is starting with 9600 of baud rate speed

//Serial.println("Ultrasonic Sensor HC-SR04 Test with Arduino UNO R3");

void loop() {

// Clears the trigPin condition

digitalWrite(trigPin, LOW);

digitalWrite(trigPin, HIGH);

//digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

// Displays the distance on the Serial Monitor

Serial.print("Distance: ");

Serial.print(distance);

Serial.println(" cm");

}
Experiment:13

Aim: Interfacing DHT11 Humidity & Temperature Sensor with Arduino.

Introduction:

DHT11 Module features a temperature & humidity sensor complex with a calibrated digital signal output. The
exclusive digital-signal-acquisition technique and temperature & humidity sensing technology ensure high reliability
and excellent long-term stability. This sensor includes an NTC for temperature measurement and a resistive-type
humidity measurement component for humidity measurement. These are connected to a high-performance 8-bit
microcontroller, offering excellent quality, fast response, anti-interference ability, and cost-effectiveness.
Code:

#include <DHT.h>
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

//Variables
int chk;
float hum; //Stores humidity value float
temp; //Stores temperature value

void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp hum =
dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
}

You might also like