0% found this document useful (0 votes)
47 views34 pages

ES&IOT Labmanual - Merged - Removed

The document describes a lab experiment on interfacing an IR sensor with a Raspberry Pi. It provides the components required, circuit diagram, working principle of the IR sensor, and a Python program to read output from the IR sensor and control LEDs accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views34 pages

ES&IOT Labmanual - Merged - Removed

The document describes a lab experiment on interfacing an IR sensor with a Raspberry Pi. It provides the components required, circuit diagram, working principle of the IR sensor, and a Python program to read output from the IR sensor and control LEDs accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

AGNI COLLEGE OF TECHNOLOGY

(Approved by AICTE & Affiliated to Anna University)

Off Old Mahabalipuram Road,Thalambur,Chennai -600130

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


ACADEMIC YEAR
2023-2024
CS3691 – EMBEDDED SYSTEMS AND IOT LABORATORY
EVEN SEMESTER

NAME OF THE STUDENT :


REGISTER NUMBER :
COURSE :
YEAR :

SEMESTER :
AGNI COLLEGE OF TECHNOLOGY
(Approved by AICTE& Affiliated to Anna University)
Old Mahabalipuram Road, Thalambur, Chennai – 600 130

BONAFIDE CERTIFICATE

Register Number :

Name of the lab : CS3691 EMBEDDED SYSTEMS AND IOT LABORATORY

Department : Computer Science and Engineering

Certified that this is a Bonafide Record of Practical Work done by


Mr./Ms.………………………………………………………………………………………....
of Computer Science and Engineering Department 6th semester in the CS3691 EMBEDDED SYSTEMS
AND IOT LABORATORY during the year 2023-2024.

Signature of Lab-in-Charge Signature of Head of the Department

Submitted for the University Practical Examination held on …………………

INTERNAL EXAMINER EXTERNAL EXAMINER


CS3691 EMBEDDED SYSTEMS AND IOT LABORATORY

INDEX
S.NO NAME OF THE DATE PAGE SIGNATURE
EXPERIMENT NO

1 Complement of 8 bit number


using assembly language

2 Data Transfer using assembly


language

3 ALU operation using assembly


language

4 Average of n – bytes stored in


assembly language

5 Arithmetic operations using


embedded C

6 LED Blinking using Arduino

7 Interfacing IR Sensor Using


Raspberry pi

8 Bluetooth interfacing Arduino.

9 LED Blinking using Raspberry pi

10 Message transfer using Arduino and


raspberry pi

11 Setup a cloud platform to log the data

12 Log Data using Raspberry PI and


upload to the cloud platform

4
Ex.No:1 Program for Complement Operation
Date:

Aim: To write an assemble language program to Complement 8 bit number.

Components Required:
• Keil software
• PC

Algorithm:
❖ Initialize input ports

❖ Initialize output ports

❖ Move the contents from Port to register

PROGRAM

ORG 0000H

MOV A, 00H

XX: MOV P1,A

CPL A

JMP XX

END

OUTPUT

Result: Thus, the program to Complement 8 bit number was successfully verified.

5
Ex.No:2 Data Transfer using assembly language
Date:

Aim: To write an assemble language program to Data Transfer using assembly


language.

Components Required:
• Keil software
• PC

Algorithm:
❖ Initialize input ports

❖ Initialize output ports

❖ Move the contents from Port to register

PROGRAM

ORG 000H

MOV R0, #30H

MOV R1, #50H

MOV R3, #05H

Back: MOV A, @R0

MOV@R1, A

INC R0

INC R1

DJNZ R3, BACK

END

OUTPUT:

Result: Thus the program using store average of n – bytes was executed
successfully and output is verified.
6
Ex.No:3 ALU operation using assembly Language
Date:

Aim: To write an assemble language program to addition, subtraction, multiplication,


division, of two numbers.

Components Required:
• Keil software
• PC

Algorithm:
❖ Initialize Ports P0 and P1 as input ports.

❖ Initialize Ports P2 and P3 as output ports.

❖ Initialize the R1 register.

❖ Move the contents from Port 0 to B register.

❖ Move the contents from Port 1 to A register.

