0% found this document useful (0 votes)
74 views

Esiot Lab Manual (All Experiments)

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)
74 views

Esiot Lab Manual (All Experiments)

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

[[[

DEPARTMENT OF INFORMATION TECHNOLOGY

LABORATORY MANUAL

CS3691 – Embedded Systems and IoT


Practical Exercises
(For III-year V Semester B.Tech – IT Students)
Regulation – 2021

NAME :
REGISTER NUMBER :
YEAR/SEMESTER :
BRANCH :
Prepared By: G.Vijaykumar M.E (Ph.D)., AP/BME
ABOUT OBSERVATION NOTES & PREPARATION OF RECORD
❖ This Observation contains the basic diagrams of the circuits enlisted in the syllabus of the
CS3691 EMBEDDED SYSTEMS AND IOT course, along with the design of various
components of the circuit and controller.
❖ The aim of the experiment is also given at the beginning of each experiment. Once the student
can design the circuit as per the circuit diagram, he/she is supposed to go through the instructions
carefully and do the experiments step by step.
❖ They should note down the readings (observations) and tabulate them as specified.
❖ It is also expected that the students prepare the theory relevant to the experiment referring to
prescribed reference books/journals in advance, and carry out the experiment after understanding
thoroughly the concept and procedure of the experiment.
❖ They should get their observations verified and signed by the staff within two days and prepare &
submit the record of the experiment when they come to the laboratory in the subsequent week.
❖ The record should contain experiment No., Date,Aim, Apparatus required, Theory, Procedure,
and result on one side(i.e., Right-hand side, where rulings are provided) and Circuit diagram,
Design, Model Graphs, Tabulations, and Calculations on the other side (i.e., Left-hand side,
where no rulings are provided)
❖ All the diagrams and table lines should be drawn in pencil
❖ The students are directed to discuss & clarify their doubts with the staff members as and when
required. They are also directed to follow strictly the guidelines specified.
CS3691 EMBEDDED SYSTEMS AND IOT

SYLLABUS

COURSE OBJECTIVES:

❖ To learn the internal architecture and programming of an embedded processor.


❖ To introduce interfacing, I/O devices to the processor.
❖ To introduce the evolution of the Internet of Things (IoT).
❖ To build a small low-cost embedded IoT system using Arduino/Raspberry Pi/
open platform.
❖ To apply the concept of the Internet of Things in real-world scenario.

LIST OF EXPERIMENTS

1. Write 8051 Assembly Language experiments using simulator.


2. Test data transfer between registers and memory.
3. Perform ALU operations.
4. Write Basic and arithmetic Programs Using Embedded C.
5. Introduction to Arduino platform and programming
6. Explore different communication methods with IoT devices (Zigbee, GSM,
Bluetooth)
7. Introduction to Raspberry PI platform and python programming
8. Interfacing sensors with Raspberry PI
9. Communicate between Arduino and Raspberry PI using any wireless medium
10. Setup a cloud platform to log the data
11. Log Data using Raspberry PI and upload to the cloud platform
12. Design an IOT based system

OUTCOMES:

CO1: Explain the architecture of embedded processors.


CO2: Write embedded C programs.
CO3: Design simple embedded applications.
CO4: Compare the communication models in IOT
CO5: Design IoT applications using Arduino/Raspberry Pi /open platform.
CERTIFICATE

REGISTER NO.

Certified that this is the bonafide record of work done by Mr/Ms …………………….

of the ……………. Semester in ……………………………………. branch during the year

…………… in the ……………………………….……………………………….. Laboratory.

Staff In-charge Head of the Department

Submitted for the Practical Examination held on

Internal Examiner External Examin


Name : Reg.No.:
Year/Semester :
CONTENTS
EXP. PAGE FACULTY
DATE NAME OF THE EXPERIMENT MARKS
NO. NO. SIGNATURE
1 Write 8051 Assembly Language experiments using
simulator
2 Test data transfer between registers and memory

3 Perform ALU operations.


Write Basic and arithmetic Programs Using
4 Embedded C.
5 Introduction to Arduino platform and programming
Explore different communication methods with
6 IoT devices (Zigbee, GSM, Bluetooth)
Introduction to Raspberry PI platform
7
and python programming

8 Interfacing sensors with Raspberry PI

9 Communicate between Arduino and Raspberry PI


using any wireless medium
10 Setup a cloud platform to log the data

11 Log Data using Raspberry PI and upload to the


cloud platform
12 Design an IOT based system
EXP. NO: 01 DATE:
WRITE 8051 ASSEMBLY LANGUAGE EXPERIMENTS USING SIMULATOR

Aim:

To write 8051 assembly language experiments using simulator.

SOFTWARE REQUIRED:

1. Keil uVision IDE

Theory:

Earlier to Microcontrollers, Microprocessors were greatly used for each


and every purpose. Microprocessors were containing ALU, general purpose
register, stack pointer, program counter, clock counter and so many other
features which the today’s Microcontroller also possesses. But the difference
between them exists with respect to the number of instructions, access times,
size, reliability, PCB size and so on. Microprocessor contains large instruction
set called as CISC processor whereas Microcontroller contains less number of
instructions and is called as RISC processor. The access time is less in case of
microcontrollers compared to microprocessors and the PCB size reduces in case
of microcontrollers.

There are many versions of microcontrollers 8051, 80528751, AT8951


from Atmel Corporation and many more. In this manual we will study about the
8051 architecture, its features, programming and interfacing.

MCS 8051 is an 8-bit single chip microcontroller with many built-in


functions and is the core for all MCS-51 devices.

The main features of the 8051 core are:

Operates with single Power Supply +5V.

 8-bit CPU optimized for control applications.

 16-bit program counter (PC) and 16-bit data pointer (DPTR).

 8-bit program status word (PSW).

 8-bit stack pointer (SP).

 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).

 128 bytes of On-Chip Data Memory (Internal RAM):


 Four Register Banks, each containing 8 registers (R0 to R7)
[Total 32 reg]

 16-bytes of bit addressable memory.

 80 bytes of general-purpose data memory (Scratch Pad Area).

 Special Function Registers (SFR) to configure/operate microcontroller.

 32 bit bi-directional I/O Lines (4 ports P0 to P3).

 Two 16-bit timers/counters (T0 and T1).

 Full duplex UART (Universal Asynchronous Receiver/Transmitter).

 On-Chip oscillator and clock circuitry.

General Block Diagram of 8051 Microcontroller Architecture


STEPS TO CREATE AND COMPILE Keil µVision-3/4 PROJECT:
Procedure:

1. Launch the Simulator


2. Write the Assembly Program and save it with .asm extension
3. Click the build target option from project menu to assemble the program
4. Click the Debug menu to Start/Stop Debug Session
5. Press STEP button to single step the Program
8051 Assembly Language Experiments

a. Write an assembly language program to find the square of a given


number N.

Let N = 06

mov a,#06 // a=N=06


mov b,a
mul ab
mov 30h,a // result is stored in 30h and 31h
mov 31h,b
end

Result:

b. Write an assembly language program to find the cube of a given


number.

mov r0,#0fh // r0 = given number to find the cube of it.


mov a,r0
mov b,r0
mul ab
mov r1,b
mov b,r0
mul ab
mov 32h,a
mov r2,b
mov a,r1
mov b,r0
mul ab
add a,r2
mov 31h,a
mov a,b
addc a,#00h
mov 30h,a //result is stored in 30h, 31h, 32h end

Result:

c. Write an assembly language program to perform logical operations


AND, OR, XOR on two eight bit numbers -45h & 67h

/ / Logical operations between two 8-bit numbers//


mov a,#45h //1st number 0100 0101
mov r0,#67h //2nd number 0110 0111
anl a,r0 //AND Logic 0100 0101
mov 20h,a // saving and result with 20h memory
mov a,#45h
orl a,r0 //OR Logic 0110 0111
mov 21h,a // saving and result with 21h memory
mov a,#45h
xrl a,r0 //XOR Logic 0010 0010
mov 22h,a // saving and result with 22h memory
mov a,#45h
cpl a //NOT LOGIC 1011 1010
mov 23h,a // saving and result with 23h memory
end

Result:
Result:

Thus the 8051 assembly language experiments using Keil IDE was
executed and simulation results were verified.
EXP. NO: 02 DATE:

Test data transfer between registers and memory

Aim:

To write 8051 assembly language program to test data transfer between register
and memory

SOFTWARE REQUIRED:

1. Keil uVision IDE

Theory:

Earlier to Microcontrollers, Microprocessors were greatly used for each


and every purpose. Microprocessors were containing ALU, general purpose
register, stack pointer, program counter, clock counter and so many other
features which the today’s Microcontroller also possesses. But the difference
between them exists with respect to the number of instructions, access times,
size, reliability, PCB size and so on. Microprocessor contains large instruction
set called as CISC processor whereas Microcontroller contains less number of
instructions and is called as RISC processor. The access time is less in case of
microcontrollers compared to microprocessors and the PCB size reduces in case
of microcontrollers.

There are many versions of microcontrollers 8051, 80528751, AT8951


from Atmel Corporation and many more. In this manual we will study about the
8051 architecture, its features, programming and interfacing.

MCS 8051 is an 8-bit single chip microcontroller with many built-in


functions and is the core for all MCS-51 devices.

The main features of the 8051 core are:

Operates with single Power Supply +5V.

 8-bit CPU optimized for control applications.

 16-bit program counter (PC) and 16-bit data pointer (DPTR).

 8-bit program status word (PSW).

 8-bit stack pointer (SP).

 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).


 128 bytes of On-Chip Data Memory (Internal RAM):

 Four Register Banks, each containing 8 registers (R0 to R7)


[Total 32 reg]

 16-bytes of bit addressable memory.

 80 bytes of general-purpose data memory (Scratch Pad Area).

 Special Function Registers (SFR) to configure/operate microcontroller.

 32 bit bi-directional I/O Lines (4 ports P0 to P3).

 Two 16-bit timers/counters (T0 and T1).

 Full duplex UART (Universal Asynchronous Receiver/Transmitter).

 On-Chip oscillator and clock circuitry.

General Block Diagram of 8051 Microcontroller Architecture


STEPS TO CREATE AND COMPILE Keil µVision-3/4 PROJECT:
Procedure:

1. Launch the Simulator


2. Write the Assembly Program and save it with .asm extension
3. Click the build target option from project menu to assemble the program
4. Click the Debug menu to Start/Stop Debug Session
5. Press STEP button to single step the Program
Data Transfer Programming:
Result:

Thus the 8051 Assembly Language Programs to test the data transfer
between memory and Registers were executed successfully.
EXP. NO: 03 DATE:

PERFORM ALU OPERATIONS

Aim:

To write 8051 assembly language program to perform ALU operations.

SOFTWARE REQUIRED:

1. Keil uVision IDE

Theory:

Earlier to Microcontrollers, Microprocessors were greatly used for each


and every purpose. Microprocessors were containing ALU, general purpose
register, stack pointer, program counter, clock counter and so many other
features which the today’s Microcontroller also possesses. But the difference
between them exists with respect to the number of instructions, access times,
size, reliability, PCB size and so on. Microprocessor contains large instruction
set called as CISC processor whereas Microcontroller contains less number of
instructions and is called as RISC processor. The access time is less in case of
microcontrollers compared to microprocessors and the PCB size reduces in case
of microcontrollers.

There are many versions of microcontrollers 8051, 80528751, AT8951


from Atmel Corporation and many more. In this manual we will study about the
8051 architecture, its features, programming and interfacing.

MCS 8051 is an 8-bit single chip microcontroller with many built-in


functions and is the core for all MCS-51 devices.

The main features of the 8051 core are:

Operates with single Power Supply +5V.

 8-bit CPU optimized for control applications.

 16-bit program counter (PC) and 16-bit data pointer (DPTR).

 8-bit program status word (PSW).

 8-bit stack pointer (SP).

 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).


 128 bytes of On-Chip Data Memory (Internal RAM):

 Four Register Banks, each containing 8 registers (R0 to R7)


