Download as pdf or txt
Download as pdf or txt
You are on page 1of 78

EXP NO : 1

8051 ASSEMBLY LANGUAGE EXPERIMENTS USING


DATE : SIMULATOR

AIM:
To Write 8051 Assembly Language experiments using simulator
SOFTWARE REQUIRED:
1. EDSIM51 2.PC
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

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.

1
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:
1.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:
ORG 0x0000 ; Define the origin address
MOV A, #0x55 ; Load a value (0x55) into the accumulator
MOV R0, #0x10 ; Load a memory address (0x10) into register R0
MOV @R0, A; Store the value of A (Accumulator) into memory at address stored in R0
MOV A, #0xAA; Load a different value into A
MOV R0, #0x10; Load the same memory address into R0
MOV A, @R0; Load the value from memory at address stored in R0 into A
END ; End of the program

RESULT:
Thus the data transfer between registers and memory by using simulator was successfully tested.

2
EXP NO : 3
DATE : PERFORM ALU OPERATIONS

AIM:
To Preform Arithmetic and Logical Operations by using 8051 Simulator
SOFTWARE REQUIRED:
1.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:
Addition of two 16 bit numbers:
MOV DPTR,#1020H
MOV A,#15H
MOV B,#25H
ADD A,DPL,
MOV DPL,A
MOV A,B
ADDC A,DPH
MOV DPH,A
END
Subtraction of two 16 bit numbers:
MOV DPTR,#1020H
MOV A,#35H
MOV B,#45H
subb A,DPL,
MOV DPL,A
MOV A,B
subb A,DPH
MOV DPH,A
END
Logical Operations:
Bitwise AND:
ORG 0x0000 ; Define the origin address
MAIN: MOV A, #0x0F; Load value 0x0F (binary 00001111) into Accumulator A
MOV B, #0x3C; Load value 0x3C (binary 00111100) into register
ANL A, B; Perform bitwise AND operation between A and B
Here, A now contains the result of (0x0F & 0x3C), which is 0x0C (binary 00001100)
END ; End of the program
Bitwise OR:
ORG 0x0000 ; Define the origin address
MAIN:MOV A, #0x27 ; Load value 0x0F (binary 00001111) into Accumulator A
3
MOV B, #0x35 ; Load value 0x3C (binary 00111100) into register B
ORL A, B ; Perform bitwise OR operation between A and B
Here, A now contains the result of (0x0F | 0x3C), which is 0x3F (binary 00111111)
END ; End of the program
Bitwise NOT:
ORG 0x0000 ; Define the origin address
MAIN:MOV A, #0x27 ; Load value 0x0F (binary 00001111) into Accumulator A
CPL A ; Perform bitwise NOT(Complementary) operation of Accumulator
END ; End of the program
Bitwise NAND:
ORG 0x0000 ; Define the origin address
MAIN: MOV A, #0x0F; Load value 0x0F (binary 00001111) into Accumulator A
MOV B, #0x3C; Load value 0x3C (binary 00111100) into register
ANL A, B; Perform bitwise AND operation between A and B
Here, A now contains the result of (0x0F & 0x3C), which is 0x0C (binary 00001100)
CPL A; Complementary of Accumulator content
END ; End of the program
Bitwise NOR:
ORG 0x0000 ; Define the origin address
MAIN:MOV A, #0x27 ; Load value 0x0F (binary 00001111) into Accumulator A
MOV B, #0x35 ; Load value 0x3C (binary 00111100) into register B
ORL A, B ; Perform bitwise OR operation between A and B
Here, A now contains the result of (0x0F | 0x3C), which is 0x3F (binary 00111111)
CPL A; Complementary of Accumulator content
END ; End of the program
Bitwise XOR:
ORG 0x0000 ; Define the origin address
MAIN:MOV A, #0x0F ; Load value 0x0F (binary 00001111) into Accumulator A
MOV B, #0x3C ; Load value 0x3C (binary 00111100) into register B
XRL A, B ; Perform bitwise XOR operation between A and
Here, A now contains the result of (0x0F ^ 0x3C), which is 0x33 (binary 00110011)
END ; End of the program

RESULT:
Thus the ALU Performance was Verified Successfully