❖ Add contents in A and B.

❖ If carry is present increment R1.

❖ Move contents in R1 to Port 2.

❖ Move the sum in step 6 to Port 3.

PROGRAM

Mov a,#25h

Mov b,#12h

Add a,b

Mov 40h,a

Mov a,#25h

Sub a,b

Mov 41h,a

Mov a,#25h

Mul a, b

Mov 42h,a

Mov 43h,b

7
Mov a,#25h

Mov b,#12h

Div ab

Mov 44h,a

Mov 45h,b

Mov a,#25h

Inc a

Mov 46h,a

Dec a

Mov 47h,a

end

OUTPUT:

Result: Thus the program to addition, subtraction, multiplication, division, of two


numbers was executed successfully verified.
8
Ex.No:4 Average of n-type stored in assembly language
Date:

Aim: To write an assemble language program using average of n-type stored.

Components Required:
• Keil software
• PC

Algorithm:
❖ Initialize Ports P0 and P1 as input ports.

❖ Initialize Ports P2 and P3 as output ports.

❖ Initialize the R1 register.

❖ Move the contents from Port 0 to B register.

❖ Move the contents from Port 1 to A register.

❖ Store the contents to output port

Program:

MOV R1,#50H

MOV A,#00H

MOV B,#05H

L1:ADD A,@R1

INC R1

DJNZ R0,L1

DIV AB

MOV @RO,A

END

Output:

10
Result: Thus the program using program to store Average of n – bytes was
executed successfully verified.

11
Ex.No:5 Arithmetic operation using embedded C
Date:

Aim: To write an assemble language program using 8-bit arithmetic addition,


subtraction, multiplication and division.

Components Required:
• Keil software
• PC

Algorithm:
❖ Initialize Ports P0 and P1 as input ports.

❖ Initialize Ports P2 and P3 as output ports.

❖ Initialize the R1 register.

❖ Move the contents from Port 0 to B register.

❖ Move the contents from Port 1 to A register.

❖ ADD contents in A and B.

❖ Move the sum in step 6 to port 3.

Program:

#include<reg.51.h>

Void main(void)

Unsigned char s,p,q;

Unsigned int I;

P1=0*00;

P2=0*00;

S=0*03

P=0*02;

q=s+p;

P1=q;

I =s*p;

P2=I;

12
While(1);

Program:

#include<reg.51.h>

Void main(void)

Unsigned char p,q,r;

Unsigned int s;

P1=0*00;

P2=0*00;

p=0*06;

q=0*02;

r=p-q;

P1=r;

s=p*q;

P2=s;

While(1);

Output:

Result: Thus the program using 8-bit arithmetic addition, subtraction, multiplication
and division was executed successfully verified.

13
Ex.No:6 LED Blinking using Arduino
DATE:

AIM: To write a program for LED Blinking using Arduino

Hardware Requirements:

• Arduino UNO Board


• USB Cable
• Breadboard
• LED

Software Requirements:

Arduino IDE

Algorithm

Step 1: Start a new sketch in the Arduino IDE

Step 2: Set the pinMode for Pin 13

Step 3: Set Pin 13 HIGH

Step 4: Compile the code

Step 5: Upload the code to Arduino

PROGRAM:

To interface LED/Buzzer with platform/Arduino


Void setup()
{
Pin mode(13,output);
}
Void loop()
{
Digital write(13,High);
Delay(1000);
Digitalwrite(13,High);
Delay(1000);
}

Result: Thus the program was successfully verified.

15
Ex.No:7 Interfacing IR Sensor Using Raspberry pi
DATE:

Aim: To write a program for Interfacing IR Sensor Using Raspberry pi.

Components Required:

• Raspberry Pi 4
• IR sensor module
• Breadboard
• LED
• Jumper wires