[Total 32 reg]

 16-bytes of bit addressable memory.

 80 bytes of general-purpose data memory (Scratch Pad Area).

 Special Function Registers (SFR) to configure/operate microcontroller.

 32 bit bi-directional I/O Lines (4 ports P0 to P3).

 Two 16-bit timers/counters (T0 and T1).

 Full duplex UART (Universal Asynchronous Receiver/Transmitter).

 On-Chip oscillator and clock circuitry.

General Block Diagram of 8051 Microcontroller Architecture


STEPS TO CREATE AND COMPILE Keil µVision-3/4 PROJECT:
Procedure:

1. Launch the Simulator


2. Write the Assembly Program and save it with .asm extension
3. Click the build target option from project menu to assemble the program
4. Click the Debug menu to Start/Stop Debug Session
5. Press STEP button to single step the Program
Arithmetic Instruction Programming

a. Write an assembly language program to perform the addition of two


16-bit numbers.

/program to add 16bit numbers and storing the result in 40h and 41h location
// 1173
/// +2493
/// --------
// 3606
org 00h
mov a, #73h
mov r0, #93h
add a, r0
mov 41h,a
mov a, #11h
mov r0, #24h
add a, r0
mov 40h,a
end

Result:
Before Execution:
After Execution:
c. Write an assembly language program to perform the multiplication of
two 16-bit numbers.

