Embedded Systems and IOT Lab Manual Final
Embedded Systems and IOT Lab Manual Final
LABORATORY RECORD
BACHELOR OF ENGINEERING
IN
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
May 2024
MAR EPHRAEM COLLEGE OF ENGINEERING &
TECHNOLOGY
Malankara Hill, Elavuvilai -629171
Kanyakumari District
LABORATORY RECORD
20 - 20
A. 1. The record of an experiment should be submitted on the day the students come to the
same laboratory to perform the next experiment.
2. Only such experiment as done by the candidate should be recorded in the order in which
they are done.
B. The record should be written neatly in ink, excepts for the diagrams which should be in
pencil.
C. Every experiment should begin on a new page.
D. The Right hand page should contain:
1. Date of performance of the experiment in the margin at the top.
2. Serial number just below the date.
3. Experiment number and the title of the experiment on the first line followed by:
a. Aim of the experiment.
b. Apparatus required.
c. Materials required.
d. Principle
e. Procedure (Including precaution if any)
f. Results
E. The Left hand page should contain the following in the same order:
1. Diagram of the apparatus if any.
2. Circuit diagrams if any.
3. Observations, if any, in tabular form.
4. Sample calculations if any
5. Graphs if any, to be pasted.
3
Index
SI.No Exp.date Name of the Experiment Page No Signature
4
EX.NO:1 8051 ASSEMBLY LANGUAGE EXPERIMENTS USING
SIMULATOR
DATE :
AIM
To Write 8051 Assembly Language experiments using simulator.
COMPONENTS REQUIRED
THEORY :
The assembly language is a low-level programming language used to write program code
in terms of mnemonics. Even though there are many high-level languages that are currently in
demand, assembly programming language is popularly used in many applications. It can be used
for direct hardware manipulations. It is also used to write the 8051 programming code efficiently
with less number of clock cycles by consuming less memory compared to the other high-level
languages.
The assembly language is a fully hardware related programming language. The embedded
designers must have sufficient knowledge on hardware of particular processor or controllers
before writing the program. The assembly language is developed by mnemonics; therefore, users
cannot understand it easily to modify the program.
Assembly programming language is developed by various compilers and the
“keiluvison” is best suitable for microcontroller programming development.
Microcontrollers or processors can understand only binary language in the form of ‘0s or 1s’; An
assembler converts the assembly language to binary language, and then stores it in
the microcontroller memory to perform the specific task.
PROCEDURE
1. Open EDSIM51 Software and set the clock frequency default by 12 MHZ.
2. Type and Save the Program with Extension asm.
3. Assemble the Source code.
4. Run the Program and getting the results.
PROGRAM:
ADDITION:
MOV A,#50H
MOV R1,#30H
ADD A,R1
EXIT:SJMP EXIT
5
OUTPUT :
ADDITION:
OUTPUT:
LED DISPLAY:
6
PROGRAM :
LED DISPLAY:
BACK:MOV A,#00H
MOV P1,A
ACALL DELAY
MOV A,#0FFH
MOV P1,A
ACALL DELAY
SJMP BACK
DELAY:
MOV R7,#01H
L1:DJNZ R7,L1
RET
RESULT
Thus the 8051 Assembly Language Programs was simulated.
7
EXP NO : 2
TEST DATA TRANSFER BETWEEN REGISTERS AND
DATE :
MEMORY
AIM:
To Test data transfer between registers and memory by using simulator
SOFTWARE REQUIRED:
Edsim51
PROCEDURE:
1. Open EDSIM51 Software and set the clock frequency default by 12 MHZ.
PROGRAM:
ORG 0x0000;
MOV A, #0x55;
MOV @R0, A;
MOV A, #0xAA;
MOV A, @R0;
END;
8
OUTPUT:
RESULT:
Thus the data transfer between registers and memory by using simulator was successfully tested.
9
EXP NO : 3
DATE : PERFORM ALU OPERATIONS
AIM:
To Preform Arithmetic and Logical Operations by using Edsim51 Simulator
SOFTWARE REQUIRED:
Edsim51
PROCEDURE:
1. Open EDSIM51 Software and set the clock frequency default by 12 MHZ.
2. Type and Save the Program with Extension asm
3. Assemble the Source code
4. Run the Program and getting the results.
PROGRAM:
Arithmetic Operations:
10
Logical Operations:
Bitwise AND:
ORG 0x0000;
MAIN: MOV A, #0x0F;
MOV B, #0x3C;
ANL A, B;
END;
Bitwise OR:
ORG 0x0000;
MAIN:MOV A, #0x27;
MOV B, #0x35;
ORL A, B;
END;
Bitwise NOT:
ORG 0x0000;
MAIN:MOV A, #0x27;
CPL A;
END;
Bitwise NAND:
ORG 0x0000;
MAIN: MOV A, #0x0F;
MOV B, #0x3C;
ANL A, B;
CPL A;
END;
Bitwise NOR:
ORG 0x0000;
MAIN:MOV A, #0x27;
MOV B, #0x35;
ORL A, B;
CPL A;
END;
Bitwise XOR:
ORG 0x0000;
MAIN:MOV A, #0x0F;
MOV B, #0x3C;
XRL A, B;
END;
11
Fig: Output of addition of two 16 bit numbers
12
Fig: Output of Bitwise logical AND operation
13
Fig: Output of Bitwise logical NOT operation
14
Fig: Output of Bitwise logical NOR operation
RESULT:
Thus the ALU operations are verified successfully using Edsim51 Simulator.
15
EXP NO : 4
BASIC AND ARITHMETIC PROGRAMS USING
DATE : EMBEDDED C.
AIM:
To Write Basic and arithmetic Programs Using Embedded C.
SOFTWARE REQUIRED:
Keil micro version 5 with PC
PROCEDURE:
1. Start the Keil software. Go to the Project > New Project then choose a location to store your
program, and give a name and Save.
2. Now in the next window select the device from different manufacturers. We are
selecting Microchip, and then by expanding we are selecting AT89C51 device and click ok
3. Now go to the New in the menu and select New. It will open a new editor to write code.
4. Go to the save option and save the program file with .asm extension.
5. Write the code for 8051 Microcontroller. (Here we are using a arithmetic cides)
6. Now from the left panel, select Source Group 1, and Add Existing Files to Group ‘Source Group
1’. Then select the program (c file) then add and close
7. now go to the Project > Build Target to build the project. If there is some error the building will
be failed, after correcting the errors it can be build.
8. Now click on the Target1 from the left panel and select Options for Target ‘Target1’. Then set
the xtal (MHz) value to 11.0592. Check mark on the Use On Chip ROM. Then go to the output tab.
In this tab check Create Hex File, and click OK. Then build it again.
PROGRAM:
# include<reg51.h>
void main(void)
{
unsigned char x,y,z, a,b,c, d,e,f, p,q,r; //define variables
//addition
x=0x12; //first 8-bit number
y=0x34; //second 8-bit number
P0=0x00; //declare port 0 as output port
z=x+y; // perform addition
P0=z; //display result on port 0
//subtraction
a=0x12; //first 8-bit number
b=0x34; //second 8-bit number
P1=0x00; //declare port 1 as output port
c=b-a; // perform subtraction
P1=c; //display result on port 1
//multiplication
d=0x12; //first 8-bit number
e=0x34; //second 8-bit number
P2=0x00; //declare port 2 as output port
16
f=e*d; // perform multiplication
P2=f; //display result on port 2
//division
p=0x12; //first 8-bit number
q=0x34; //second 8-bit number
P3=0x00; //declare port 3 as output port
r=q/p; // perform division
P3=r; //display result on port 3
while(1);
}
Theory:
Operators in Embedded C programming are symbols that perform specific operations on values or variables.
Mathematical and logical operations is one of the important tasks that any microcontrollers have to perform during
execution of set of instructions based on the user data expressions. This operation in embedded C will be
performed
with special symbolic operator called as “Operators in C”. To execute this operation C compiler recognizing them
with with special symbols. Operators are the symbols that help in performing operations of mathematical and
logical format
Arithmetic Operators:
Embedded C supports standard arithmetic operators such as +(addition), -(subtraction), *(multiplication),
/(division), and %(modulus).
17
ADDTION OUTPUT
SUBTRACTION OUTPUT
MULTIPICATION OUTPUT
18
DIVISION OUTPUT
RESULT:
Thus the Basic and arithmetic Programs Using Embedded C was Executed successfully.
19
EX.NO:5 INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING
DATE :
AIM
To develop a Platform and Programming by using Arduino.
COMPONENTS REQUIRED
PROCEDURE
20
List of all boards using the AVR core.
Downloading and installing
1. First, we need to download the Arduino IDE, which can be done from the software page.
2. Install the Arduino IDE on your local machine.
3. Open the Arduino IDE.
Choosing the board
First, we need to select the right core & board. This is done by navigating to Tools > Board >
Arduino AVR Boards > Board. Make sure you select the board that you are using. In this case, we are
using an Arduino UNO.
21
Selecting the right board and port.
This will look different depending on what kind of operative system you are using.
For Windows users, it could look like this:
<COM9> (Arduino Uno)
For MAC users, it could look like this:
/dev/cu.usbmodem14112 (Arduino Uno)
Uploading a simple example
You are now ready to start using your board! The easiest way to check that everything is working, is to
upload just a simple blink example to your board. This is done by navigating to File > Examples
> 01.Basics > Blink.
22
Uploading the sketch.
When the code is uploaded, the text
"Done uploading."
is visible in the bottom left corner.
If you look closely at your board, you will notice an orange LED blink with an interval of one
second. This means you have successfully uploaded a program to your board.
23
PROGRAM :1
WRITE DIGITAL OUTPUT- BLINKING A LED
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
RESULT
Thus the LED blinking with Arduino Programming was successfully executed.
24
EXP NO : 6 EXPLORE DIFFERENT COMMUNICATION METHODS WITH
DATE : IOT DEVICES
AIM:
To Explore Different Communication Methods with IoT Devices(Zigbee,GSM,Bluetooth)
PROCEDURE:
After this, go to Tool/ Board Tools/board/board manager and type ESP8266. You will find a board
of ESP8266 click on the install option.
25
this is how your ESP8266 board get installed
After installing the ESP8266 board in Arduino, you need to follow few simple steps:
26
Now go to file and open blink sketch and replace keyword "Inbuild_LED" with "2", as the ESP8266
board's inbuild LED is connected to pin 2.
Procedure:
Configuring Blynk App for ESP32
Following are the steps to configure Blynk app in your phone and use it for a project:
1. Firstly, download Blynk app in your phone from Google play store and install it.
2. After installing, you need to create an account in this app; you may use your current Gmail account.
3. After creating account a window will open, in this click on New Project.
27
4. Now give project a name according to your choice and in device choose ESP32 Dev Board and in
Connection type choose Wi-Fi and then click on Create.
5. Now a window will come which shows that your authentication token which you will need later
sent to your concerned mail ID. You can open your email to check authentication key.
28
8.Click on the Button widget to change the setting.
9.Set output pin to gp2 as I am taking output here from GPIO2 pin, you can change according to you. In
Mode select to switch.
10.When you are done with this setting, you are ready to work with this app. On pressing Play button it
will switch you from EDIT mode to PLAY mode where you can interact with the hardware. In PLAY
mode, you will not be able to drag or set new widgets, press STOP to get back to STOP mode.
Programming ESP32 for Blynk Application
First of all, you have to download the Blynk library from the given link.
https://github.com/blynkkk/blynk-library
It is a zip file, download it and extract it and then copy this library file to Arduino Library files. You
can find your Arduino library file in Documents--> Arduino--> libraries. Copy this library file here.
Now in programming, the first thing you have to do is include the required libraries.
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
Now define your output pin, here I am taking my output from GPIO 2 so I will include pin 2.
int pin = 2;
Now enter your Authentication token and your network credentials inside double inverted commas.
char auth[] = " ";
char ssid[] = " ";
char pass[] = " ";
In void setup() function, we will initialize the baud rate, LED output and will connect the module with
the Wi-Fi using WiFi.begin(ssid,password); function. This function begins the Wi-Fi connection.
In the loop function include Blynk.run() command.
void loop(){
Blynk.run();
}
29
Programming of ESP32 with Arduino IDE and Blynk app
Now you are in a stage to upload the code in your ESP32 and perform the project, for this following
steps should be performed:
1. Connect ESP32 to your PC via USB cable and make circuit as given above, here I am using GPIO2
you can use according to you.
2. Open your Arduino IDE and copy this code to your IDE window but make sure that you provide
correct WiFi credentials of your network.
3. Now go to Tools--> Board--> ESP32 Dev module.
4. Then Tools-->Port and select port to which your ESP32 is connected.
5. Now click on upload to upload the code.
6. After complete uploading you will find message like this in your output console.
7. Now open your serial monitor and press reset button of ESP32 and now ESP starts connecting to
your network, once connected it will give you IP of your ESP and message like this:
8. Now open Blynk app and go to the project you created earlier and tap on PLAY.
9. Now you can see on clicking on button your LED will change its state.
This is how you are successfully able to control LED using ESP32 with Blynk App.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "unGDlpBNJzl3Y6KtE87oqswB-54WrWEy";
// Your WiFi credentials.
30
// Set password to "" for open networks.
char ssid[] = "................ ";
char pass[] = " .................";
int LED = D1; // Define LED as an Integer (whole numbers) and pin D8 on Wemos D1 Mini Pro
void setup()
{
//
Debug console
Serial.begin(115200);
pinMode(LED, OUTPUT); //Set the LED (D8) as an output
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
PIN DIAGRAM
31
RESULT:
Thus the Different Communication Methods with IoT Devices was Executed Successfully
32
EXP NO : 7 INTRODUCTION TO RASPBERRY PI PLATFORM AND
DATE : PYTHON PROGRAMMING
AIM:
To develop a Raspberry Pi Platform and Python Programming
SOFTWARE REQUIRED:
Raspberry pi
HDMI to VGA Cable
Power cable
Monitor
PROCEDURE
o Look at your Raspberry Pi. Can you find all the things labelled on the diagram?
USB ports — these are used to connect a mouse and keyboard. You can also connectother
components, such as a USB drive.
SD card slot — you can slot the SD card in here. This is where the operating systemsoftware
and your files are stored.
Ethernet port — this is used to connect Raspberry Pi to a network with a cable. Raspberry Pi
can also connect to a network via wireless LAN.
Audio jack — you can connect headphones or speakers here.
HDMI port — this is where you connect the monitor (or projector) that you are using to display
the output from the Raspberry Pi. If your monitor has speakers, you can also use them to hear
sound.
Micro USB power connector — this is where you connect a power supply. You should always
do this last, after you have connected all your other components.
GPIO ports — these allow you to connect electronic components such as LEDs and buttons to
Raspberry Pi
33
Set up your SD card
If you have an SD card that doesn’t have the Raspberry Pi OS operating system on it yet, or if
you want to reset your Raspberry Pi, you can easily install Raspberry Pi OS yourself. To do
so, you need a computer that has an SD card port — most laptop and desktop computers have
one.
The Raspberry Pi OS operating system via the Raspberry Pi Imager
Using the Raspberry Pi Imager is the easiest way to install Raspberry Pi OS on your SD card.
Note: More advanced users looking to install a particular operating system should use this
guide to installing operating system images.
Download and launch the Raspberry Pi Imager
o Click on the link for the Raspberry Pi Imager that matches your operating system
34
o When the download finishes, click it to launch the installer
Anything that’s stored on the SD card will be overwritten during formatting. If your SD card
currently has any files on it, e.g. from an older version of Raspberry Pi OS, you may wish to
back up these files first to prevent you from permanently losing them.
When you launch the installer, your operating system may try to block you from running it. For
example, on Windows I receive the following message:
35
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
In the Raspberry Pi Imager, select the OS that you want to install and the SD card youwould
like to install it on
Note: You will need to be connected to the internet the first time for the 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.
36
Then simply click the WRITE button
Wait for the Raspberry Pi Imager to finish writing
Once you get the following message, you can eject your SD card
37
Note: Many microSD cards come inside a larger adapter — you can slide the smaller card out
using the lip at the bottom.
o Find the USB connector end of your mouse’s cable, and connect the mouse to a USB port
on your Raspberry Pi (it doesn’t matter which port you use).
o Make sure your screen is plugged into a wall socket and switched on.
o Look at the HDMI port(s) on your Raspberry Pi — notice that they have a flat side on top
38
Use a cable to connect the screen to the Raspberry Pi’s HDMI port — use an adapter if
necessary.
Raspberry Pi 4
Connect your screen to the first of Raspberry Pi 4’s HDMI ports, labelled HDMI0.
Raspberry Pi 1, 2, 3
Connect your screen to the single HDMI port.
39
Note: nothing will display on the screen, because the Raspberry Pi is not running yet.
o If you want to connect the Pi to the internet via Ethernet, use an Ethernet cable to connect
the Ethernet port on the Raspberry Pi to an Ethernet socket on the wall or on your internet
router. You don’t need to do this if you want to use wireless connectivity, or if you don’t
want to connect to the internet.
o If your screen has speakers, your Raspberry Pi can play sound through these. Or you could
connect headphones or speakers to the audio port.
o Plug the power supply into a socket and connect it to your Raspberry Pi’s power port.
40
You should see a red LED light up on the Raspberry Pi, which indicates that Raspberry Pi is connected
to power. As it starts up (this is also called booting), you will see raspberries appear in the top left-
hand corner of your screen.
When you start your Raspberry Pi for the first time, the Welcome to Raspberry Pi application will pop
up and guide you through the initial setup.
41
o Enter a new password for your Raspberry Pi and click Next.
o Connect to your WiFi network by selecting its name, entering the password, and
clicking Next.
42
Note: if your Raspberry Pi model doesn’t have wireless connectivity, you won’t see thisscreen.
o Click Next let the wizard check for updates to Raspbian and install them (this might take a
little while).
43
A tour of Raspberry Pi
44
o Type I just built a Raspberry Pi computer in the window that appears.
o Click on File, then choose Save, and then click on Desktop and save the file as .
45
Close the text editor by clicking the X in the top right-hand corner of the
window.
ls
and then press Enter on the keyboard.
You can now see a list of the files and folders in your directory.
46
o Now drag to the Wastebasket on the desktop so the Raspberry Pi will be tidy for the next
person using it.
You might want to connect your Raspberry Pi to the internet. If you didn’t plug in
an Ethernet cable or connect to a Wi-Fi network during the setup, then you can connect now.
Click the icon with red crosses in the top right-hand corner of the screen, and select your
network from the drop-down menu. You may need to ask an adult which network you should choose.
o Type in the password for your wireless network, or ask an adult to type it for you, then
click OK.
o When your Pi is connected to the internet, you will see a wireless LAN symbol instead of
the red crosses.
47
Configuring your Raspberry Pi
You can control most of your Raspberry Pi’s settings, such as the password, throughthe
Raspberry Pi Configuration application found in Preferences on the menu.
System
In this tab you can change basic system settings of your Raspberry Pi.
48
Password — set the password of the pi user (it is a good idea to change the passwordfrom the factory
default ‘raspberry’)
Boot — select to show the Desktop or CLI (command line interface) when yourRaspberry Pi starts
Auto Login — enabling this option will make the Raspberry Pi automatically log inwhenever it starts
Network at Boot — selecting this option will cause your Raspberry Pi to wait until a network
connection is available before starting
Splash Screen — choose whether or not to show the splash (startup) screen when yourRaspberry Pi boots
Interfaces
You can link devices and components to your Raspberry Pi using a lot of different types of
connections. The Interfaces tab is where you turn these different connections on or off, so that your
Raspberry Pi recognizes that you’ve linked something to it via a particular type of connection.
49
Performance
If you need to do so for a particular project you want to work on, you can change theperformance
settings of your Raspberry Pi in this tab.
Warning: Changing your Raspberry Pi’s performance settings may result in it behavingerratically or
not working.
Localisation
50
This tab allows you to change your Raspberry Pi settings to be specific to a country orlocation.
Locale — set the language, country, and character set used by your Raspberry Pi
Timezone — set the time zone
Keyboard — change your keyboard layout
WiFi Country — set the WiFi country code
Introduction to Python
The Raspberry Pi made physical computing and programming accessible to many -- it is relatively inexpensive, and
almost anyone could simply connect a monitor, keyboard, and mouse to get started. Python is an easy to start with
high-level language, and it is an integral part of the Raspberry Pi's operating system.
In this guide, we'll show you how to get started with the Thonny IDE, learn about basic data types and control flow
statements that are readily used when working with sensors and actuators on the Raspberry Pi.
Complete this guide to get started with Python programming on the Raspberry Pi.
Step 1 Overview
● The Raspberry Pi was created so that computing could be more accessible for everyone -- it
is relatively inexpensive, and anyone could simply connect a monitor, keyboard, and mouse to get
started. As sensors, actuators and other devices can be easily attached to it via its handy General
purpose Input Output (GPIO) connector, it also serves as a gentle introduction into physical
computing. The other impetus was to make programming more accessible, especially for beginners
and kids. That's why Python is an integral part of the Raspberry Pi's operating system!
● In this guide, will show you how to get started with programming in Python on the Pi. We'll
also briefly talk about the commonly used data types.
Step 2 What is a programming language?
Machine language or machine code is a lower-level form that is read and executed by the
computer. This language is comprised of binary, 0's and 1's. In this machine code, all instructions,
memory locations, numbers, and characters are represented in 0's and 1's.
While they can run and execute fast, the main disadvantage is that it is tedious for humans to use,
maintain, or debug. Enter high-level languages, these are languages that seem a lot more like our
human language, enabling us to focus on problem-solving.
Still, programming languages such as Java or C++ require the use of a compiler, which is a program
that converts human-readable instructions or code, into machine code, and is then executed and run.
On the other hand, a programming language such as Python is executed directly using
an interpreter, rather than needing to go through a compiler. The code is read one at a time, where
each statement is translated into machine language and then executed.
● While a compiler scans the entire program and translates it as a whole into machine code, an
interpreter translates the program one statement at a time.
Step 3 Starting Python for the First Time
52
● One of the challenges when beginning to use Python is the need to install Python and other related
software. Thankfully, all this is already set up for you in the latest version of Raspbian with
PIXEL desktop, specifically Raspbian Buster at this time of writing.
The easiest way to get started is to use Thonny, a new IDE (integrated development environment)
that can be easily accessed by navigating to Raspberry Pi icon (menu) > Programming >
Thonny Python IDE
● You will see a script editor and a shell, you enter a program in the script editor and run it in the
shell. Let's write our first program!
Step 4 Save and execute code
● Another way to write and run python programs is through the terminal. To access the terminal,
click on the terminal icon up the top left-hand corner.
54
● Type the following command: Nano helloworld.py
● Enter the following code
● Press CTRL+O to save
● Press CTRL+X to exit
● Now you can run the saved script by using the command: python helloworld.py
RESULT:
Thus the Raspberry pi Platform and python installed successfully.
55
EXP NO : 8
DATE : INTERFACING SENSORS WITH RASPBERRY PI
AIM:
To Interface a Temperature Sensor with Raspberry Pi
SOFTWARE REQUIRED:
A Raspberry Pi (any model)
A DS18B20 Temperature Sensor
A 4.7K Ohm Resistor (Colour Code: Yellow Purple Red Gold)
A Breadboard
3 x Female to male jumper cables.
1 x Male to Male jumper cable (Optional, see the comment in the Getting Started
paragraphbelow)
An Internet connection for your Raspberry Pi
PROCEDURE:
With your Raspberry Pi turned off, build the circuit as per this
diagram. The DS18B20 is placed into the breadboard so that the
flat side faces you.
The black jumper cable goes from GND, which is the third pin down on the right
column to the first pin of the DS18B20.
The yellow jumper cable goes from the fourth pin down on the left column and is
connected to the middle pin of the DS18B20.
The red jumper cable goes from the top left pin of the Raspberry Pi to the far right pin
of the DS18B20.The Resistor connects the RIGHT pin to the MIDDLE pin. This is called
a pull up resistor and is used to ensure that the middle pin is always on. In the diagram
I had to use a spare red wire to show this connection. But in reality, using the resistor to
make the connection, as per this photo is the best way.
Now attach your keyboard, mouse, HDMI and power to your Raspberry Pi and boot to the desktop.
Configuring the Raspberry Pi
We now need to take two steps to enable our DS18B20 for use.
Install the Python Library
Firstly we need to install a Python library, pre-written code that enables the Python code that we
shall later write to talk to the sensor. The Python library is called w1thermsensor and to install it
we need to use the Terminal. You can find the terminal icon in the top left of the screen. It looks
like...
When the terminal opens, enter the following to install the library, just press ENTER to start.
The DS18B20 uses a 1 wire serial interface, this is the middle pin of the sensor, that is connected to
the Raspberry Pi via the yellow wire in the diagram. We need to tell our Raspberry Pi that we are
using this pin and to do that we use the Raspberry Pi Configuration tool, found in the
Preferences menu.
When it opens, click on the Interfaces tab and then click on Enable for the 1-Wire interface.
Now click on Ok and you will be asked to reboot, so go ahead and do that, and let the Raspberry
Pi reboot to the desktop.
When the application opens, click on File >> New to create a new blank document. In this new
window, click on File >> Save and call the project temperature-sensor.py Remember
to save your work often!
Importing the libraries
The first step in any Python project that uses libraries is to import the libraries that we wish to
use. In this case we import time to control how often the sensor data is collected, and weimport
w1thermsensor to enable our project to talk to the sensor.
So lets import the libraries.
import time
from w1thermsensor import W1ThermSensor
Sensor
Our next line is to create an object to store a connection the sensor. So rather thantyping
W1ThermSensor() everytime we want to use the sensor, we store the connection in an object called
sensor.
sensor = W1ThermSensor()
Running in a loop
We'd like to get the temperature sensor data every second, and run forever. So let's use a while
True loop to run the code inside of it forever.
while True:
Now the next lines of code are indented, this is how Python shows that this code belongs inside
the loop that we have just created.
The first thing to do in our loop is to get the current temperature from the DS18B20 sensor, and
then store it in a variable called temperature. Variables are boxes / containers into which we can
store any data.
temperature = sensor.get_temperature()
Now that we have the data, lets print it to the screen using the print() function. But lets use the
data in the form of a sentence that will tell the us what the temperature is in celsius. For this we
use a little Python trick called string formatting, where we would like the temperature data to be
printed in the sentence, we use an %s which will format the temperature data from an float (a
number with a decimal place) to a string (text, characters that can be printed but not used in any
mathematical equations)
Our last line of Python code will tell the Raspberry Pi to wait for 1 second between taking a
temperature reading.
time.sleep(1)
That's all of the code, so make sure that you save your work.
Complete Code Listing
Check that your code matches the code below before moving on.
import time
from w1thermsensor import W1ThermSensor
sensor = W1ThermSensor()
while True:
temperature = sensor.get_temperature()
print("The temperature is %s celsius" % temperature)
time.sleep(1)
Run the Code!
To run the code, click on Run >> Run Module and you will see the Python Shell window pop
upand start displaying temperature data!
RESULT:
Thus the temperature Sensor was Successfully Interface with RaspberryPi.
61
EX.NO:9 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI
USING ANY WIRELESS MEDIUM
DATE :
AIM
To Develop a Communicate Between Arduino And Raspberry Pi Using Any Wireless
Medium.
COMPONENTS REQUIRED
PROCEDURE
1.Download Raspbian: Your Pi needs an OS. Download Raspbian from Raspberrypi.org ‘s download section:
https://www.raspberrypi.org/downloads/raspbian/
2.download SD Memory Card Formatter: It is used to format the SD card as it is needed that the SD card
should be empty before the flashing image you downloaded. You can download it from
https://www.sdcard.org/downloads/formatter/eula_windows/
3.Flash it onto an SD card: You need to flash this downloaded image to the micro SD card. Assuming your
laptop has an SD card slot or a micro Sd card reader, you need a flashing software like etcher. Go ahead and
download from https://etcher.io/
4.Configure Wi-Fi: It’s easier to make two devices talk to each other if they are in the same network. An
ethernet cable can easily make your laptop’s network available to the Pi. But we don’t have one. So, we are
going to add a file to the SD card so that the Pi boots with a wifi pre-configured. The SD card mounts as two
volumes boot and rootfs . Open the boot volume and create a file named wpa_supplicant.conf on booting the
RPi, this file will be copied to /etc/wpa_supplicant directory in /rootfs partition. The copied file tells the Pi
the WIFI setup information. This would overwrite any existing WIFI configuration, so if you had already
configured WIFI on the pi, then that will be overwritten.
A typical wpa_supplicant.conf file is as follows:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1country=US
network={ ssid="«your_SSID»" psk="«your_PSK»" key_mgmt=WPA-PSK}
NOTE: Your SSID is your WIFI’s name. And psk is the password of the WI-FI.
5. Enable SSH We will later access the Pi using a secured shell (SSH), SSH is disabled by default in Raspbian.
To enable SSH, create a file named ssh in the boot partition. If you are on Linux, use the touch command to
do that.
62
6) Find Pi’s Ip address: Before switching on your raspberry pi, we need to find out the existing devices
connected to the network. Make sure your laptop is connected to the same WIFI network as the one you
configured on pi above. Download the Advanced IP Scanner to scan the IP of our raspberry pi. You can
download it from here https://www.advanced-ip-scanner.com/
7) SSH into your Pi: To create a secured shell connection in Linux we can use the ssh command. If you are
on windows, try downloading Putty from https://www.putty.org/
63
Default credentials are:
username: pipassword: raspberry
8) Access Pi remotely: Sometimes it doesn’t feel right if we can’t use the mouse. For that, we need to look
into the Raspbian desktop. We need to setup VNC (Virtual Network Connection) to see and control Pi
graphically. Let’s do that. To access the remote desktop, you need VNC-viewer (client) for your laptop.
Fortunately, RealVNC is available for a lot of OSes, pick one for your OS from
https://www.realvnc.com/en/connect/download/viewer/
9) Commands for vncserver:
64
10) Now open VNC Viewer on your remote computer:
Schematic Diagram for wiring of Arduino Uno with ultrasonic sensor and NRF24L01
To wire your NRF24L01+ wireless sender to your Arduino, connect the following pins:
Connect the VCC pin to 3.3 Volts
Connect the GND pin to ground (GND)
Connect the CE pin to Arduino 9
Connect the CSN pin to Arduino 10
Connect the SCK pin to Arduino 13
Connect the MOSI pin to Arduino 11
Connect the MISO pin to Arduino 12
Schematic Diagram for wiring of Arduino Uno NRF24L01
NOTE: RF24 module is mandatory for the code to run so you can add the library accordingly
Start Arduino IDE then add the Downloaded Library from Here :
66
5.2. Code:
Sender Side code:
Receiver Side code:
Sending the Data
67
Wireless communication of Arduino to Raspberry Pi with nRF24L01:
Installation of RF24 Module on Raspberry Pi:
It is the most important and foremost step for any Communication to work between Arduino and Raspberry
Pi as we have used RF24 library in Arduino for communication so the same Library isneeded on Pi.
Further are the steps to which involve the installation of the Library. It took me almost one week to install it
as no clear idea about it is present.
=> Way to go:
1. Login to Raspberry Pi using Putty.
2. Go to the VNC server for GUI.
3. In the terminal type: sudo raspi-config
68
4. Reboot the Pi. In the terminal, type: sudo reboot
5. In the terminal type: sudo apt-get update
6. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh or Run
this on terminal: wget http://tmrh20.github.io/RF24Installer/RPi/install.sh
7. Make it executable: chmod +x install.sh
8. Run it and choose your options:
69
Schematic Diagram:
70
RESULT
Thus the Temperature Sensor with Raspberry Pi was interfaced successfully.
71
EXP NO : 10
Setup a cloud platform to log the data
DATE :
AIM:
To Setup a cloud platform to log the data by using Arduino and Rasberry Pi.
SOFTWARE REQUIRED:
Google Colud
PROCEDURE:
72
Click Next
In the next page, click – Yes, I’m in
In the next page, agree to the T&C
Agree the terms and conditions and you now have a free tier account for GCP
73
Click on the Activate Button to go to the next page
In the next page – select your country and Agree to the T&C and click Continue
74
Select the project My first project and you are good to go.
75
After clicking on VM Instances it will show below screen
Now Click on CREATE INSTANCE above to create a new instance.
76
Boot disk: click on change (now you will see other screen like below right side)
Operation system: choose Ubuntu
Version: Ubuntu 18.04LTS
Boot disk type: leave the default
Size: leave the default
Then click on “select” at the bottom
Now you should see as below left side Boot disk section shows Ubuntu Identity
and API access Section:
Service account: Compute Engine default service account (default)
Access scopes: Allow default access (default)
Now click on “create” at the bottom.
77
To create more VMs, repeat same process
Step 1: On the navigation menu on the left, scroll down and go to Networking section -
> VPC network – > VPC networks.
78
Step 3: Click on the Edit link.
Step 4: Choose All instances in the network from the Targets dropdown.
79
Step 5: Source filter should be selected to IP ranges.
Step 6: Select Allow all from Protocols and ports and click save.
Step 7: Once the rule is saved, you will view this screen.
80
RESULT:
81
EXP NO : 11 LOG DATA USING RASPBERRY PI AND UPLOAD TO THE CLOUD
PLATFORM
DATE :
AIM:
To Log Data Using Raspberry Pi and Upload To The Cloud Platform.
SOFTWARE REQUIRED:
Raspberry Pi
DHT11 Sensor
Jumper Cables
PROCEDUR:
Step 1: Signup for ThingSpeak
For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if you
already have account on ThingSpeak just sign in using your id and password.
For creating your account go to www.thinspeak.com
Click on signup if you don’t have account and if you already have account click on sign in. After
clicking on signup fill your details.
82
Step 2: Create a Channel for Your Data
Once you Sign in after your account verification, Create a new channel by clicking “New Channel”
button
After clicking on “New Channel”, enter the Name and Description of the data you want to upload on
this channel. For example I am sending my CPU data (temperature), so I named it as CPU data.
Now enter the name of your data (like Temperature or pressure) in Field1. If you want to use more than
one Field you can check the box next to Field option and enter the name and description of your data.
After this click on save channel button to save your details.
83
Now copy your “Write API Key”. We will use this API key in our code.
python /path/filename.py
Case 1: If you are using monitor screen then just use the given code. Now
install all libraries:
84
If there are any errors uploading the data, you will receive “connection failed” message.
Case 2: If you are using “Putty” then you should follow these commands: First
update your pi using:
nano cpu.py
After creating this file copy your code to this file and save it using CTRL + X and then ‘y’ and
Enter.
After this install all libraries using:
python cpu.py
If the code runs properly you will see some CPU temperature values as shown in above image.
85
Like this you can send any sensor data connected with Raspberry pi to the ThingSpeak Cloud. In next
article we will connect LM35 temperature sensor with Raspberry Pi and send the temperature data to
ThingSpeak, which can be monitored from anywhere.
Complete Python code for this Raspberry Pi Cloud Server is given below. Code is easy and self-
explanatory to understand.
Code
import httplib
import urllib
import time
key = "ABCD" # Put your API Key here
def thermometer():
while True:
#Calculate CPU temperature of Raspberry Pi in Degrees C
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Get Raspberry Pi CPU
temp
params = urllib.urlencode({'field1': temp, 'key':key })
headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80") try:
conn.request("POST", "/update", params, headers) response =
conn.getresponse()
print temp
print response.status, response.reason data =
response.read()
conn.close() except:
print "connection failed" break
if name == " main ":
while True:
thermometer()
RESULT:
Thus the data was uploaded Sucessfully in the Cloud by using Raspberry Pi
86
EXP NO : 12 DESIGN AN IOT BASED SYSTEM
DATE :
AIM
To Design an IOT Based System Hardware Requirements
1. Arduino UNO board
2. USB cable for connecter Arduino UNO
3. Bluetooth Module HC-05
4. Jumper wires male to female
5. LED
6. AC 220v/120v home appliances or 9v Hi-Walt Battery
SOFTWARE REQUIREMENTS
1. Arduino software
2.Android Studio
PROCEDURE:
In this project, there are three main components used; an Android Smartphone, Bluetooth transceiver,
and an Arduino.
The Android app is built to send serial data to the Bluetooth Module HC-05 by pressing ON button. As
Bluetooth Module HC-05 works on serial communication. It receives the data from the app and sends it
through TX pin of Bluetooth module to RX pin of Arduino. The uploaded code inside Arduino checks
the data received. If the receive data is 1, the LED turns ON, and if the received data is 0 the LED turns
OFF.
TX > RX (Pin 0)
RX > TX (Pin 1)
VCC > 5v
GND > GND
87
LED Pin ARDUINO UNO
Pin1 >GND
Pin 2 > Pin13
For doing the programming for Arduino board, we need to download Arduino software. This can be
done from Arduino official site https://www.arduino.cc/
88
Click Download
After successful download, run the setup and follow the instructions.
89
90
When it asks to install the driver software, click to install
After installation, open the software, and if it generates a security alert then allow it.
91
Write a program for Arduino UNO board, if received data is equal to 1, LED turns on and if data is
equal to 0, LED turns OFF.
92
Connect your Arduino device to your Laptop (or Monitor) via Arduino UNO USB cable. Remove all the
other connections with Arduino UNO device such as Bluetooth Module and LED while uploading the
program in Arduino UNO.
After compiling the code, upload it in Arduino UNO device. Before uploading the code in Arduino,
UNO device makes sure that your Arduino serial port is selected otherwise, it generates an error message
"Serial port not selected".
To select your serial port, open Device Manager > Ports >Arduino Uno, and then upload your code.
Download the Android app's .apk file and install it on your Android smartphone. Click Here to Download
1.Open Bluetooth connecter app and allow turning on Bluetooth of the device.
93
2.Search for Bluetooth device for making the pair.
3.To pair with Bluetooth HC-05 module, enter a pin 0000 or 1234.
94
5.Control LED device.
While clicking "ON" button it sends data 1 to Bluetooth module and this data is transmitted
from the Bluetooth module to Arduino device and it turns ON the LED. When clicking
"OFF", Android app sends data 0 to Bluetooth module, and this data is transmitted from
the Bluetooth module to Arduino and it turns OFF the LED.
RESULT:
Thus the IOT System was Successfully Designed
95