4
EXP NO : 4
BASIC AND ARITHMETIC PROGRAMS USING
DATE : EMBEDDED C.
AIM:
To Write Basic and arithmetic Programs Using Embedded C.
SOFTWARE REQUIRED:
1. 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:
Addition
ORG 00H
SJMP START
START :Mov a,#50H
Mov b,#30h
add a,b
exit:sjmp exit
END
Subtraction
ORG 00H
SJMP START
START :Mov a,#30H
Mov b,#20h
subb a,b
exit:sjmp exit
END
Multiplication
ORG 00H
SJMP START
START :Mov a,#35H
Mov b,#32h
mul ab
5
exit:sjmp exit
END
Division
ORG 00H
SJMP START
START :Mov a,#35H
Mov b,#32h
div ab
exit:sjmp exit
END

RESULT:
Thus the Basic and arithmetic Programs Using Embedded C was Executed successfully

6
EXP NO : 5
INTRODUCTION TO ARDUINO PLATFORM AND
DATE : PROGRAMMING

AIM
To develop a Platform and Programming by using arduino
SOFTWARE REQUIRED
1.Arduino IDE software with PC
2.Arduino board
3.Bread Board and Connecting Wires
PROCEDURE
Installing the AVR core
The classic Arduino boards, including the favorites UNO, Nano and Mega, requires the AVR core to
be installed to compile and upload sketches to your board.
Fortunately, the classic IDE comes with the AVR core already pre-installed. This means that we
only need to download and install the editor to start using our Arduino products.
In this Procedure, we will simply show how to select the right board, choose the right port, and how
to upload the classic blink example to our board, a simple program that makes your LED blink
every second.
Boards using the AVR core
 Arduino UNO R3
 Arduino Mega2560
 Arduino Nano (classic)
 Arduino Micro
 Arduino Leonardo
 UNO Mini LE
Retired boards using the AVR core
There are several retired boards that uses the AVR core, but are no longer available from our store.
You can see all of them in the list of boards in the editor.

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.
7
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.

Select the board.


Selecting the port
Now, let's make sure that our board is found by our computer, by selecting the port. Regardless what
kind of program we are uploading to the board, we always need to choose the port for the board we
are using. This is simply done by navigating to Tools > Port, where you select your board from the
list.

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)

8
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.

Selecting the blink example.


To upload the sketch, simply click on the arrow in the top left corner. This process takes a few
seconds, and it is important to not disconnect the board during this process.

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.

9
PROGRAM :1 WRITE DIGITAL OUTPUT- BLINKING A LED
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

10
// 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

11
EXP NO : 6 EXPLORE DIFFERENT COMMUNICATION METHODS WITH
DATE : IOT DEVICES

AIM:
To Explore Different Communication Methods with IoT Devices(Zigbee,GSM,Bluetooth)
HARDWARE AND SOFTWARE REQUIRED:
1.Zigbee(ESP-32 with Bluetooth)
2.Bread Board and Connecting Wires
3.Arduino IDE

PROCEDURE:

 First, you need to download the Arduino IDE.


 After that, we need to install the ESP8266 Board in Arduino IDE.
 Copy the following link to add ESP8266 or ESP8266 integrated board in Arduino IDE.
 http://arduino.esp8266.com/stable/package_esp8266com_index.json
 Go to Arduino IDE, then follow the path File/preferences and open the preference tab.
 And paste the above link in the additional board manager URL box as shown in the image.

 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.

12
this is how your ESP8266 board get installed
After installing the ESP8266 board in Arduino, you need to follow few simple steps:

Open Arduino IDE.


Go to Tools /Board/ ESP8266 (2.7.4) and then select Generic ES8266 Module, just like shown in the
image.

13
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.

14
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.

6. After clicking on OK, you will find canvas window.


7. Now, tap anywhere on the canvas to open the widget box. All the available widgets are located here.
Now choose a button.

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

16
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.
// Set password to "" for open networks.
char ssid[] = "………….";
17
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();
}

// This function will be called every time button Widget


// in Blynk app writes values to the Virtual Pin V3
BLYNK_WRITE(V3) {
int pinValue = param.asInt(); // Assigning incoming value from pin V3 to a variable
if (pinValue == 1) {
digitalWrite(LED, HIGH); // Turn LED on.
} else {
digitalWrite(LED, LOW); // Turn LED off.
}
}
PIN DIAGRAM

RESULT:
Thus the Different Communication Methods with IoT Devices was Executed Successfully

18
EXP NO : 7 INTRODUCTION TO RASPBERRY PI PLATFORM AND
DATE : PYTHON PROGRAMMING