mov r0,#34h // 5678*1234


mov r1,#12h
mov r2,#78h
mov r3,#56h
mov a,r0
mov b,r2
mul ab
mov 33h,a
mov r4,b
mov a,r0
mov b,r3
mul ab
add a,r4
mov r5,a
mov a,b
addc a,#00h
mov r6,a
mov a,r1
mov b,r2
mul ab
add a,r5
mov 32h,a
mov a,b
addc a,r6
mov 00h,c
mov r7,a
mov a,r3
mov b,r1
mul ab
add a,r7
mov 31h,a
mov a,b
addc a,20h
mov 30h,a
end
Result After Execution:

Result:

Thus the 8051 Assembly Language Program to perform ALU operation is


executed successfully.
int result; // Result
// Perform arithmetic
//operations
result = num1 + num2; // Addition
Serial.print("Sum: ");
Serial.println(result);
result = num1 - num2;
// Subtraction
Serial.print("Difference: ");
Serial.println(result);
result = num1 * num2;
//multiplication
Serial.print("Product: ");
Serial.println(result);
result = num1 / num2;
// Division
Serial.print("Quotient: ");
Serial.println(result);
delay(1000);
// Delay for 1 second
}

Output:

Program to Find the Sum of Two Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(57600);
}

void loop() {
// Define two variables to hold the numbers
int num1 = 10;
int num2 = 20;

// Find the sum of the two numbers


int sum = num1 + num2;

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Sum: ");
Serial.println(sum);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

Output:

Program to Calculate the Average of Three Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(9600);
}