IR Sensor Module:
IR sensors (Infrared sensor) are modules which detect the presence of objects before
them. If the object is present it give 3.3V as output and if it is not present it gives 0
volt. This is made possible by using a pair of IR pair (transmitter and receiver), the
transmitter (IR LED) will emit an IR ray which will get reflected if there is a object
present before it. This IR ray will be received back by the receiver (Photodiode) and
the output will be made high after amplified using an op-amp link LM358 .The
IR Sensor is shown above. Like all IR sensor it has three pins which are 5V, Gndand
Out respectively. The module is powered by the 5V pin from Raspberry Pi and the out
pin is connected to GPIO14 of Raspberry Pi. The potentiometer on top of the module
can be used to adjust the range of the IR sensor.

Circuit Diagram and Explanation:


The circuit diagram for connecting Raspberry Pi with IR sensor is shown below. As
you can see the circuit diagram is very simple. We have directly powered the IR module
from the 5V and Ground Pin of Raspberry Pi. The output pin of the IR module is
connected to the GPIO14. We have also used two LED (Green and Red) to indicate the
status of theobject. These two LEDs are connected to GPIO3 and GPIO2 respectively.
Since the GPIO pins of Raspberry Pi are 3.3V, a current limiting resistor is not
mandatory. However if desired a resistor of value 470 ohms can be added between the
ground pin of LEDs and Raspberry Pi. The whole circuit is powered by a 5V mobile
charger through the micro USB port of the Raspberry pi.

Note: When connecting any sensor, make sure the ground of the sensor is connected to
ground of the MCU or MPU (here Raspberry Pi). Only then they will be able to
communicate.

Programming your Raspberry Pi:


It using Python Programming language for programming RaspberryPi. There are many
ways to program your Raspberry Pi using the Python 3 IDE, since it is the most used
one. The complete Python program is given at the end of this lab

16
Program:

Import RPi.GPIO as GPIO

Import time

GPIO.Setmode(GPIO.Board)

GPIO.Setup(8,GPIO>IN)

While true

If GPIO.input(8)==0:

Printf (“IR sensor detect the object”);

Time.sleep(0.1)

else

printf(“IR sensor not detect the object”);

17
time.sleep(0.1)

Output:

IR sensor detect the object

IR sensor not detect the object

Result: Thus, the program was successfully verified.

18
Ex.No:8 Bluetooth Interfacing Arduino
DATE:

Aim: To Write a program for Bluetooth interfacing using arduino

Components Required :

• Arduino Uno

• 1 HC05 module

• Some male to female jumper cables

• Arduino IDE

• Connection cable
• LED (already built into the Arduino board)

Pinout and Connections

It start with the hardware part. Using jumper cables, connect the HC05 module to the

Arduino board using the diagram below as reference:

19
This is the connection that works for me. However, I found some references that
mention that the +5V terminal in the HC05 module should be connected to a 5V pin on
the Arduino board.

Next, need to give power the Arduino board by connecting it to a laptop (using the

USB cable) or other external power supply. When it will see the LED on the HC05

module is blinking, then to the right track.

Once it type the code , save the sketch and click compile. The code is very simple and
minimum, so there shouldn‟t be any error at this stage. Next, click the upload button to

write the code to the Arduino board. If there is an error, usually it‟s because of

improper connection between the board and laptop. Please ensure that the board is

properly recognized by Arduino IDE.

Note: remove +5V HC05 connection from the board before uploading the code

then reconnect it after the upload.

When everything is correct, see the built-in LED is blinking.

The First Bluetooth Data Transmission

At this point, the board is already transmitting data via the Bluetooth module.
However, for the time being, there is no other Bluetooth device paired and connected

to the Arduino board to receive the data that we transmit. So the only way is to make

sure that the board is transmitting is by looking at the serial monitor on Arduino IDE.

Open the serial monitor in Arduino IDE, then adjust the baud rate to 9600 baud (the

same baud rate we specify in the code). If everything is correct, to the screen:

20
CONNECTIONS:

• LED on HC05 module is blinking

• LED on Arduino board is blinking

• Serial monitor shows a transmission message

Program:

Void loop ()

If(BT serial .available())

BT_data=BTserial.Readstring();

Serial.login(BT_data);

If(serial. Available ( ))

Arduino _ data= serial. read string( );

BTserial.printin(Arduino_data);

Result: Thus, the program was successfully verified.

21
Ex.No: 9 LED Blinking using Raspberry pi
DATE:

Aim: To write a program for LED Blinking using Raspberry Pi

Components Required:

• Raspberry Pi 3 setup with monitor and USB Mouse & Keyboard


• Solderless breadboard
• Jumper wires
• Resistor
• Red LED
• Multimeter

CIRCUITCONNECTIONS

The first step to design a simple led circuit. Then it will make the LED circuit
controllable from the Raspberry Pi by connecting the circuit to the general purpose
input/output (GPIO) pins on the Raspberry Pi.

A simple LED circuit consists of a LED and resistor. The resistor is used to limit the
current that is being drawn and is called a current limiting resistor. Without the resistor
the LED would run at too high of a voltage, resulting in too much current being drawn
which in turn would instantly burn the LED, and likely also the GPIO port on the
Raspberry Pi.

When hooking up the circuit note the polarity of the LED. It notice that the LED has a
long and short lead. The long lead is the positive side also called the anode, the short
lead is the negative side called the cathode. The long should be connected to the resistor
and the short lead should be connected to ground via the blue jumper wire and pin 6 on
the Raspberry Pi as shown on the diagram.

To find the pin number refer to this diagram showing the physical pin numbers on the
Raspberry Pi.

PROGRAM:
Turn LED on for 2 seconds and off for 1 second, loop forever. Code is given below

Import RPI.GPIO
Import time
Defmain():
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD) #to use Raspberry pi board pin numbers
GPIO.setup(11,GPIO.OUT) #set up GPIO output channel
While True:
GPIO.output(!!,GPIO.LOW) #set RPI board pin 11 low. Turn off LED.
time.sleep(1)
GPIO.output(11,GPIO,HIGH) #set RPI board pin 11 high. Turn on LED.
time.sleep(2)
Main()

22
Result: Thus the program for LED Blinking using Raspberry Pi was successfully
verified.

23
Ex.No:10 Message transfer using Arduino and raspberry pi
DATE:

Aim : To write a program for Message transfer using Arduino and raspberry pi

Components Required
• Arduino IDE Software
• Arduino Board
• Raspberry pi board
• USB Cable

Program :

import serial
import time
ser=serial.serial(„/dur//tty ACMO‟,11500,time out=1.0)
time.sleep(3)
ser.reset_input_buffer()
printf(“serial OK”)
ser.close(
void setup(){
serial.begin(115200);
}
Void loop(){
//put your main code here, to run repeatedly;
}

Hardware setup for Serial communication


There are 2 ways to connect your Raspberry Pi and Arduino for Serial
communication.

Serial via USB


Arduino, will use the USB port that use to upload code from computer (with the
Arduino IDE) to board. Here the USB connector will depend on version . For boards
like Arduino Uno and Mega, the connector will be different from Arduino Nano, and
from Arduino Zero.

Serial via GPIOs

To make a Serial connection it can also use plain wires between the Raspberry Pi
GPIOs and the Arduino pins.

24
Depending on your Arduino board might need to use a voltage level-shifter. The
Raspberry Pi is operating at 3.3V. For Arduino boards like Due, 101, it will be fine
because it use 3.3V.

But, for many Arduino, such as Uno, Mega, Leonardo, Nano, and many more, the
board is operating at 5V. it need a 3.3V/5V level-shifter to protect the Raspberry
Pi when connecting RX and TX (more info on Raspberry Pi pins and Arduino Uno
pins). For the rest of the use setup with the USB cable.

Output:
Serial OK

Result: Thus the program for Message transfer using Arduino and raspberry pi was
successfully verified.

25
Ex.No:11 SETUP A CLOUD PLATFORM TO LOG THE DATA
DATE:

Aim: To Setup a cloud platform and log the data

Components Required:
• PC
• WIFI or internet

Algorithm:
Steps to Setup a cloud platform to log the data
Step 1 - Confirm Google Operations Logs

Step 2 - Export Logs To Google Pub/Sub

Step 3 - Create Google Pub/Sub

Step 4 - Create Service Account

Step 5 - Configuring Logstash

Step 6 - Check Logi IO For Your Logs

Step 7 - Google Operations Logging Overview

PROCEDURE:

Step 1 - Confirm Google Operations Logs:First, confirm the logs are located in
project by visiting the Logs Viewer section on Google Cloud Platform.

26
Step 2 - Export Logs To Google Pub/Sub

Located the logs to export, choose the option to CREATE SINK. It will be prompted
with the following options. Choose the Cloud Pub Sub topic option.

It will be then be prompted for:

Sink name
Sink Service (choose Pub/Sub)
Sink Destination (choose create new Cloud Pub/Sub topic)

27
Once entered these details choose create sink. This will ensure that the logs you have
specified are directed to the Pub/Sub sink.

Step 3 - Create Google Pub/Sub:

On your topic, click the ellipsis to the right.

28
Enter a suitable subscription ID and make sure delivery type is set to pull.

Scroll to the bottom of the page and press create.

29
Step 4 - Create Service Account

Visit service accounts and choose the project then to add the service account to. This
will be used to retrieve logs from the Google Pub Sub and send to Log stash.

Select create a new service account.

Give the service account a name and add the relevant Pub/Sub permissions for the
service account.

Now we need to create a key for the service account, this will be used by Logstash to
access the service account in order to retrieve logs.

Click into the newly created service account.

30
Choose the option to add a key and then select create a key option, remember to
download the service key as json when prompted.

31
Step 5 - Configuring Logstash

To start pulling Logs from the Google Cloud Platform pub/sub to your Stack a Logit.
To configure the Logstash input for you. To share the following details securely over
intercom using the button below.

Project_id=>The complete ID of project

topic=> name of topic

subscription=> name of the subscription

json _key_file=> json key file

Step 6 - Check Logit.IOFor Your Logs

to view your data

Step 7 - Google Operations Logging Overview

Logit.io provides an alternative log management solution that also extends to


managing not only GCP logs but also AWS, Azure & hundreds of other log data
sources.

The Logit.io platform makes correlating the performance of your Google operations
logs easy.

Result: Thus the data to Setup a cloud platform was verified successfully.

32
Ex.No:12 LOG DATA USING RASPBERRY PI AND UPLOAD THE
CLOUD PLATFORM

DATE:
Aim: To log the data using raspberry pi and upload the cloud platform

Components Required:

1. Raspberry Pi
2. Power Cable
3. WiFi or Internet

Algorithm:
Steps to log data using Raspberry pi and upload the cloud platform
Step 1- Signup for Thing Speak
Step 2 - Create a Channel for Your Data
Step 3 - Getting API Key in Thing Speak
Step 4 - Python Code for Raspberry Pi
Step 5 - Check Thing Speak site for Data Logging
Steps for building Raspberry Pi Data Logger on Cloud
Step 1: Signup for ThingSpeak
For creating the channel on ThingSpeak first need to sign up on ThingSpeak. In case
if already have an account on ThingSpeak just sign in using your id and password.

After clicking on signup fill personal details.

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

Step 2: Create a Channel for Your Data


Once Sign in after account verification, Create a new channel by clicking “New
Channel” button

After clicking on “New Channel”, enter the Name and Description of the data then to
upload on this channel.Now enter the name of data (like Temperature or pressure) in
Field1.Enter the name and description of your data.
Afterthisclick on save channel button to save the 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.

34
Now copy and“Write API Key”. It 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. Must to replace the API key
with yours. It can run the python file any time using below command:
Python/path/filename.py
Sudo apt-get install python
Case 1:To give the code.
Now install all libraries:
sudo apt-get install httplib
sudo apt-get install urllib
After installing libraries run code (python /path/filename.py)
If the code runsproperly will see some CPU temperature values as shown in below
image.

35
If there are any errors uploading the data, will receive “connection failed” message.
Step 5: Check ThingSpeak site for Data Logging
After completing these steps open the channel and will see the CPU temperature data
is updating into ThingSpeak website.

36
It can send any sensor data connected with Raspberry pi to the ThingSpeak Cloud. Then
to connect LM35 temperature sensor with Raspberry Pi and send the temperature data
to ThingSpeak, which can be monitored from anywhere.
Program:
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 log data using raspberry pi and upload the cloud platform was
verified successfully.

37

You might also like