AIM:
To develop a Raspberry Pi Platform And Python Programming
SOFTWARE REQUIRED:
 Raspberery 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 connect
other components, such as a USB drive.
SD card slot — you can slot the SD card in here. This is where the operating system
software 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

19
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 Visit the Raspberry Pi downloads page

o Click on the link for the Raspberry Pi Imager that matches your operating system

20
o When the download finishes, click it to launch the installer

Using the Raspberry Pi Imager

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:

21
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 you
would 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.

22
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

Connect your Raspberry Pi

Let’s connect up your Raspberry Pi and get it running.


o Check the slot on the underside of your Raspberry Pi to see whether an SD card is inside.
If no SD card is there, then insert an SD card with Raspbian installed (via NOOBS)

23
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 Connect the keyboard in the same way.

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

24
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.

You could connect an optional second screen in the same way.

Raspberry Pi 1, 2, 3

Connect your screen to the single HDMI port.

25
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.

Start up your Raspberry Pi


Your Raspberry Pi doesn’t have a power switch. As soon as you connect it to a power outlet,
it will turn on.

o Plug the power supply into a socket and connect it to your Raspberry Pi’s power port.

26
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.

After a few seconds the Raspberry Pi OS desktop will appear.

Finish the setup

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.

Click Next to start the setup.


Set your Country, Language, and Timezone, then click Next again.

27
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.

28
Note: if your Raspberry Pi model doesn’t have wireless connectivity, you won’t see this
screen.

o Click Next let the wizard check for updates to Raspbian and install them (this might take a
little while).

o Click Done or Reboot to finish the setup.


Note: you will only need to reboot if that’s necessary to complete an update.

29
A tour of Raspberry Pi

Now it’s time to take a tour of your Raspberry Pi.


o Do you see the raspberry symbol in the top left-hand corner? That’s where you access the
menu: click on it to find lots of applications.
o Click on Accessories, and then click on Text Editor.

30
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 .

o You should see an icon named rp.txt appear on the desktop.

Your file has been saved to your Raspberry Pi’s SD card.


Close the text editor by clicking the X in the top right-hand corner of the window.
Return to the menu, click on Shutdown, and then click on Reboot.
When Raspberry Pi has rebooted, your text file should still be there on the desktop.
31
Raspberry Pi runs a version of an operating system called Linux (Windows and
macOS are other operating systems). This operating system allows you to make things
happen by typing in commands instead of clicking on menu options. To try this out,
click on the Terminal symbol at the top of the screen:

o In the window that appears, type:

32
ls
and then press Enter on the keyboard.
You can now see a list of the files and folders in your directory.

o Now type this command to change directory to the Desktop:


cd Desktop
You have to press the Enter key after every command.
Then type:
ls
Can you see the text file you created?
o Close the terminal window by clicking on the X.
o Now drag to the Wastebasket on the desktop so the Raspberry Pi will be tidy for the
next person using it.

Browsing the web

You might want to connect your Raspberry Pi to the internet. If you didn’t plug in an ethernet
cable or connect to a WiFi network during the setup, then you can connect now.

o 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.

33
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.

o Click the web browser icon and search for .

Configuring your Raspberry Pi

You can control most of your Raspberry Pi’s settings, such as the password, through
the Raspberry Pi Configuration application found in Preferences on the menu.

34
System
In this tab you can change basic system settings of your Raspberry Pi.

Password — set the password of the pi user (it is a good idea to change the password
from the factory default ‘raspberry’)
Boot — select to show the Desktop or CLI (command line interface) when your
Raspberry Pi starts
Auto Login — enabling this option will make the Raspberry Pi automatically log in
whenever 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 your
Raspberry 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 recognises that you’ve linked something to it via a particular type of
connection.

35
Camera — enable the Raspberry Pi Camera Module
SSH — allow remote access to your Raspberry Pi from another computer using
SSH
VNC — allow remote access to the Raspberry Pi Desktop from another computer
using VNC
SPI — enable the SPI GPIO pins
I2C — enable the I2C GPIO pins
Serial — enable the Serial (Rx, Tx) GPIO pins
1-Wire — enable the 1-Wire GPIO pin
Remote GPIO — allow access to your Raspberry Pi’s GPIO pins from another
computer

Performance
If you need to do so for a particular project you want to work on, you can change the
performance settings of your Raspberry Pi in this tab.
Warning: Changing your Raspberry Pi’s performance settings may result in it behaving
erratically or not working.

Overclock — change the CPU speed and voltage to increase performance

GPU Memory — change the allocation of memory given to the GPU


36
Localisation

This tab allows you to change your Raspberry Pi settings to be specific to a country or
location.
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

RESULT:
Thus the Rasbperrypi Platform installed Successfully

37
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 paragraph
below)
 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.

38
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.

sudo pip3 install w1thermsensor

That's it, now you can close the Terminal window.


Enable the Interface
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.

39
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.

Writing the Python Code


Our project will gather the temperature from the DS18B20 sensor every one second and print it to
the screen. The code will run forever.

40
To write the code we shall use the Python 3 Editor found in the Programming menu.

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 we
import 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 than
typing 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.

41
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)

print("The temperature is %s celsius" % temperature)

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)

42
Run the Code!

To run the code, click on Run >> Run Module and you will see the Python Shell window pop up
and start displaying temperature data!

RESULT:
Thus the temperature Sensor was Successfully Interface with Raspberry Pi

43
EXP NO : 9 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI
DATE : USING ANY WIRELESS MEDIUM

AIM:
To Develop a Communicate Between Arduino And Raspberry Pi Using Any Wireless
Medium
SOFTWARE and COMPONENTS REQUIRED:
 Ultrasonic Sensor
 2 Arduino Uno
 Raspberry Pi 3
 2 nRF24l01 transmitter and receiver
 Jump wires
 Arduino cable
 MINI USB 2.0 for Pi
 Breadboard
 Raspbian for pi
 Arduino IDE or Visual Studio
 Putty on a remote computer for SSH
 VNC viewer on a remote computer
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.

44
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/

45
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:

46
10) Now open VNC Viewer on your remote computer:

Implementation and Working:


5.1. Wireless communication of Arduino to Arduino with nRF24L01:
In this, we will learn how to make wireless communication between two Arduino boards using
the NRF24L01. And measure distance with ultrasonic sensor and transmit it to another Arduino
with transceiver module.
Wiring Instructions:
47
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
To wire your ultrasonic sensor to your Arduino, connect the following pins:
Connect the VCC pin to Arduino 5Volts
Connect the GND pin to ground (GND)
Connect the Trig pin to Arduino 4
Connect the Echo pin to Arduino 3

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 :

48
5.2. Code:
Sender Side code:
Receiver Side code:
Sending the Data

49
Receiving the data:

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 is
needed 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.
50
3. In the terminal type:
sudo raspi-config

Turn on SPI from Interfacing options in config

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:

51
9. Run an example from one of the libraries:
cd rf24libs/RF24/examples_linux
make
sudo ./gettingstarted
Run Following Commands to run the program.
10. Further, if we want to run Python Programs for the same purpose, we can do this:
Running the Example Edit the pingpair_dyn.py example to configure the appropriate pins per the
above documentation:
nano pingpair_dyn.py
Configure another device, Arduino or RPi with the pingpair_dyn example
Run the example
sudo python pingpair_dyn.py

52
Schematic Diagram:

Schematic Diagram for wiring of Raspberry Pi and NRF24L01


Code:
Sender Side Code:
Receiver Side Code:
It's not mandatory to use this code as it is tweaked by me as per my requirement.
To check the proper functioning of your connection and code you can run the examples present in
the library like pingpair_dyn.ino on your Arduino and pingpair_dyn.py on Raspberry Pi
The snippet of my running communication:

53
RESULT:
Thus the Temperature Sensor with Raspberry Pi was interfaced Sucessfully

54
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:

Step 1 – Create a GMAIL account


 Go to
https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flo
wEntry=SignUp to create a new gmail account
 You may also opt to use your existing Gmail account
 Fill in the details and click next

 Add your mobile number and verify using verification code


 Add details about your recovery address, data of birth and Gender
 Once account setup is complete – go to https://mail.google.com/mail/u/0/
 Login as your new account

55
 Click Next
 In the next page, click – Yes, I’m in
 In the next page, agree to the T&C

Step 2 – Log in to GCP console


 On your browser (preferably chrome), navigate to https://console.cloud.google.com

 Agree the terms and conditions and you now have a free tier account for GCP

Step 3 – Enable Billing to receive $300 credits


 On top of your screen you will see the link to enable billing

56
 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

In the next page –


 Change account type to – Individual
 Select your Tax status type
 Add your Address
 Add details about your registered ID like SSN/PAN etc
 Add credit card details
NOTE – It is YOUR responsibility to ensure that you shut down your GCP resources so
that you dont incur unnecessary charges. Google provides you with an evaluation credit
of $300, upto which you will not be charged. Once you cross the limit of $300 Google
will charge you for the resources that you utilize. All cloud providers has the PAY AS
YOU GO model, which ensures that you are charged only for the resources that you
are utilizing.
NOTE – Ensure that your card supports auto debit. I have seen a few instances where
debit cards were rejected as they dont support auto debit.
 Once done – click Start My Free Trial

Step 4 – Create a new project


 The top blue menu bar has an option of Select a project

 Click on Select a project dropdown


 By default a new project would be created

57
 Select the project My first project and you are good to go.

Create UBUNTU VM Instance


 Once after setting project successfully & enabled the billing for it.
 On your google cloud home page, top left corner click 3dash symbol as shown below
 You will see various services offered by google.
 Now scroll down list of services until you see “Compute Engine” then click on it
 It will pop up with various other services under compute engine as show below
 Now click on “VM Instances”

58
 After clicking on VM Instances it will show below screen
 Now Click on CREATE INSTANCE above to create a new instance.

After clicking on “CREATE INSTANCE” it will show below screen


 Name: “type any name” (ex: machine1)
 Series: N1 (do not change this)
 Machine type: (choose the appropriate capacity as per the requirement)

Scroll down for other options such As:

59
 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.

 Once we click on create you will see below screen.


 The machine will get ready in couple of minutes & you will see as below highlighted.
 To login to the machine click on SSH – open in browser window.

60
 To create more VMs, repeat same process Port from VPC Networks
Step 1: On the navigation menu on the left, scroll down and go to Networking section -
> VPC network – > VPC networks.

Step 2: Go to firewall details and click on the default-allow-http.

61
Step 3: Click on the Edit link.

Step 4: Choose All instances in the network from the Targets dropdown.

62
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.

63
RESULT:

Thus the Cloud log on Data was created Successful

64
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
Procedure:
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.

After this verify your E-mail id and click on continue.

65
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.

Step 3: Getting API Key in ThingSpeak


To send data to ThingSpeak, we need an unique API key, which we will use later in our python
code to upload our CPU data to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading your CPU data.

66
Now copy your “Write API Key”. We will use this API key in our code.

Step 4: Python Code for Raspberry Pi


Complete code is given at the end of this tutorial, just make a file with any name and .py
extension and copy-paste the code and save the file. Don’t forget to replace the API key with
yours. You can run the python file any time using below command:

python /path/filename.py

Assuming you already installed python in Raspberry pi using this command

sudo apt-get install python

Case 1: If you are using monitor screen then just use the given code.
Now install all libraries:

sudo apt-get install httplib


sudo apt-get install urllib

After installing libraries run your python code (python /path/filename.py)


If the code runs properly you will see some CPU temperature values as shown in below image.

67
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:

sudo apt-get update

After this make a file cpu.py 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:

sudo apt-get install httplib


sudo apt-get install urllib

After installing libraries run your python code using:

python cpu.py

If the code runs properly you will see some CPU temperature values as shown in above image.

Step 6: Check ThingSpeak site for Data Logging


After completing these steps open your channel and you will see the CPU temperature data is
updating into ThingSpeak website.

68
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

69
EXP NO : 11 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:

The Working principle of Arduino-Bluetooth Module

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.

Digital circuit diagram

TX --------------------------------> RX (Pin 0)
RX --------------------------------> TX (Pin 1)
VCC --------------------------------> 5v
GND --------------------------------> GND

70
LED Pin ARDUINO UNO
Pin1-------------------------------->GND
Pin 2 --------------------------------> Pin 13

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/

Download the Arduino software according to your OS compatibility (Windows Installer).

71
Click Download

After successful download, run the setup and follow the instructions.

72
When it asks to install the driver software, click to install

73
After installation, open the software, and if it generates a security alert then allow it.

74
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.

char data = 0; //Variable for storing received data


void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
if(data == '1') // Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') // Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
} }

Save your program and compile it.

75
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

Step to connect with Android app with Bluetooth Module

1. Open Bluetooth connecter app and allow turning on Bluetooth of the device.

76
2. Search for Bluetooth device for making the pair.

3. To pair with Bluetooth HC-05 module, enter a pin 0000 or 1234.

4. Select pair device HC-05 to connect with Android app.

77
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

78

You might also like