void loop() {
// Define three variables to hold the numbers
int num1 = 10;
int num2 = 20;
int num3 = 30;

// Calculate the average of the three numbers


float average = (num1 + num2 + num3) / 3.0;

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Number 3: ");
Serial.println(num3);
Serial.print("Average: ");
Serial.println(average);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

Output:
Program to Find the Maximum of Two Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(57600);
}

void loop() {
// Define two variables to hold the numbers
int num1 = 10;
int num2 = 20;

// Find the maximum of the two numbers


int maxNum = max(num1, num2);

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Maximum: ");
Serial.println(maxNum);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

Output:

Pre-lab questions

1. What is the purpose of an embedded C program performing basic arithmetic operations?


2. Can you provide an example of a basic arithmetic operation that can be performed using an embedded
C program?
3. How do you declare variables in an embedded C program for arithmetic operations?
4. What are the basic arithmetic operators available in embedded C?
5. Can you explain the order of precedence of arithmetic operators in embedded C?

Post Lab Questions

1. How do you perform addition and subtraction operations in an embedded C program?


2. How do you perform multiplication and division operations in an embedded C program?
3. Are there any additional libraries or headers that need to be included for performing arithmetic
operations in embedded C?
4. What are the potential issues or limitations when performing arithmetic operations in embedded C?
5. Can you provide an example of an embedded C program that performs a complex arithmetic operation?
Result:

Thus the embedded C programs to perform basic and arithmetic Programs are verified.
EXP.NO: 05 DATE:

Introduction to Arduino platform and programming

Aim:

To study the Arduino platform and write the Arduino program to blink
the LED.

COMPONENTS NEEDED:
1. Arduino UNO development board
2. LED
3. 220Ω resistor
4. Arduino to PC power cable
5. Breadboard
6. Connecting wires

Theory:
TECHNICAL SPECIFICATIONS OF ARDUINO UNO:

Microcontroller - ATmega328
Operating Voltage - 5V
Supply Voltage (recommended) - 7-12V
Maximum supply voltage (not recommended) - 20V
Digital I/O Pins - 14(of which 6 provide PWM o/p)
Analog Input Pins – 6
DC Current per I/O Pin - 40 mA
DC Current for 3.3V Pin - 50 mA
Flash Memory - 32 KB (ATmega328) of which 0.5KB Used by Bootloader
SRAM - 2 KB (ATmega328)
EEPROM - 1 KB (ATmega328)
Clock Speed - 16 MHz

Component Explanations:
 Analog input pins – pins (A0-A5) that take-in analog values to be
converted to be represented with a number range 0-1023 through an
Analog to Digital Converter (ADC).
 ATmega328 chip – 8-bit microcontroller that processes the sketch you
programmed.
 Built-in LED – an on board LED to pin 13.
 Crystal Oscillator – clock that has a frequency of 16MHz
 DC Jack – where the power source (AC-to-DC adapter or battery)
should be connected. It is limited to input values between 6-20V but
recommended to be around 7-12V.
 Digital I/O pins – input and output pins (0-13) of which 6 of them (3, 5,
6, 9, 10 and 11) also provide PWM (Pulse Width Modulated) output by
using the analogWrite() function. Pins (0 (RX) and 1 (TX)) are also used
to transmit and receive serial data.
 ICSP Header – pins for “In-Circuit Serial Programming” which is
another method of programming.
 ON indicator – LED that lights up when the board is connected to a
power source.
 Power Pins – pins that can be used to supply a circuit with values VIN
(voltage from DC Jack), 3.3V and 5V.
 Reset Button – A button that is pressed whenever you need to restart the
sketch programmed in the board.
 USB port – allows the user to connect with a USB cable the board to a
PC to upload sketches or provide a voltage supply to the board. This is
also used for serial communication through the serial monitor from the
Arduino software.
Integrated Development Environment (IDE):

 Once the board is installed, it’s time to open the Arduino IDE.

 It is fairly simple when compared to larger desktop C language


development systems.
PROGRAMMING:
void setup()
{
// initialize digital pin 10 as an output.
pinMode(10, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

CONNECTION DIAGRAM:
PROCEDURE:
1. Arduino development board is connected to PC through USB cable
2. Open “Arduino” icon from the computer desktop
3. Select tools menu to choose Arduino board type
4. Select tools menu to choose Arduino board COM port
5. Select file menu to choose new and type program
6. Click Verify icon to once compilation done to upload the program to Arduino
controller by clicking Upload icon
7. The circuit connections were given as shown in connection diagram.
8. When the given LED glows with a respective time delay.

Result:
Thus the study of the Arduino platform and the Arduino program to blink
LED has been studied and verified successfully.
the serial monitor to the Zigbee module.

OUTPUT:

GSM Communication (Sending SMS):

#include <SoftwareSerial.h>

SoftwareSerial gsm(2, 3); // RX, TX

void setup() {
Serial.begin(9600);
gsm.begin(9600);
delay(2000);
gsm.println("AT+CMGF=1"); // Set SMS mode to text
delay(1000);
gsm.println("AT+CMGS=\"+1234567890\""); // Replace with desired phone number
delay(1000);
gsm.println("Hello from Arduino!"); // Replace with desired message
delay(1000);
gsm.println((char)26); // Send Ctrl+Z to end the message
}

void loop() {
// Empty loop
}

Procedure
This program uses SoftwareSerial to establish communication between an Arduino and a GSM module. It
sends an SMS message containing a predefined message to a specified phone number.

OUTPUT:
Bluetooth Communication:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3); // RX, TX

void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
}

void loop() {
if (bluetooth.available()) {
char receivedData = bluetooth.read();
Serial.print("Received data: ");
Serial.println(receivedData);
}

if (Serial.available()) {
char sendData = Serial.read();
bluetooth.print(sendData);
}
}
Procedure

This program establishes communication between an Arduino and a Bluetooth module using
SoftwareSerial. It reads data from the Bluetooth module and prints it to the serial monitor, and it also allows
data to be sent from the serial monitor to the Bluetooth module.
Make sure to adjust the pins used for SoftwareSerial communication and modify the specific settings based
on your IoT devices' requirements. Additionally, ensure that you have the necessary libraries installed for
Zigbee, GSM, or Bluetooth communication.

OUTPUT:
Pre-lab questions:

1. What is the purpose of using Zigbee, GSM, and Bluetooth modules in Arduino projects?
2. How can you establish communication between an Arduino and a Zigbee module?
3. Which library is commonly used for Zigbee communication in Arduino programs? How do you use it?
4. How can you send and receive data between an Arduino and a Zigbee module?
5. Can you explain the process of establishing GSM communication with an Arduino?

Post Lab Questions:

1. What are the AT commands used for GSM communication in Arduino programs?
2. How can you send an SMS message using an Arduino and a GSM module?
3. Which library is commonly used for GSM communication in Arduino programs? How do you use it?
4. How do you establish Bluetooth communication between an Arduino and a Bluetooth module?
5. What are the key functions used for Bluetooth communication in Arduino programs?

Result:

Thus the Arduino programs to communicate with IoT devices (Zigbee, GSM, Bluetooth) are written and
verified for its execution
EXP.NO: 07 DATE:

Introduction to Raspberry pi platform and python programming

Aim:

To develop the Raspberry Pi platform and Python programming to implement


LED blinking applications

Components Required:

1. Raspberry Pi kit
2. HDMI to VGA cable
3. MicroSD card with Raspbian image loaded on it
4. Mouse and Keyboard
5. MicroUSB power supply
6. Bred board
7. LED
8. Jumper wire
9. Raspberry Pi IDE Platform

Circuit Connection:
Theory: Introduction to Raspberry PI
Procedure:
Step 1: On the desktop, go the Start Menu and choose for the PYTHON 3, as
shown in figure below

Step 2: After that, PYTHON will run and you will see a window as shown in
below figure.
Step 3: After that, click on New File in File Menu, you will see a new window
Open

Step 4: Save this file as blinky on the desktop.

Step 5: Connect 5v of Raspberry Pi board with LED Anode through GPIO


ports
Step 6: Connect the cathode of LED to ground of Raspberry Pi board.

Step 7: After that write the program for blinky as given below and execute the
program by clicking on “RUN” on “DEBUG” option.

Step 6: Verify the LED blinking status with the respective time delay given by
the program

Program:
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40.GPIO.OUT)
While True:
GPIO.output(40,True)
time.sleep(1)
GPIO.output(40,False)
time.sleep(1)

