10.4 Embedded IoT Manual
10.4 Embedded IoT Manual
LABORATORY MANUAL
Regulation–2021
(As per Anna University, Chennai Syllabus)
IIIYEAR VI SEMESTER
Prepared by Approved By
Mr.G.Sivakumar -AP/ECE Dr.C.ArunachalaPerumal
Mr.R.Ramasamy-AP/ECE Professor & Head
Department of ECE
RAMCOINSTITUTEOFTECHNOLOGY
Department of Electronics and Communication engineering
Department Vision, Mission, PEOs, Pos & PSO
VISION
Develop futuristic technologist in Electronics and Communication Engineering to meet the
global challenges and the societal needs of our nation.
MISSION
Educate students to become enlightened engineers with the latest know-how to take on the
challenges concerned with the society.
EquipthestudentswiththecurrenttrendsandlatesttechnologiesinthefieldofElectronicsandCommu
nicationEngineeringtomakethemtechnicallystrongandethicallysound.
ConstantlymotivatethestudentsandfacultymemberstoachieveexcellenceinElectronicsandComm
unicationEngineeringandResearch&Developmentactivities
COURSE OBJECTIVES:
COURSE OUTCOMES:
After completion of the course, it is expected that:
The students will be able to:
1. Apply the various cellular concepts like frequency reuse, channel assignments, handoff strategies
etc., in mobile communication.
2. Elaborate the characteristics of a wireless channel and evolve the system design specifications.
3. Analyze the performance of various digital signalling schemes, equalization and diversity for
fading channels.
4. Examine the performance of various multiple access schemes.
5. Explore the knowledge of various wireless networks in telecommunication field.
Assessment Methods followed:
AIM:
To write a program to perform arithmetic and logical operations between two 8-bit numbers
using a microcontroller.
OBJECTIVE:
To make the student to perform basic arithmetic and logic operation using 8051
microcontroller.
Hardware/Software Required:
MCU8051 IDLE
PROCEDURE:
Ensure that you have the MCU8051 Idle Simulator software installed on your system.
Set up the simulation environment. Prepare the input data or program that you want to
simulate on the 8051 microcontroller.
Open new project -> Type program and save as .asm extension
Click Start simulation icon -> click Run Icon
START
PERFORM ADDITION/
SUBTRACTION/MULTIPLICATION/
DIVISION
STOP
I. ADDITION PROGRAM :
OBSERVATION:
INPUT OUTPUT
56H
95H
OBSERVATION:
INPUT OUTPUT
50 4500
OBSERVATION:
INPUT OUTPUT
4500
DIVISION PROGRAM:
LABEL PROGRAM COMMENTS
MOV A,#50 Initialize the A value
MOV A,#10 Initialize the B value
DIV A,B Division A by B
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
INC DPTR Increment DPTR
MOV A, B Move B register value to accumulator
MOVX @DPTR,A Move accumulator to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
50
4500
10
OBSERVATION:
INPUT OUTPUT
02 4500
OR OPERATION PROGRAM:
LABEL PROGRAM COMMENTS
MOV A,#02 Initialize the A value
MOV A, #06 Initialize the B value
ORL A,B OR operation between A & B
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
02
4500
06
III.NOT OPERATION PROGRAM:
LABEL PROGRAM COMMENTS
MOV A,#06 Initialize the A value
CPL A Complement of A
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
06 4500
RESULT:
Thus the assembly language program for arithmetic and logical operation was executed successfully.
Expt.No.:
TEST DATA TRANSFER BETWEEN REGISTERS AND MEMORY.
Date:
AIM:
To write a program to test data transfer between registers and memory using microcontroller.
APPARATUS REQUIRED
1. MCU8051 IDLE - 1
3. Power Cable - 1
4. Keyboard - 1
PROCEDURE:
Ensure that the MCU8051 Idle Simulator software installed on your system.
Set up the simulation environment. Prepare the input data or program that you want to
simulate on the 8051 microcontroller.
Open new project -> Type program and save as .asm extension
Click Start simulation icon -> click Run Icon
Program:
MOV RO,#34H
MOVR1,#12H
MOV R2 ,#DCH
MOV R3,#FEH
CLR C
MOV A, R0
ADD A, R2
MOV A, R1
ADDC A, R3
MOV 21H, A
MOV 22H, C
END
OBSERVATION:
INPUT OUTPUT
06 4500
Transfer data from external memory to internal RAM
OBSERVATION:
INPUT OUTPUT
External
memory Register Data
Data
Location
4100 R0
OBSERVATION:
INPUT OUTPUT
External
Register Data memory
Data
Location
R1 4100
RESULT:
Thus the data transfer between registers and memory are executed successfully.
Expt.No.:
BASIC ARITHMETIC AND LOGICAL OPERATION
Date:
AIM:
To write a program to perform arithmetic and logical operation between two 8-bit numbers
using8051 microcontroller.
OBJECTIVE:
To make the student to perform basic arithmetic and logic operation using 8051
microcontroller.
APPARATUS REQUIRED
Sl.No. COMPONENTS RANGE QUANTITY
2. Power Cable - 1
3. Keyboard - 1
ALGORITHM:
a. Arithmetic Operation
Step1: Initialize memory pointer to data location.
Step2: Get the first number from memory in accumulator.
Step3: Get the second number and add/sub/mul/div it to the accumulator.
Step4: Store the answer at another memory location.
b. Logical Operation
Step1: Get the two numbers in mentioned registers using MOV instruction
Step2: AND/OR/NOT these two numbers using AND/OR/NOT instruction store the coming
output from these AND/OR/NOT operation using MOV instructions
Step3: AND/OR/NOT operation is used for masking particular bits in a byte
FLOW CHART: ADDITION/SUBTRACTION/MULTIPLICATION/DIVISION OPERATION
START
STOP
I. ADDITION PROGRAM:
ADDRESS OPCODE LABEL PROGRAM COMMENTS
4100 MOV A,#50 Initialize the A value
MOV A,#10 Initialize the B value
ADD A, B Add A & B
MOV DPTR, #4500 Initialize the DPTR value
MOVX @DPTR, A Move the accumulator value to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
50
4500
10
II. SUBTRACTION PROGRAM:
ADDRESS OPCODE LABEL PROGRAM COMMENTS
4100 MOV A,#50 Initialize the A value
MOV A,#10 Initialize the B value
SUBB A,B Subtract A & B
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
50
4500
10
OBSERVATION:
INPUT OUTPUT
4500
IV. DIVISION PROGRAM:
ADDRESS OPCODE LABEL PROGRAM COMMENTS
4100 MOV A,#50 Initialize the A value
MOV A,#10 Initialize the B value
DIV A,B Division A by B
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
INC DPTR Increment DPTR
MOV A, B Move B register value to accumulator
MOVX @DPTR,A Move accumulator to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
50
4500
10
OBSERVATION:
INPUT OUTPUT
02
4500
06
II.OR OPERATION PROGRAM:
ADDRESS OPCODE LABEL PROGRAM COMMENTS
4100 MOV A,#02 Initialize the A value
MOV A, #06 Initialize the B value
ORL A,B OR operation between A & B
MOV DPTR,#4500 Initialize the DPTR value
MOVX @DPTR,A Move the accumulator value to DPTR
Loop SJMP Loop End of the program
OBSERVATION:
INPUT OUTPUT
02
4500
06
OBSERVATION:
INPUT OUTPUT
06 4500
RESULT:
Thus the assembly language program for arithmetic and logical operation was executed successfully.
Expt.No.: WRITE BASIC AND ARITHMETIC PROGRAMS USING
Date: EMBEDDED C
AIM:
To write 8051 Assembly Language Program for an 8-bit addition using Keil simulator and execute
it.
SOFTWARE REQUIRED:
Keilμvision5 IDE
KEIL µVision:
KEIL is the most popular software simulator. It has many features like interactive IDE
and supports both C and assembly languages for compilation and simulation.
ADDITION:
#include<reg51.h>
void main(void)
{
unsigned a,b,c;
a=0x08;
b=0x02;
P0=0X00;
c=a+b;
P0=c;
}
OUTPUT :
SUBTRACTION:
#include<reg51.h>
void main(void)
{
unsigned a,b,c;
a=0x0a;
b=0x02;
P0=0X00;
c=a-b;
P0=c;
}
OUTPUT:
MULTIPLICATION:
#include<reg51.h>
void main(void)
{
unsigned a,b,c;
a=0x05;
b=0x02;
P0=0X00;
c=a*b;
P0=c;
}
OUTPUT:
DIVISION:
#include<reg51.h>
void main(void)
{
unsigned a,b,c;
a=0x08;
b=0x02;
P0=0X00;
c=a/b;
P0=c;
}
OUTPUT:
Result:
Thus embedded C program for the arithmetic operation was executed successfully.
Expt.No.: 5
INTRODUCTION TO THE ARDUINO PLATFORM
Date:
AIM:
To study the basics of Arduino Uno board and Arduino IDE 2.0 software.
INTRODUCTION TO ARDUINO:
Arduino is a project, open-source hardware, and software platform used to design and build
electronic devices. It designs and manufactures microcontroller kits and single-board interfaces for
building electronics projects. The Arduino boards were initially created to help students with the non-
technical background. The designs of Arduino boards use a variety of controllers and
microprocessors. Arduino is an easy-to-use open platform for creating electronic projects.
Arduino boards play a vital role in creating different projects. It makes electronics accessible to
non-engineers, hobbyists, etc. The various components present on the Arduino boards are a
Microcontroller, Digital Input/output pins, USB Interface and Connector, Analog Pins, reset buttons,
Power buttons, LEDs, Crystal oscillators, and Voltage regulators. Some components may differ
depending on the type of board. The most standard and popular board used over time is Arduino
UNO. The ATmega328Microcontroller present on the UNO board makes it rather powerful than
other boards. There are various types of Arduino boards used for different purposes and projects. The
Arduino Boards are organized using the Arduino (IDE), which can run on various platforms. Here,
IDE stands for Integrated Development Environment. Let's discuss some common and best Arduino
boards.
2) Arduino Nano :
The Arduino Nano is a small Arduino board based on ATmega328P or ATmega628
Microcontroller.The connectivity is the same as the Arduino UNO board. The Nano board is defined
as a sustainable,small, consistent, and flexible microcontroller board. It is small in size compared to
the UNO board.The devices required to start our projects using the Arduino Nano board are Arduino
IDE and mini-USB. The Arduino Nano includes an I/O pin set of 14 digital pins and 8 analog pins. It
also includes6 Power pins and 2 Reset pins.
The components of Arduino UNO board are shown below:Let's discuss each component in detail.
3) Arduino Mega:
The Arduino Mega is based on the ATmega2560 Microcontroller. The ATmega2560 is an 8-
bitmicrocontroller. We need a simple USB cable to connect to the computer and the AC to DC
adapteror battery to get started with it. It has the advantage of working with more memory space.
TheArduino Mega includes 54 I/O digital pins and 16 Analog Input/Output (I/O), ICSP header, a
resetbutton, 4 UART (Universal Asynchronous Reciever/Transmitter) ports, USB connection, and a
power jack.
4) Arduino Micro :
The Arduino Micro is based on the ATmega32U4 Microcontroller. It consists of 20 sets of pins.
The7 pins from the set are PWM (Pulse Width Modulation) pins, while 12 pins are analog input
pins.The other components on board are a reset button, a 16MHz crystal oscillator, an ICSP header,
anda micro-USB connection. The USB is built in the Arduino Micro board.
5) Arduino Leonardo:
The basic specification of the Arduino Leonardo is the same as the Arduino Micro. It is also basedon
the ATmega32U4 Microcontroller. The components present on the board are 20 analog and digital
pins, a reset button, a 16MHz crystal oscillator, an ICSP header, and a micro USB connection.
Arduino UNO :
The Arduino UNO is a standard board of Arduino. Here UNO means 'one' in Italian. It was
named as UNO to label the first release of Arduino Software. It was also the first USB board released
by Arduino. It is considered as the powerful board used in various projects. Arduino.cc developed the
Arduino UNO board.Arduino UNO is based on an ATmega328P microcontroller. It is easy to use
compared to other boards, such as the Arduino Mega board, etc. The board consists of digital and
analog Input/Output pins (I/O), shields, and other circuits.
The Arduino UNO includes 6 analog pin inputs, 14 digital pins, a USB connector, a power jack, and
an ICSP (In-Circuit Serial Programming) header. It is programmed based on IDE, which stands for
Integrated Development Environment. It can run on both online and offline platforms.The IDE is
common to all available boards of Arduino.
Power LED Indicator- The ON status of LED shows the power is activated. When the power
is OFF, the LED will not light up.
Digital I/O pins- The digital pins have the value HIGH or LOW. The pins numbered from D0
to D13 are digital pins.
TX and RX LED's- The successful flow of data is represented by the lighting of these LED's.
AREF- The Analog Reference (AREF) pin is used to feed a reference voltage to the Arduino
UNO board from the external power supply.
USB- It allows the board to connect to the computer. It is essential for the programming of the
Arduino UNO board.
Crystal Oscillator- The Crystal oscillator has a frequency of 16MHz, which makes the Arduino
UNO a powerful board.
Voltage Regulator- The voltage regulator converts the input voltage to 5V.
GND- Ground pins. The ground pin acts as a pin with zero voltage.
Analog Pins- The pins numbered from A0 to A5 are analog pins. The function of Analog pins
is to read the analog sensor used in the connection. It can also act as GPIO (General Purpose
Input Output) pins.
Open the LED blink example sketch: File > Examples >01.Basics > Blink.
Select your board type and port
Need to select the entry in the Tools > Board menu that corresponds to your Arduino board.
Select the serial device of the board from the Tools | Serial Port menu. This is likely to be
COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find
out, you can disconnect your board and re-open the menu; the entry that disappears should be
the Arduino board. Reconnect the board and select that serial port.
Now, simply click the "Upload" button in the environment. Wait a few seconds - you should
see the RX and TX leds on the board flashing. If the upload is successful, the message "Done
uploading." will appear in the status bar.
RESULT:
Expt.No. 5(B)
INTRODUCTION TO ARDIUNO PROGRAMING
Date:
AIM:
To write and execute different Arduino programming for analog, digital signals and serial
Communication.
APPARATUSREQUIRED:
THEORY:
The DHT11 sensor is a low-cost digital temperature and humidity sensor that provides reliable and
accurate readings of temperature and humidity with a relatively simple interface. The DHT11 sensor
utilizes a capacitive humidity sensor and a thermistor to measure humidity and temperature,
respectively. The capacitive humidity sensor consists of a moisture-sensitive capacitor whose
capacitance changes with variations in humidity. When the relative humidity increases, moisture is
absorbed by the sensor, causing the dielectric constant of the sensing material to change, thereby altering
the capacitance of the capacitor. By measuring this change in capacitance, the humidity level can be
determined. The DHT11 sensor also incorporates a thermistor, which is a type of resistor whose
resistance varies with temperature.
The thermistor's resistance decreases as the temperature increases and vice versa. By measuring the
resistance of the thermistor, the temperature can be calculated using a known relationship between
resistance and temperature. The DHT11 sensor has a temperature measurement range of 0°C to 50°C
with an accuracy of ±2°C and a humidity measurement range of 20% to 90% RH with an accuracy of
±5%. The DHT11 sensor operates on a wide range of voltages (typically 3.3V to 5V) and consumes very
low power, making it suitable for battery-powered applications.
PROCEDURE:
1. Connect the Arduino Uno to your computer using the USB cable.
2. Launch the Arduino IDE software on your computer.
3. Place the DHT11 or DHT22 sensor on the breadboard.
4. Connect the power and ground pins of the sensor to the 5V and GND pins on the Arduino Uno,
respectively.
5. Connect the out pin of the sensor to analog pin A0 on the Arduino Uno.
6. Write the code in the Arduino IDE to read temperature and humidity values from the sensor.
7. Upload the code to the Arduino Uno.
8. Open the serial monitor in the Arduino IDE to observe the temperature and humidity readings.
PROGRAM:
BUZZER:
LED BLINKING:
void setup() {
void loop() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
CIRCUIT DIAGRAM:
CODE:
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11 // Other possibilities DHT21, DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temp) || isnan(humidity))
{
Serial.println("Failed to read from DHT11");
}
else
{
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C, ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
delay(5000);
}
RESULT
Thus the interfacing of a LED, Buzzer, temperature and humidity sensor with an
Arduino board successfully completed and measured real time temperature and humidity values
using DHT 11 Sensor.
Expt.No. 6
EXPLORE DIFFERENT COMMUNICATION METHODS
Date: WITH IOT DEVICES (ZIGBEE, GSM, BLUETOOTH)
AIM:
To explore different communication methods with IoT devices (Zigbee, GSM, Bluetooth).
IoT devices require reliable and efficient communication methods to transmit data and interact
with other devices or systems. Here are three commonly used communication methods for IoT
devices:
Zigbee:
GSM is a widely used cellular network technology that enables IoT devices to connect to the
internet using SIM cards. It operates on various frequency bands and provides wide coverage, making
it suitable for applications that require long-range communication. GSM is commonly used in
applications such as asset tracking, remote monitoring, and smart cities.
Bluetooth:
Bluetooth is a short-range wireless communication technology that operates on the 2.4 GHz
frequency band. It is commonly used for connecting IoT devices to smartphones, tablets, and other
nearby devices. Bluetooth Low Energy (BLE) is a power-efficient version of Bluetooth that is ideal
for battery-powered IoT devices. Bluetooth is widely used in applications such as wearable devices,
healthcare monitoring, and home automation. Each communication method has its advantages and
limitations, and the choice depends on the specific requirements of the IoT application. Factors to
consider include range, power consumption, data rate, security, and interoperability with other
devices or systems.
Expt.No. 6(a)
BLUETOOTH COMMUNICATION
Date:
AIM:
To control an LED wirelessly using a Bluetooth module HC-05 and an Arduino board.
THEORY:
Bluetooth:
Bluetooth is a short-range wireless communication technology that operates on the 2.4 GHz
frequency band. It is commonly used for connecting IoT devices to smartphones, tablets, and other
nearby devices. Bluetooth Low Energy (BLE) is a power-efficient version of Bluetooth that is ideal
for battery-powered IoT devices. Bluetooth is widely used in applications such as wearable devices,
healthcare monitoring, and home automation. Each communication method has its advantages and
limitations, and the choice depends on the specific requirements of the IoT application. Factors to
consider include range, power consumption, data rate, security, and interoperability with other
devices or systems.
PROCEDURE
Arduino DHT11
Pin 12 Data
Arduino HC-05
Tx Rx
Rx Tx
2. Upload the Arduino code to your Arduino board (Note: Before uploading the code, remove Tx, Rx
pins from the Arduino board and after uploading the code, connect the pins at Tx and Rx.
3. Use Bluetooth Receiver Controller application (Android) to receive the transmitted data wirelessly.
4. Pair HC-05 Bluetooth module with the smartphone application and open the terminal window.
5. Send the character '1' to turn on the LED and '0' to turn it off.
PROGRAM:
#define ledPin 12
int data = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
if (data == '0')
{
digitalWrite(ledPin, LOW);
Serial.println("LED: OFF");
}
else if (data == '1')
{
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");
}
}
}
RESULT:
The experiment successfully demonstrated the interfacing of a LED and bluetooth module
with an Arduino board, enabling turning on/off the LED from the smartphone application terminal
window.
Expt.No. 6(b)
ZIGBEE COMMUNICATION
Date:
AIM:
The aim of this experiment is to demonstrate the interfacing of an Arduino microcontroller with a
Zigbee module to establish wireless communication between devices.
5 Zigbee Module 2
THEORY:
#include "SoftwareSerial.h"
SoftwareSerialXBee(2,3);
int BUTTON = 5;
boolean toggle = false; //this variable keeps track of alternative click of the button
void setup()
{
Serial.begin(9600);
pinMode(BUTTON, INPUT_PULLUP);
XBee.begin(9600);
}
void loop()
{
//When button is pressed (GPIO pulled low) send 1
if (digitalRead(BUTTON) == LOW && toggle)
{
Serial.println("Turn on LED");
toggle = false;
XBee.write('1');
delay(1000);
}
//When button is pressed second time (GPIO pulled low) send 0
else if (digitalRead(BUTTON) == LOW && !toggle)
{
Serial.println("Turn off LED");
toggle = true;
XBee.write('0');
delay(1000);
}
}
PROCEDURE:
1. Connect Zigbee module's TX pin to Arduino's digital pin 2 (RX) and RX pin to digital pin 3 (TX).
Thus the experiment, interfacing of a Zigbee module with an Arduino board has been
successfully completed, facilitating communication between two Zigbee devices connected via
Arduino.
Expt.No. 6(b)
GSM COMMUNICATION
Date:
AIM:
APPARATUS REQUIRED:
THEORY:
GSM SIM module is an ultra-compact and reliable wireless module. It provides a complete
Dual-band GSM/GPRS solution in a Surface Mount Technology (SMT) module, which can be easily
integrated into customer applications. This module offers an industry- standard interface and delivers
excellent performance for voice, SMS, Data, and Fax over GSM/GPRS 900/1800 MHz frequencies.
The SIM module is a GSM/GPRS modem that allows devices to communicate over cellular networks.
It works by integrating the necessary hardware and software to establish a connection to the GSM
network and facilitate data transmission.
PROCEDURE:
In this section we have listed the steps to successfully boot our SIM GSM Module:
• Insert the SIM card into the GSM module and lock it.
• Now wait for some time (say 1 minute) and see the blinking rate of the status LED’ or ‘network
LED’ (the GSM module will take some time to establish a connection with the mobile network).
• Once the connection is established successfully, the status/network LED will blink continuously
every 3 seconds. You may try making a call to the mobile number of the SIM card inside the GSM
module. If you hear a ring back, the GSM module has successfully established a network connection.
Pin of SIM GSM Module Pin of Arduino Board
Tx 10 as Rx
Rx 9 as Tx
GND GND
Program:
}
}
if (mySerial.available() > 0)
{
Serial.write(mySerial.read());
}
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); // Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milliseconds or 1 second
mySerial.println("AT+CMGS=\"+xxxxxxxxxxx\"\r"); //Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module"); // The SMS text you want to send delay(100);
mySerial.println((char)26); // ASCII code of CTRL+Z delay(1000);
}
void DialCall()
{
mySerial.println("ATD+xxxxxxxxxxxx;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the
end!!
delay(100);
}
Output:
RESULT
The experiment successfully demonstrated the interfacing of a GSM module with an Arduino board,
enabling sending and receiving messages between devices.
Expt.No. 7
INTRODUCTION TO RASPBERRY PI PLATFORM AND
Date: PYTHON PROGRAMMING
AIM :
The objective of this experiment is to introduce the Raspberry Pi platform and Python
programming.
APPARATUS REQUIRED:
5. Personal Computer - 1
THEORY:
The Raspberry Pi 3 Model B+ is a versatile single-board computer renowned for its compact
size and powerful performance. Released in 2018 as an upgrade to its predecessor, it boasts a 64-bit
quad-core processor running at 1.4 GHz, offering enhanced processing capabilities for various
computing tasks. Notable improvements include dual-band wireless LAN supporting 2.4GHz and
5GHz frequencies, along with Bluetooth 4.2/BLE, ensuring faster and more reliable networking.
Gigabit Ethernet over USB 2.0 further enhances connectivity options, complementing its array of
USB ports, HDMI, and GPIO pins. With 1GB LPDDR2 SDRAM and support for microSD storage,
the Raspberry Pi 3 Model B+ accommodates a wide range of projects, from home automation to IoT
applications. The official operating system for the Raspberry Pi is called Raspberry Pi OS (formerly
known as Raspbian). Raspberry Pi OS is a Debian-based Linux distribution optimized for the
Raspberry Pi hardware.
Features:
Quad Core 1.2GHz Broadcom BCM2837 64bit CPU.
1GB RAM.
BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board.
100 Mbps Base Ethernet.
40-pin extended GPIO.
PIN DIAGRAM:
4 USB 2.0 ports.
4 Pole stereo output and composite video port.
Full size HDMI.
CSI camera port for connecting a Raspberry Pi 3 B+ camera.
DSI display port for connecting a Raspberry Pi 3 B+ touchscreen display.
Micro SD port for loading your operating system and storing data.
Upgraded switched Micro USB power source up to 2.5A.
Processor: Raspberry Pi uses Broadcom BCM2835 system on chip which is an ARM processor and
Video core Graphics Processing Unit (GPU). It is the heart of the Raspberry Pi which controls the
operations of all the connected devices and handles all the required computations.
HDMI: High Definition Multimedia Interface is used for transmitting video or digital audio data to a
computer monitor or to digital TV. This HDMI port helps Raspberry Pi to connect its signals to any
digital device such as a monitor digital TV or display through an HDMI cable.
GPIO ports: General Purpose Input Output ports are available on Raspberry Pi which allows the user
to interface various I/P devices.
Audio output: An audio connector is available for connecting audio output devices such as
headphones and speakers.
USB ports: This is a common port available for various peripherals such as a mouse, keyboard, or
any other I/P device. With the help of a USB port, the system can be expanded by connecting more
peripherals.
SD card: The SD card slot is available on Raspberry Pi. An SD card with an operating system
installed is required for booting the device.
Ethernet: The ethernet connector allows access to the wired network, it is available only on the
model B of Raspberry Pi.
Power supply: A micro USB power connector is available onto which a 5V power supply can be
connected.
Camera module: Camera Serial Interface (CSI) connects the Broadcom processor to the Pi camera.
Display: Display Serial Interface (DSI) is used for connecting LCD to Raspberry Pi using 15 15-pin
ribbon cables. DSI provides a high-resolution display interface that is specifically used for sending
video data.
A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins along
the top edge of the board. A 40-pin GPIO header is found on all current Raspberry Pi boards
Voltages:
Two 5V pins and two 3.3V pins are present on the board, as well as a number of ground pins (GND),
which can not be reconfigured. The remaining pins are all general-purpose 3.3V pins, meaning
outputs are set to 3.3V and inputs are 3.3V-tolerant.
Outputs:
A GPIO pin designated as an output pin can be set to high (3.3V) or low (0V).
Inputs :
A GPIO pin designated as an input pin can be read as high (3.3V) or low (0V). This is made easier
with the use of internal pull-up or pull-down resistors. Pins GPIO2 and GPIO3 have fixed pull-up
resistors, but for other pins this can be configured in software.
Other functions :
As well as simple input and output devices, the GPIO pins can be used with a variety of alternative
functions, some are available on all pins, others on specific pins.
Pulse width modulation (PWM) is a modulation technique that generates variable-width pulses to
represent the amplitude of an analog input signal.
SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8), CE1 (GPIO7)
SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1 (GPIO17);
CE2 (GPIO16)
I2C :
I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into
devices for serial communication. I2C stands for Inter-Integrated Circuit. It is a bus interface
connection protocol incorporated into devices for serial communication.
Serial:
TX (GPIO14); RX (GPIO15)
GPIO pinout :
A GPIO reference can be accessed on your Raspberry Pi by opening a terminal window and running
the command pinout. This tool is provided by the GPIO Zero Python library, which is installed by
default in Raspberry Pi OS.
Serial interface:
The serial interface on Raspberry Pi has received (Rx) and transmit (Tx) pins for
communication with serial peripherals.
Raspberry Pi has multiple serial ports. The first two are called primary and secondary. By default,
primary appears on GPIO 14 (transmit) and 15 (receive) of the J8. Secondary is used by bluetooth, on
Raspberry Pi that support bluetooth. Each port is driven by a UART. On every Raspberry Pi there are
at least two of them: UART0 and UART1. The assignment of which UART drives which port
depends on the model and its configuration.
Thonny IDE :
Thonny is an open-source IDE which is used to write and upload programs to different
development boards such as Raspberry Pi Pico, Raspberry Pi 1 , Raspberry Pi 2, Raspberry Pi 3,
ESP32 and ESP8266. It is extremely interactive and easy to learn IDE as much as it is known as the
beginner-friendly IDE for new programmers. With the help of Thonny, it becomes very easy to code
in Micropython as it has a built-in debugger that helps to find any error in the program by debugging
the script line by line. You can realize the popularity of Thonny IDE from this that it comes pre-
installed in Raspian OS which is an operating system for a Raspberry Pi. It is available to install on r
Windows, Linux, and Mac OS.
PROCEDURE:
2. Open the Thonny IDE and create new file. Type the program, save and run.
GPIO.setmode(GPIO.BCM)
LED_PIN = 17
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
GPIO.output(LED_PIN, GPIO.HIGH)
GPIO.output(LED_PIN, GPIO.LOW)
except KeyboardInterrupt:
AIM:
1 Thonny IDE 1
5 IR sensor 1
6 Temperature sensor 1
Theory:
An infrared (IR) sensor is a device that detects infrared radiation emitted or reflected by
objects in its field of view. It typically consists of an IR emitter and an IR detector. The emitter emits
infrared radiation, while the detector detects the radiation reflected or emitted by objects. IR sensors
are commonly used for various applications such as motion detection, proximity sensing, and
temperature measurement. They work based on the principle that different materials emit and reflect
different amounts of infrared radiation at different temperatures. By measuring the intensity of
infrared radiation, IR sensors can determine the presence or absence of objects, as well as their
temperature.
The DHT11 sensor is a digital temperature and humidity sensor that utilizes a capacitive
humidity sensor and a thermistor to measure environmental conditions. It can detect temperature in
the range of 0°C to 50°C with an accuracy of ±2°C, and humidity in the range of 20% to 80% with an
accuracy of ±5%. The sensor outputs data in a digital format, making it easy to interface with
microcontrollers like Arduino. The DHT11 sensor is widely used in applications requiring precise
monitoring of temperature and humidity levels, such as weather stations, HVAC systems, and
environmental monitoring devices.
PROCEDURE:
1. Once Raspberry Pi 3 B+ is booted up to GUI, Connect the keyboard and Mouse to USB slots.
2. Now you can write your programs at Thonny Python IDE. Menu → Programming → Thonny
Python IDE. File → New. You can write your Program here and save.
IR Sensor
GPIO Pin Components
GP16 IR sensor
DHT11 Sensor
GP4 DHT11 Sensor
4. Execute the program at terminal only by following command
5. Check the temperature and humidity values and the presence of objects in the screen.
PROGRAM FOR DHT Sensor:
import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.D4, use_pulseio=False) ## Raspberry pi 4 - gpio4
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32humidity = dhtDevice.humidity
print("Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(temperature_f, temperature_c, humidity))
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(2.0)
OUTPUT:
PROGRAM FOR IR SENSOR:
gpio.setmode(gpio.BOARD)
while True:
sensor=gpio.input(36)
if sensor==1:
sleep(0.1)
elif sensor==0:
print(" detect")
OUTPUT :
RESULT
Thus the experiment, interfacing of IR and DHT11 sensors with Raspberry PI board using
python programming was implement successfully. Real-time temperature and humidity readings were
obtained as a result.
Expt.No. 9
COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI
Date: USING ANY WIRELESS MEDIUM
AIM:
5. Personal Computer - 2
Theory:
Procedure
2. Open Thonny IDE in another PC and write slave code and save.
Arduino :
int led=13;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600); //default baud rate for bt 38400
}
void loop()
{
if(Serial.available())
{
int a=Serial.parseInt();
Serial.println(a);
if (a==1)
{
digitalWrite(led, HIGH);
}
if (a == 0)
{
digitalWrite(led, LOW);
}
}
}
Raspberry Pi Bluetooth:
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"))
Arduino
UNO Pin Bluetooth Module
D2 Tx
D3 Rx
D13 LED
4. Arduino:
5. Raspberry :
CTRL + Z
sudo rfcomm bind 7 mac address ## enter command paste your mac ad
Connect the Bluetooth on raspberry pi ,right corner click Bluetooth icon and pair
RESULT
The experiment successfully executed the communication between Arduino and Raspberry PI
using Bluetooth wireless medium to blink a LED with Raspberry PI board using python
programming.
Expt.No. 10
SETUP A CLOUD PLATFORM TO LOG THE DATA
Date:
AIM:
Theory:
Procedure
Step1: Navigate to the Thing Speak website using your web browser
(Link: https://thingspeak.com/login?skipSSOCheck=true).
Step 2: Login using the credentials if an existing account is present or else create a new account.
Step 3: Once Logged in, create new channel. Give a channel name and required field names and save
channel.
Step 4: Go to the Sharing tab and select ‘Share channel view with everyone’.
Step 5: Under API Keys tab, note the ‘Write API Key’ for enabling communication from any device.
RESULT
The experiment successfully set up a cloud platform in Things Speak to log the data from IoT
devices.
Expt.No. 11
LOG DATA USING RASPBERRY PI AND UPLOAD TO THE
Date: CLOUD PLATFORM
AIM:
To write the program Log Data using Raspberry PI and upload it to the cloud platform
1 Thonny IDE 1
Theory:
To log data using a Raspberry Pi and upload it to a cloud platform utilizing the Raspberry Pi
CPU temperature, begin by setting up your Raspberry Pi and writing a Python script to read the CPU
temperature from the appropriate system file. Modify the script to upload the CPU temperature data
to the chosen cloud platform using their respective APIs or SDKs, ensuring proper authentication and
data formatting for security. To ensure continuous monitoring, schedule the script to run at regular
intervals using a cron job or system d service. Implement security measures, such as encryption, to
protect the data during transmission, and set up monitoring for error detection and performance
optimization.
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. Shown in Fig. 1. After this
verifies your E-mail id and click on continue.
Figure 1: Signup for 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 Thing Speak Website. Click on “API Keys” button to get your unique API
key for uploading your CPU data.Shown in Fig. 3. Now copy your “Write API Key”. We will use this
API key in our code.
Output :
CPU temperature data is updating into ThingSpeak website:
RESULT:
The experiment successfully set up a cloud platform in Things Speak to log the CPU
temperature data from Raspberry PI board to the cloud.
Expt.No. 12
DESIGN AN IOT BASED SYSTEM
Date: