Embedded and Iot Lab Manual
Embedded and Iot Lab Manual
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.
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.
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:
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:
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.
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();
}
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 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
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
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 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.
Raspberry Pi 1, 2, 3
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.
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.
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.
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).
29
A tour of Raspberry Pi
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 .
32
ls
and then press Enter on the keyboard.
You can now see a list of the files and folders in your directory.
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.
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.
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.
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.
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)
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/
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:
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
48
5.2. Code:
Sender Side code:
Receiver Side code:
Sending the Data
49
Receiving the data:
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:
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:
55
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
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
57
Select the project My first project and you are good to go.
58
After clicking on VM Instances it will show below screen
Now Click on CREATE INSTANCE above to create a new instance.
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.
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.
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:
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.
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.
66
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:
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:
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.
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
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
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/
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.
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
1. Open Bluetooth connecter app and allow turning on Bluetooth of the device.
76
2. Search for Bluetooth device for making the pair.
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