OUTPUT:
LED ON
LED OFF

Result:
Thus the development of Raspberry Pi platform and Python programming to
implement LED blinking applications was executed successfully and the output
was verified.
EXP.NO: 08 DATE:

Interfacing sensors with Raspberry PI

Aim:

To interfacing sensors with Raspberry Pi platform.

Components Required:

1. Raspberry Pi kit
2. IR Sensor or LDR Sensor or Touch Sensor
3. HDMI to VGA cable
4. Mouse and Keyboard
5. MicroUSB power supply
6. Bred board
7. LED (red & green)
8. Jumper wire
9. Raspberry Pi IDE Platform

Circuit Connection:
Theory: IR Sensor Module
IR (Infrared) Sensor IR (Infrared) Sensor works by emitting infrared
signal/radiation and receiving of the signal when the signal bounces back from
any obstacle. In other words, the IR Sensor works by continuously sending
signal (in a direction) and continuously receive signal, if comes back by
bouncing on any obstacle in the way.

Components:
IR Sensor Emitter: This component continuously emits the infrared signal
Receiver: It waits for the signal which is bounced back by obstacle
Indicator: On board LED to signal if obstacle is deducted by the sensor
Output: Could be used as Input for further processing of the signal
Ground: Ground/Negative point of the circuit
Voltage: Input 3.3V In this tutorial we will learn how we can Interface an IR
sensor with Raspberry pi.

These sensors are most commonly use in small robots like line follower robot,
Edge avoiding robot etc.. Simply putting, it can detect the presence of objects
before it and also differentiate between white and black colour. So lets learn
how to interface this sensor with Raspberry Pi. In this experiment, when there is
no object in front of IR sensor then the Red LED remains turned on and soon as
we put something in front of IR sensor then red LED turns off and Green LED
turn on. This circuit can also serve as Security Alarm Circuit.

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 used in this
assignment is like all IR sensor it has three pins which are 5V, Gnd and 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 the object. 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.
PROGRAM:
import RPi.GPIO as IO

import time

IO.setwarnings(False)

IO.setmode(IO.BCM)

IO.setup(2,IO.OUT) #GPIO 2 -> Red LED as output

IO.setup(3,IO.OUT) #GPIO 3 -> Green LED as output

IO.setup(14,IO.IN) #GPIO 14 -> IR sensor as input

while 1:

if(IO.input(14)==True): #object is far away

IO.output(2,True) #Red led ON

IO.output(3,False) # Green led OFF

if(IO.input(14)==False): #object is near

IO.output(3,True) #Green led ON

IO.output(2,False) # Red led OFF

Procedure:
Step 1: Connections are made as per the circuit diagram.
Step 2: On the desktop, go the Start Menu and choose for the PYTHON 3
Step 3: After that, PYTHON will run and you will see a programming window
Step 4: Click on New File in File Menu, you will see a new window
Step 5: After that write the program for IR sensor module and execute the
program by clicking on “RUN” on “DEBUG” option.
Step 6: Verify the LED’s blinking status with respect to the program.
Result:
Thus the interfacing sensor with Raspberry Pi platform was executed and the
output was verified successfully.
EXP.NO: 09 DATE:

Communicate between Arduino and Raspberry PI using


HC-05 Bluetooth medium
Aim:

To Communicate between Arduino and Raspberry PI using HC-05 bluetooth


medium.

Components Required:

1. Raspberry Pi kit
2. Arduino UNO Board
3. HC-05 Bluetooth Module
4. LED
5. Jumper Wires

Connection Diagram:
Theory:
Wireless communication is swiftly replacing the wired connection when it
comes to electronics and communication. Designed to replace cable connections
HC-05 uses serial communication to communicate with the electronics. Usually,
it is used to connect small devices like mobile phones using a short-range
wireless connection to exchange files. It uses the 2.45GHz frequency band. The
transfer rate of the data can vary up to 1Mbps and is in range of 10 meters.

The HC-05 module can be operated within 4-6V of power supply. It supports
baud rate of 9600, 19200, 38400, 57600, etc. Most importantly it can be
operated in Master-Slave mode which means it will neither send or receive data
from external sources.

Description of pins
Enable - This pin is used to set the Data Mode or and AT command mode (set
high).
VCC - This is connected to +5V power supply.
Ground - Connected to ground of powering system.
Tx (Transmitter) - This pin transmits the received data Serially.
Rx (Receiver) - Used for broadcasting data serially over bluetooth.
State -Used to check if the bluetooth is working properly.

Modes of Operation
The HC-05 Bluetooth Module can be used in two modes of operation:
Command Mode and Data Mode.
Command Mode
In Command Mode, you can communicate with the Bluetooth module through
AT Commands for configuring various settings and parameters of the Module
like get the firmware information, changing Baud Rate, changing module name,
it can be used to set it as master or slave.

A point about HC-05 Module is that it can be configured as Master or Slave in a


communication pair. In order to select either of the modes, you need to activate
the Command Mode and sent appropriate AT Commands.

Data Mode
Coming to the Data Mode, in this mode, the module is used for communicating
with other Bluetooth device i.e. data transfer happens in this mode.

Programming HC-05 with Microcontroller


Technical specs of the code:
 Arduino-Uno is used as the microcontroller.

 Name: HC-05

 Password: 1234 (or 0000)

 Type: Slave

 Mode: Data

 Baud Rate: 9600 with 8 data bits, no parity and 1 stop bit

Arduino UNO Program:

int led=13;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
int a=Serial.parseInt();
Serial.println(a);
if(a==100)
{
digitalWrite(led,HIGH);
}
if (a==200)
{
digitalWrite(led,LOW);
}
}
}

Raspberry Pi Program:

import serial
import time

bluetooth=serial.Serial("/dev/rfcomm7",9600)

while True:
a=input("enter:-")
string='X{0}'.format(a)
bluetooth.write(string.encode("utf-8"))

RESULT:
Input from Raspberry Pi:
enter:100
Output from Arduino UNO:
100
LED ON
Input from Raspberry Pi:
enter:200
Output from Arduino UNO:
200
LED OFF

Procedure:
Step 1: Connections are made as per the circuit Diagram.
Step 2: Install ‘Pi Apps’ to the Raspbian environment.
Step 3: Click the ‘Pi Apps’ icon select the Arduino and Install the Arduino
IDE.
Step 4: Click the Rasbian icon and select the programming option then select
Arduino IDE and write the program, verify the code and upload.
Step 5: Click the Rasbian icon and select the programming option then select
Thonny Python IDE and write the Program.
Step 6: Execute the program by clicking on “RUN” on “DEBUG” option.
Step 7: Enter the respective command from Raspberry PI and verify the
corresponding output to Arduino Uno with LED ON/OFF.

Result:
Thus the communication between Arduino and Raspberry PI using HC-05
Bluetooth medium was executed and the output was verified successfully.
CS3691 EMBEDDED SYSTEMS AND IOT

EXP NO: 10
CLOUD PLATFORM TO LOG THE DATA
DATE

AIM:
To set up a cloud platform to log the data from IoT devices.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Software Requirements Quantity

1 Blynk Platform 1

CLOUD PLATFORM-BLYNK:

Blynk is a smart platform that allows users to create their Internet of Things applications without the
need for coding or electronics knowledge. It is based on the idea of physical programming & provides
a platform to create and control devices where users can connect physical devices to the Internet and
control them using a mobile app.

Setting up Blynk 2.0 Application


To control the LED using Blynk and Raspberry Pi Pico W, you need to create a Blynk project and
set up a dashboard in the mobile or web application. Here’s how you can set up the dashboard:

Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign
in using the registered Email ID.

Step 2: Click on +New Template.


CS3691 EMBEDDED SYSTEMS AND IOT

Step 3: Give any name to the Template such as Raspberry Pi Pico W. Select ‘Hardware Type’ as
Other and ‘Connection Type’ as WiFi.

So a template will be created now.


CS3691 EMBEDDED SYSTEMS AND IOT

Step 4: Now we need to add a ‘New Device’ now.

Select a New Device from ‘Template’.


CS3691 EMBEDDED SYSTEMS AND IOT

Select the device from a template that you created earlier and also give any name to the device. Click
on Create.

A new device will be created. You will find the Blynk Authentication Token Here. Copy it as it is
necessary for the code.
CS3691 EMBEDDED SYSTEMS AND IOT

Step 5: Now go to the dashboard and select ‘Web Dashboard’.

From the widget box drag a switch and place it on the dashboard screen.
CS3691 EMBEDDED SYSTEMS AND IOT

Step 6:

On the switch board click on Settings and here you need to set up the Switch. Give any title to it and
Create Datastream as Virtual Pin.

Configure the switch settings as per the image below and click on create.
CS3691 EMBEDDED SYSTEMS AND IOT

Configure the final steps again.

With this Blynk dashboard set up, you can now proceed to program the Raspberry Pi Pico W board
to control the LED.

Step 7:
CS3691 EMBEDDED SYSTEMS AND IOT

To control the LED with a mobile App or Mobile Dashboard, you also need to setup the Mobile
Phone Dashboard. The process is similarly explained above.

Install the Blynk app on your smartphone The Blynk app is available for iOS and Android. Download
and install the app on your smartphone. then need to set up both the Mobile App and the Mobile
Dashboard in order to control the LED with a mobile device. The process is explained above.

1. Open Google Play Store App on an android phone


2. Open Blynk.App
3. Log In to your account (using the same email and password)
4. Switch to Developer Mode
5. Find the “Raspberry Pi Pico Pico W” template we created on the web and tap on it
6. Tap on the “Raspberry Pi Pico Pico W” template (this template automatically comes because we
created it on our dashboard).
7. tap on plus icon on the left-right side of the window
8. Add one button Switch
9. Now We Successfully Created an android template
10. it will work similarly to a web dashboard template
CS3691 EMBEDDED SYSTEMS AND IOT

RESULT:
lOMoARcPSD|32279070

EX.NO: 10 SETUP A CLOUD PLATFORM TO LOG THE DATA


DATE:

AIM:

To write a program how logs to Google Cloud Logging and how to check the logs in the Logs
Explorer.

SOFTWAREREQUIREMENTS:
Google cloud platform

PROCEDURE:

Step1: Open a Google cloud platform

Step2: Create an account


lOMoARcPSD|32279070

Step3: Enter “logging” in the Filter and choose “Logging Admin”.

Step4: Click the name of the service account to open the settings. Then click “KEYS” => “ADD
KEY” => “Create new key” => “JSON” to create a key.

Step5:installiPython:
(base)$condacreate--namegcp_loggingpython=3.10
(base)$condaactivategcp_logging(gcp_logging)
$pipinstall-Ugoogle-cloud-logging(gcp_logging)
$pipinstallipython

Step6: To check Logs Explorer

Step7: the following query expressions will all find our log:
# Noequalsignor colon:
lOMoARcPSD|32279070

"This is a warning!"# with equal sign:


jsonPayload.message="Thisisawarning!"#withcolon:
jsonPayload.message:"This is"#Amoreexplicitonewithlogicaloperators:
jsonPayload.message = "This is a warning!"
lOMoARcPSD|32279070

logName:"python"
Step8: use the log_struct method:
json_payload = {"message": "This is a warning from
'python_application_name'!"}
logger.log_struct(json_payload,severity=severity.WARNING)

Step9: To delete the temporary project after you have finished.

PROGRAM:

*setup_logging*

importlogging

importgoogle.cloud.logging

client=google.cloud.logging.Client()

# Alternatively, but not recommended. It's helpfulwhen you can't set anenvironmentvariable.
service_key_path="/home/lynn/Downloads/temp-project-for-logging-ff33f97cf72f.json"client
= google.cloud.logging.Client.from_service_account_json(service_key_path)
client.setup_logging()
logging.warning("Thisisawarning!")

*built-inloggingmoduleandaddthehandlerstoaloggercreatefromit*
importlogging
importgoogle.cloud.logging
lOMoARcPSD|32279070

fromgoogle.cloud.logging.handlersimport CloudLoggingHandlerlog_name=
"python_application_name"
# Create a handler for Google Cloud Logging. gcloud_logging_client =
google.cloud.logging.Client()gcloud_logging_handler=CloudLoggingHandler(
gcloud_logging_client, name=log_name
)
#Createastreamhandlerto logmessagestotheconsole.stream_handler =
logging.StreamHandler() stream_handler.setLevel(logging.WARNING)
#Nowcreatealogger and addthehandlers:
logger = logging.getLogger(log_name) logger.setLevel(logging.DEBUG)
logger.addHandler(gcloud_logging_handler)logger.addHandler(stream_handler)
*GoogleLogging:*
In[1]:logger.info("ThisisDEBUG.")In[2]:logger.info("ThisisINFO.") In [3]: logger.warning("This
is WARNING.")# This is WARNING.
In[4]:logger.error("ThisisERROR.")#ThisisERROR.

OUTPUT:

All messages were sent to Google Logging, but only some are printed in the console.

RESULT:
lOMoARcPSD|32279070

EX.NO: 11 LOG DATA USING RASPBERRY PI AND UPLOAD TO THE


DATE: CLOUD PLATFORM
Aim:

To write a program to log data using Raspberry pi and upload to the cloud platform.

HARDWARE REQUIREMENTS:

 RaspberryPi
 Power Cable

SOFTWARE REQUIREMENTS:

 Raspberry PI
 Thing speak IOT platform

PROCEDURE:

Steps for building RaspberryPi Data Loggeron Cloud

Step 1: Signup for Thing Speak


For creating your channel on Thing Speak you first need to signup on Thing Speak. For
creating your account go to www.thinspeak.com

After clicking on signup fill your details.


lOMoARcPSD|32279070

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

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.

Step 3: 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. After this, click on the save channel button to save your details.

Step 4: Getting API Key in Thing Speak. Click on “API Keys” button to get your unique API key
for uploading your CPU data.

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

Step 5: Python Code for Raspberry Pi. Run the python file anytime using the below command:
python /path/filename.py
Assuming you already installed python in Raspberry Pi using this command: sudo apt-get install
python
Step6: If you are using monitor screen then just use the given code. Now install all libraries:
sudoapt-getinstallhttplib
sudo apt-get install urllib

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

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 Celsius
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-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80")
try:
lOMoARcPSD|32279070

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

OUTPUT:

See the CPU temperature data is updating into Thing Speak website.

RESULT:
EXP.NO: 12 DATE:

Design an IOT-based system


AIM:

To design a Smart Agriculture using IOT-based system

COMPONENTS NEEDED:
1. Arduino board
2. Moisture sensor
3. Connecting wires

HARDWARE CONNECTIONS:
Moisture sensor To Arduino
Vcc --- 5v
GND --- GND
A0 --- A0 (Analog Pin of Arduino)

CONNECTION DIAGRAM:
PINOUT DIAGRAM:
Program:

int sensor_pin = A0;

void setup()
{
Serial.begin(9600);
pinMode(sensor_pin, INPUT);
}

void loop()
{
int sensor_data = analogRead(sensor_pin);
Serial.print("Sensor_data:");
Serial.print(sensor_data);
Serial.print("\t | ");

if(sensor_data > 950)


{
Serial.println("No moisture, Soil is dry");
}
else if(sensor_data >= 400 && sensor_data <= 950)
{
Serial.println("There is some moisture, Soil is medium");
}
else if(sensor_data < 400)
{
Serial.println("Soil is wet");
}

delay(100);
}

PROCEDURE:
1. Arduino development board is connected to PC through USB cable
2. Open “Arduino” icon from the computer desktop
3. Select tools menu, choose Arduino board type
4. Select tools menu, choose Arduino board COM port
5. Select file menu, choose new and type program
6. Click Verify icon, once compilation done to upload the program to Arduino controller by
clicking Upload icon
7. The circuit connections were given as shown in connection diagram.
8. Verify the sensor output.
Output:

RESULT:
Thus the design of Smart Agriculture for agro meteorological measurements has been
verified.

You might also like