Cs3691-E-iot Lab Record - Final
Cs3691-E-iot Lab Record - Final
It is hereby certified that this is the bonafide record of work done by Mr./Ms …………………
Reg.No ………………………. in CS3691 – EMBEDDED SYSTEMS AND IOT Laboratory during the year
2023-2024 and submitted for Anna University PracticalExaminations held on………………………
1
LIST OF EXPERIMENTS
2
EX.NO: 1
WRITE 8051 ASSEMBLY LANGUAGE EXPERIMENTS
DATE: USING SIMULATOR
AIM:
To write 8051 Assembly Language experiments using simulator.
STEPS:
1. Download and Install Keil u Vision. Download the Keil uVision IDE from the official website and
install it on your computer following the installation instructions.
2. Create a New Project Open Keil uVision and create a new project by selecting "Project" from the
menu bar and then "New µVision Project." Choose a folder to save your project, give it a name, and select
the 8051 microcontroller variant you are using (e.g., AT89C51).
3. Add a New Source File In the Project window, right-click on the "Source Group 1" folder, and
select "Add New Item to Group 'Source Group 1'." Name the file with a ".asm" extension (e.g.,
"experiment1.asm").
4. Paste the Assembly Code Open the newly created ".asm" file, and paste the 8051 assembly language
code into it.
5. Build the Project Click on the "Project" menu and select "Build Target" to assemble the code and
generate the HEX file.
6. Configure the Simulator Configure the simulator settings to match your hardware setup. This
includes specifying the crystal frequency, RAM size, and any external peripherals you are using.
7. Run the Simulator Click on the "Debug" menu and select "Start/Stop Debug Session" to run the
simulation. The simulator will execute the code, and you can observe the results in the simulation window.
8. Debug and Monitor During the simulation, you can set breakpoints, single-step through the code,
and monitor the CPU registers and memory to understand the program's behavior.
PROGRAM:
ORG 0H
MAIN:
MOV P1, #0FFH ; Turn on all LEDs
ACALL DELAY ; Call delay subroutine
MOV P1, #00H ; Turn off all LEDs
ACALL DELAY ; Call delay subroutine
SJMP MAIN ; Jump back to MAIN
DELAY:
MOV R2, #0FFH ; Load R2 with 0xFF
LOOP1:
MOV R1, #0FFH ; Load R1 with 0xFF
LOOP2:
DJNZ R1, LOOP2 ; Decrement R1 and jump if not zero
DJNZ R2, LOOP1 ; Decrement R2 and jump if not zero
RET ; Return from subroutine
3
RESULT:
Thus, the given 8051 Assembly Language experiments using simulator is verified.
4
EX.NO: 2
TEST DATA TRANSFER BETWEEN REGISTERS AND
DATE: MEMORY
AIM:
To test data transfer between registers and memory.
STEPS:
1. Set up your 8051 simulator or hardware environment.
2. Create a new 8051 assembly language project in your IDE (e.g., Keil uVision).
3. Paste the code provided above into your assembly file (e.g., test_data_transfer.asm).
4. Assemble the code to generate the HEX file.
5. Configure the simulator or hardware to simulate or execute the code.
6. Run the program and observe the data transfer between registers and memory.
PROGRAM:
ORG 0x0000 Start address of the program
MOV R0, #0x55 ; Load data 0x55 into register R0
MOV R1, R0 ; Move data from R0 to R1
; Store data from R1 to memory location 0x2000
MOV A, R1 ; Move data from R1 to accumulator (A)
MOV @R0, A ; Store data in accumulator to the memory location pointed by R0
; Read data back from memory and store it in R2
MOV R0, #0x20 ; Set R0 to point to memory location 0x2000
MOV A, @R0 ; Move data from memory to accumulator (A)
MOV R2, A ; Store data from accumulator to R2
; Infinite loop for verification
LOOP:
SJMP LOOP ; Stay in an infinite loop
END ; End of the program
5
RESULT:
Thus, the given test data transfer between registers and memory is verified.
6
EX.NO: 3
PERFORM ALU OPERATIONS
DATE:
STEPS:
1. Download and install the 8051 simulator.
2. Open the assembly language program in the simulator.
3. Set the simulator to run in "step" mode.
4. Click the "run" button.
5. The simulator will step through the program one line at a time.
6. When the program reaches the line that loads the operands into the registers, you can inspect the
values of the registers by clicking on the "registers" tab. you should see that the value of register a is 10h
and the value of register b is 20h.
7. When the program reaches the line that performs the ALU operation, the simulator will perform the
addition and store the result in register a. you can verify the result by inspecting the value of register a.
8. When the program reaches the line that checks the result, the simulator will compare the value of
register a to 30h. If the result is not equal to 30h, the program will loop back to the beginning.
9. Continue stepping through the program until it reaches the end.
PROGRAM :
; ADDITION
ORG 0000H ; Initialize the stack pointer
MOV SP, #07FH ; Start the experiment
; SUBTRACTION
MOV A, #25H
MOV B, #10H ; Initialize B for subtraction
SUBB A, B
MOV 41H, A ; Store the result in memory location 41H
7
; MULTIPLICATION
ORG 0030H ; Set the address for the multiplication routine
MOV A, #05H
MOV B, #02H
MUL AB
MOV R1, A
MOV R0, B
; DIVISION
MOV A, #25H
MOV B, #12H
DIV AB
MOV 44H, A
MOV 45H, B
; AND OPERATION
MOV A, #25H
MOV B, #12H
ANL A, B
MOV 46, A
; OR OPERATION
MOV A, #25H
MOV B, #12H
ORL A, B
MOV 47, A
8
9
RESULT:
Thus, the given perform ALU operations is executed.
10
EX.NO: 4
WRITE BASIC AND ARITHMETIC PROGRAMS USING
DATE: EMBEDDED C
AIM:
To write basic programs using Embedded C to understand the fundamental concepts of programming
microcontrollers
APPARATUS REQUIRED:
1. Personal Computer
2. Keil u5 software
3. Proteus software
THEORY:
A basic theory for programming LED blink using Embedded C involves understanding the fundamental
structure of the language and the hardware interfacing. Embedded C, being a subset of C, relies on simple
syntax and commands tailored for microcontrollers. The basic structure of an LED blink program involves
initializing the necessary pins as output, setting up a loop to toggle the state of the LED, and adding a delay
to control the blinking rate. In arithmetic operations, variables are declared to hold values, and arithmetic
operators like addition, subtraction, multiplication, and division are used to perform calculations. For
instance, variables can be incremented or decremented to control loop iterations or manipulate LED blink
frequency. By combining these elements, an LED blink program in Embedded C can be created, providing
a hands-on introduction to both basic programming concepts and practical hardware interaction.
PROCEDURE:
1. Connect the circuit as per circuit diagram in Proteus software.
2. Open the keil u5 software and create new file and write the Embedded C Program.
3. Compile the program and create the hex file.
4. Upload the hex file and verify the output in proteus software.
11
CIRCUIT DIAGRAM:
PROGRAM:
#include <REGX51.H> // Include the header file for AT89C51
RESULT:
Successfully created a Basic Program using Embedded C to blink an LED. Arithmetic operations
incorporated for LED pattern modulation
13
EX.NO: 5
INTRODUCTION TO ARDUINO PLATFORM AND
DATE: PROGRAMMING
Aim:
The aim of this experiment is to introduce participants to the Arduino platform and
programming environment.
What is Arduino?
Arduino is a software as well as hardware platform that helps in making electronic
projects. It is an open source platform and has a variety of controllers and
microprocessors. There are various types of Arduino boards used for various purposes.
The Arduino is a single circuit board, which consists of different interfaces or parts. The
board consists of the set of digital and analog pins that are used to connect various devices
and components, which we want to use for the functioning of the electronic devices.
MostoftheArduinoconsistsof14digitalI/O pins.
The analog pins in Arduino are mostly useful for fine-grained control. The pins in the
Arduino board are arranged in a specific pattern. The other devices on the Arduino board
are USB port, small components (voltage regulator or oscillator), microcontroller, power
connector, etc.
Features:
The Features of Arduino are listed below:
Arduino programming is a simplified version of C++, which makes the learning process e a s y.
The Arduino IDE is used to control the functions of board. It further
sends the set of specifications to the microcontroller.
Arduino do is not need an extra board or piece to load new code.
Arduino can read analog and digital input signals.
The hardware and software platform is easy to use and implement.
14
Arduino UNO board:
15
Let's discuss each component in detail:
o ATmega328Microcontroller-ItisasinglechipMicrocontrolleroftheATmel family.
The processor code inside it is of 8-bit. It combines Memory (SRAM, EEPROM,
and Flash), Analog to Digital Converter, SPI serial ports, I/O lines, registers,
timer, external and internal interrupts, and oscillator.
o ICSP pin –The In-Circuit Serial Programming pin allows the user to program
using the firmware of the Arduino board.
o Power LED Indicator-The ON status of LED shows the power is activated.
When the power is OFF, the LED will not light up.
o Digital I/O pins- The digital pins have the value HIGH or LOW. The pins
numbered from D0 to D13 are digital pins.
o TXandRXLED's-Thesuccessfulflowofdataisrepresentedbythelightingof these LED's.
o AREF- The Analog Reference (AREF) pin is used to feed a reference voltage to
the Arduino UNO board from the external power supply.
o Reset button-It is used to add a Reset button to the connection.
o USB-It allows the board to connect to the computer. It is essential for the
programming of the Arduino UNO board.
o Crystal Oscillator-The Crystal oscillator has a frequency of 16MHz,
which makes the Arduino UNO a powerful board.
o VoltageRegulator-Thevoltageregulatorconvertstheinputvoltageto5V.
o GND-Ground pins. The ground pin acts as a pin with zero voltage.
o Vin-It is the input voltage.
o Analog Pins- The pins numbered from A0 to A5 are analog pins. The function of
Analogpinsistoreadtheanalogsensorusedintheconnection.Itcanalsoactas GPIO
(General Purpose Input Output) pins.
Arduino Download:
The Arduino software(IDE)is open-source software. We are required to write the code
and upload the code to the board to perform some task.
TheArduinoIDEsoftwarecanbeusedwithanytypeofArduinoboards.Thesoftwareis
available for various operating system such as, Windows, Linux, and Mac OS X.
16
The steps to download the Arduino software are listed below:
Or
OpentheURLhttps://www.arduino.cc/en/Main/Soft
ware
17
3. Scroll the screen a little, as shown below:
18
6. The downloading process will start. The downloading file will look like the below image:
12. The window specifying the location of the installed folder will appear
19
Click on the 'Install' button .It is shown below:
14. Now, we have to accept the security for the installation. We are required to
accept the security Installation three times.
20
16.Again,clickonthe'Install'button.Itisshownbelow:
16. The installation process is now completed. The window will now appear as:
The Arduino IDE software will appear on your desktop, as shown below:
19. The Arduino IDE environment is written in the programming language named
as Java. So, we need to allow access to the Java Platform.
21
As soon we open the Arduino software, a license window will appear, as shown below:
We can view the port of the attached hardware ArduinoIDE to our computer.
22
1. GototheFileManagerandright-clickontheThisPCoption,asshownbelow:
2. ClickontheManage
3. First,weneedtoconnecttheArduinoboardtoourcomputer.
23
4. Awindowwillappear,asshownbelow:
5. ClickontheDeviceManager
6. UnderthePORToption,wecanseetheportsoftheconnectedhardware.
ArduinoIDE:
The Arduino IDE is an open-source software, which is used to write and upload code to
the Arduinoboards.TheIDEapplicationissuitablefordifferentoperatingsystemssuch as
Windows,MacOS X,andLinux. It supports the programming languages C and C++.
Here, IDE stands for Integrated Development Environment.
The program or code written in the Arduino IDE is often called as sketching. We need to
connect the Genuino and Arduino board with the IDE to upload the sketch written in the
Arduino IDE software. The sketch is saved with the extension '.ino.'
TheArduinoIDEwillappearas:
Toolbar Button
The icons displayed on the toolbar are New, Open, Save, Upload, and
24
Upload
The Upload button compiles and runs our code written on the screen. It further uploads the code to the
connected board. Before uploading the sketch, we need to make sure that the correct board and ports are
selected.
We also need a USB connection to connect the board and the computer. Once all the above measures are
done, click on the Upload button present on the toolbar.
The latest Arduino boards can be reset automatically before beginning with Upload. In the older boards,
we need to press the Reset button present on it. As soon as the uploading is done successfully, we
can notice the blink of the Tx and Rx LED.
If the uploading is failed, it will display the message in the error window.
We do not require any additional hardware to upload our sketch using the Arduino Bootloader. A
Bootloader is defined as a small program, which is loaded in the microcontroller present on the board.
The LED will blink on PIN 13.
Open
The Open button is used to open the already created file. The selected file will be opened in the current
window.
Save
New
Verify
TheVerifybuttonisusedtocheckthecompilationerrorofthesketchorthewrittencode.
SerialMonitor
The serial monitor button is present on the right corner of the toolbar. It opens the serialmonitor.
25
It is shown below:
When we connect the serial monitor, the board will reset on the operating system
Windows, Linux, and Mac OS X. If we want to process the control characters in our
sketch, we need
touseanexternalterminalprogram.TheterminalprogramshouldbeconnectedtotheCOM
port, which will be assigned when we connect the board to the computer.
Menu Bar
o File
When we click on the File button on the Menu bar, a drop-down list will appear. It is
shown below:
New
The New button opens the new window. It does not remove the sketch which is already present.
Open It allows opening the sketch, which can be browsed from the folders
Open Recent
The Open Recent button contains the list of there cent sketches.
26
Sketchbook
It stores the current sketches created in the Arduino IDE software. It opens the selected
sketch or code in a new editor at an instance.
Examples
It shows the different examples of small projects for a better understanding of the IDE
and the board. The IDE provides examples of self-practice.
EXAMPLE:
LEDBLINK
27
PROGRAM:
voidsetup()
{
pinMode(LED_BUILTIN,OUTPUT);
}
voidloop()
{
// turn the LED on (HIGH is the
voltage level)
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
//Waitfor1000millisecon
d(s)
//turntheLEDoffbymakingthevoltageL
OW digitalWrite(LED_BUILTIN,
LOW); delay(1000);
//Waitfor1000millisecon
d(s)
}
Result:
Understand and apply fundamental programming concepts in the context of Arduino
programming.
28
EX.NO: 6(A)
Interfacing Arduino to Zigbee module
DATE:
AIM:
To write a program to control an LED using a Zigbee module.
5 Zigbee Module 2
PROCEDURE
After configuring the XBee module, we need to interface it with Arduino. Two
Zigbee modules can communicate with each other if both are of the same type. To establish
communication between the modules, connect one module to an Arduino and the other
module to either a sensor, microcontroller, or computer. You should set the configuration
of both modules.
29
Zigbee interfacing with Arduino
The figure above shows the connection diagram of the module with Arduino. Remember, your module
should have regulated 5 volts and 3.3 volts. If you use the Adafruit XBee Adapter, it has both voltage
levels. Otherwise, you will need to use a separate power supply. In the above circuit, the TX and RX
pins of the Zigbee and Arduino connect to each other. The Arduino will send instructions to the Zigbee,
and the Zigbee will respond accordingly. Similarly, the Zigbee receives instructions from other Zigbees
to which it has an address. After receiving instructions or data from other Zigbees, it sends the data to the
Arduino through the serial pins, as shown in the connection diagram. Similarly, another module can be
connected to one more Arduino or computer. The same connection diagram is used for another Zigbee
and Arduino pair.
For demonstration, create two circuits, as shown above, and we will use those two to communicate with
each other.
Code
To establish serial communication between two XBee modules connected to two separate Arduino
boards using UART (Serial) communication, we can use the following example code for both the
transmitter and receiver. In this example, we’ll assume that one Arduino is the transmitter, and the other
is the receiver.
30
Xbee Arduino Transmitter Code
void setup() {
Serial.begin(9600); // Set the baud rate to match your XBee configuration
}
void loop() {
String message = "Hello, XBee!"; // Message to send
Serial.println(message); // Send the message over serial
delay(1000); // Wait for a moment before sending the next message
}
void setup() {
Serial.begin(9600); // Set the baud rate to match your XBee configuration
}
void loop() {
if (Serial.available() > 0) {
String receivedMessage = Serial.readStringUntil('\n'); // Read the incoming message
Serial.print("Received: ");
Serial.println(receivedMessage); // Print the received message
}
}
RESULT
In conclusion, Zigbee technology provides a reliable and efficient wireless communication solution for a
wide range of applications. It offers the ability to create mesh networks and connect and control smart
devices within homes, buildings, and industrial settings.
31
EX.NO: 6(B)
INTERFACING ARDUINO TO GSM MODULE
DATE:
Aim:
The aim of this experiment is to establish communication between an Arduino
microcontroller and a GSM SIM900A Module in order to enable the Arduino to send
and receive SMS messages.
Apparatus&SoftwareRequired:
1. ArduinoMicrocontroller
2. ArduinoIDESoftware
3. GSMSIM900AModule
4. ConnectingWires
5. ProgrammingCable
6. SIMCard(2G)
Theory:
The GSM SIM900A Module is a widely used GSM modem for various communication
applications. It allows devices to connect to the GSM network for sending and receiving
messages, making calls, and accessing the internet. The Arduino microcontroller will
serve as the interface between the SIM900A Module and other devices.
The basic theory involves connecting the SIM900A Module to the Arduino
microcontroller using serial communication.The ArduinowillsendAT commands to the
SIM900AModule via UART (Universal Asynchronous Receiver/Transmitter) to perform
various tasks such as initializing the module, sending SMS messages, and handling
incoming messages.
To achieve this, the following steps will be performed:
Hardware setup: Connect the SIM900A Module to the Arduino microcontroller via serial
communication pins.
Software setup: Write Arduino code to send AT commands to the SIM900A Module and
handle responses.
Initialization: Initialize the SIM900A Module by sending appropriate AT commands to
set up communication parameters.
Sending SMS: Use AT commands to compose and send SMS messages from the Arduino
to specified phone numbers.
Receiving SMS: Configure the SIM900A Module to notify the Arduino when new SMS
messages are received and read incoming messages.
32
Procedure:
1. Connect the Circuit as per Circuit Diagram.
2. Insert your SIMcard to GSM module and lock it.
3. Power up your gsm by connecting it to Arduino's 5Vand GND.
4. Now wait for some time (say 1 minute) and see the blinking rate of ‘status
LED’ or ‘network LED’ .
5. Once the connection is established successfully, the status/network LED
will blink continuously every 3 seconds.
6. Open the ArduinoIDE and Create the New File and Write the Program and Save it.
7. Upload the Program and Received the SMS.
Circuit Diagram:
33
Program:
#include
<SoftwareSerial.h>Software
msg; charcall;
voidsetup()
{
mySerial.begin(9600);// Setting the baud rate of GSM
Module Serial.begin(9600);
//SettingthebaudrateofSerialMonitor(Ar
Serial.println("Enter
characterforcontroloption:");
Serial.println("e:toredial");
Serial.println();
delay(100);
}
voidloop()
{
if (Serial.available()>0)
34
switch(Serial.read())
{
case 's':
SendMessage();
break;
case'c':
MakeCall();
break;
case 'h':
HangupCall();
break;
case 'e':
RedialCall();
break;
case 'i':
ReceiveCall();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
voidSendMessage()
{
mySerial.println("AT+CMGF=1");
//SetstheGSMModuleinTextMode delay(1000);
mySerial.println("AT+CMGS=\"+91XXXXXXXXX\"\r");
//Replacexwithmobilenu
mber delay(1000);
35
mySerial.println("sim900a sms");
//TheSMStextyouwanttos
end delay(100);
mySerial.println((char)26);
//ASCIIcodeofCTRL
+Z delay(1000);
voidReceiveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0");//ATCommandtorecievealiveSMS
delay(1000);
if(mySerial.available()>0)
{
msg=mySerial.read();
Serial.print(msg);
}
}
voidMakeCall()
{
mySerial.println("ATD+91XXXXXXXXX;");//ATDxxxxxxxxxx;--
watchouthereforsemicolon at the end!!
Serial.println("Calling");
//printresponseoverserial
port delay(1000);
36
voidHangupCall()
{
mySerial.println("ATH");
Serial.println("HangupCall"
); delay(1000);
}
voidReceiveCall()
{
mySerial.println("ATA");
delay(1000);
{
call=mySerial.read();
Serial.print(call);
}
}
voidRedialCall()
{
mySerial.println("AT
DL");
Serial.println("Rediali
ng"); delay(1000);
}
37
Result:
Successfully implementation of the interfacing between the Arduino microcontroller and
the GSM SIM900A Module.
38
EX.NO: 6(C)
INTERFACING ARDUINO TO BLUETOOTH
DATE: MODULE
Aim:
The aim of this experiment is to interface an Arduino microcontroller with a
Bluetooth module, specifically the HS-05 module.
Apparatus&SoftwareRequired:
1. ArduinoMicrocontroller
2. ArduinoIDESoftware
3. HC-05BluetoothModule
4. ConnectingWires
5. ProgrammingCable
6. SerialBluetoothTerminalApplication
Theory:
The Arduino microcontroller serves as the central processing unit in this setup, responsible
for controlling and coordinating the interaction between various components. The
Bluetooth module, such as the HS-05, enables wireless communication with external
devices, such as smartphones or computers.
To interface the Arduino with the Bluetooth module, certain hardware connections need
to be established. This typically involves connecting the TX (transmit) and RX (receive)
pins of the Bluetooth module to the RX and TX pins of the Arduino, respectively.
Additionally,a voltage divider may be necessary to ensure compatibility between the
voltage levels of the Arduino and the Bluetooth module.
On the software side, the Arduino code must be written to initialize the serial
communication interface and configure the appropriate baud rate to match that of the
Bluetooth module. Once communication is established, the Arduino can send and receive
data packets to and from the Bluetooth module, allowing for wireless data transmission.
39
Procedure:
1. Connect thec ircuit as per circuit diagram.
2. Open the ArduinoIDE and Create the Newfile and Write the program and Saveit.
3. Upload the program for Arduino Microcontroller.
4. To Install the SerialBluetooth Terminal Application in Mobile.
5. Connect the Bluetooth HC-05 and Communicate the messages for Serial
Monitor and Serial Bluetooth Terminal Application.
Circuit Diagram:
Program:
#include<SoftwareSerial.h>
//CreatesoftwareserialobjecttocommunicatewithHC-05
SoftwareSerialmySerial(3,2);//HC-
05Tx&RxisconnectedtoArduino#3
voidsetup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
40
//Begin serial communication with Arduino and HC-05
mySerial.begin(9600);
Serial.println("Initializing...");
Serial.println("Thedevicestarted,nowyoucanpairitwithbluetooth
!");
}
voidloop()
{
if(Serial.available())
{
mySerial.write(Serial.read());//ForwardwhatSerialreceivedtoSoftwareSerialPort
}
if(mySerial.available())
{
Serial.write(mySerial.read());//ForwardwhatSoftwareSerialreceivedtoSerialPort
}
delay(20);
}
Output :
41
Bluetooth Terminal App Output
Result:
Upon successful implementation of the hardware connections and software protocols, the
Arduino microcontroller should be able to communicate with the Bluetooth module
42
EX.NO: 7
INTRODUCTION TO RASPBERRY PI PLATFORM
DATE: AND PYTHON PROGRAMMING
Aim:
Successfully interfaced an IR sensor with a Raspberry Pi, triggering a blinking LED in response to
detect infrared signals.
Theory :
The Raspberry Pi platform, a credit-card sized computer developed by the Raspberry Pi Foundation,
has revolutionized the world of DIY electronics and programming education since its inception.
Powered by its versatility, affordability, and ease of use, the Raspberry Pi has become a cornerstone
for hobbyists, educators, and professionals alike. Its compatibility with various operating systems,
such as Raspbian and Ubuntu, coupled with its GPIO (General Purpose Input/Output) pins, allows
users to interact with the physical world through sensors, motors, and other peripherals. Python
programming language serves as the perfect companion for Raspberry Pi projects, thanks to its
simplicity, readability, and extensive libraries. Whether you're a beginner or an experienced
developer, the combination of Raspberry Pi and Python opens doors to limitless possibilities in home
automation, robotics, Internet of Things (IoT), and beyond.
Steps:
43
Step 3: Put the NOOBS files on the SD card
Procedure
Start by opening a text editor or an integrated development environment (IDE) like
Thonny or IDLE on the Raspberry Pi's desktop environment.
Write your Python code, incorporating necessary libraries/modules for specific
functionalities, GPIO handling, sensors, or other peripherals connected to the Raspberry
Pi.
Ensure the code follows proper indentation and syntax rules of the Python language. Save
the Python file with a ".py" extension in an easily accessible location.
Open the Terminal or Command Line Interface, navigate to the directory containing your
Python file using the 'cd' command, and execute the program using the 'python
filename.py' command. Monitor the program's output or behavior, debug any issues, and
refine the code as needed to achieve the desired functionality or application on the
Raspberry Pi.
44
Example Program (LED Blink)
Output
Result :
Discover the endless possibilities of Raspberry Pi and Python programming, unlocking
innovation one experiment at a time. Harness the power of this dynamic duo to fuel
successful study and exploration in the realm of technology and beyond.
45
EX.NO: 8
INTERFACING SENSORS TO RASPBERRY PI
DATE:
Aim:
The aim of this experiment is to Interface Sensors To Raspberry Pi with IR Sensor.
Apparatus&SoftwareRequired:
Theory:
Interfacing sensors, such as an infrared (IR) sensor, with a Raspberry Pi involves establishing
a
communication link between the sensor and the GPIO (General Purpose Input Output) pins of
the Raspberry Pi. By wiring the IR sensor's output pin to a GPIO pin on the Raspberry Pi and
configuring the Pi to read the sensor's data, real-time input from the sensor can be obtained.
Upon detecting a specific stimulus, like an object within range, the sensor sends a signal to the
Raspberry Pi, triggering an action such as illuminating an LED. This interaction can be
programmed using Python or other suitable languages, where the Raspberry Pi constantly
monitors the sensor's output state. When the sensor detects an object, the Pi activates the
connected LED through another GPIO pin, creating a visual indication of the sensed event.
Procedure:
1. Connect the circuit as per circuit diagram.
2. Open the thony file and Create the Newfile and Write python the program and Saveit.
3. Upload the program for Raspberry Pi.
4. Finally Verify the Output.
46
Circuit Diagram :
import time
sensor_pin = 23
led_pin =
26 # GPIO
setup
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor_pin,
GPIO.IN) GPIO.setup(led_pin,
GPIO.OUT) try:
while True:
if GPIO.input(sensor_pin):
# If no object is near
GPIO.output(led_pin, False)
while
GPIO.input(sensor_pin):
time.sleep(0.2)
47
else:
# If an object is detected
GPIO.output(led_pin,
True) except
KeyboardInterrupt:
GPIO.cleanup()
Output:
Result :
Successfully interfaced an IR sensor with a Raspberry Pi, triggering a blinking LED in
response to detected infrared signals.
48
EX.NO: 9
COMMUNICATE BETWEEN ARDUINO AND
DATE: RASPBERRY PI USING ANY WIRELESS
MEDIUM
Aim :
Enable seamless Arduino-Raspberry Pi communication wirelessly, fostering efficient
data exchange and remote control for diverse IoT applications.
Apparatus Required :
1. Arduino Development Board
2. Raspberry Pi Development Board
3. Led
4. Connecting Cables
5. Arduino IDE (C program)
6. Thony Software (Python)
Theory :
Procedure :
1. Connect the circuit as per circuit diagram.
3. Get Bluetooth MAC address and past the python Program line .
5. Open the serial monitor and type 100 LED is On , type 200 LED is Off.
49
Circuit Diagram :
Arduino (program)
int led=13;
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT)
}
void loop() {
if(Serial.available()){
int
a=Serial.parseInt();
Serial.println(a);
if(a==100)
{
digitalWrite(led,HIGH);
}
if (a==200)
50
{
digitalWrite(led,LOW);
}
}
}
serial
import
time
bluetooth=serial.Serial("/dev/rfcomm7",960
0) while True:
a=input("enter:-")
string='X{0}'.format(a)
bluetooth.write(string.encode("utf-8"))
Result :
Arduino and Raspberry Pi successfully communicate via Bluetooth, enabling LED
control with on/off functionality, demonstrating seamless wireless interaction.
51
EX.NO: 10
SETUP A CLOUD PLATFORM TO LOG THE
DATE: DATA
Aim:
The aim of the experiment is to establish a cloud platform utilizing Arduino Cloud to efficiently log
and manage data, ensuring seamless integration and accessibility for diverse applications.
Apparatus Required :
Esp8266 Microcontroller
DH11 Temperature Sensor
Arduino Cloud Platform
Connecting Wire
Theory :
In establishing a cloud platform to log data from Arduino devices, the architecture would integrate
various components to ensure seamless data transmission, storage, and accessibility. Initially,
Arduino devices equipped with sensors would gather real-time data, which would be transmitted
to a gateway device, possibly employing protocols like MQTT for efficient communication. This
gateway device would then relay the data securely to the cloud platform, leveraging robust
encryption mechanisms to safeguard sensitive information. Within the cloud infrastructure, a
scalable database system, such as MongoDB or Amazon DynamoDB, would efficiently store the
incoming data, organized in a schema optimized for fast retrieval and analysis. Concurrently, a
microservices-based approach would facilitate the development of modular services responsible
for data validation, transformation, and enrichment, ensuring data integrity and usability. A cloud-
native logging solution, such as Elasticsearch combined with Logstash and Kibana (ELK stack),
could be employed for comprehensive log management, enabling real-time monitoring and
analysis of device statuses and data streams. Furthermore, implementing containerization
technologies like Docker alongside orchestration platforms like Kubernetes would enhance the
platform's scalability, resilience, and resource utilization. Lastly, intuitive dashboard interfaces
and RESTful APIs would empower users to interact with and derive insights from the logged data,
fostering innovation and optimization across various domains, from industrial IoT to
environmental monitoring.
Procedure :
52
Circuit Diagram and Pins :
Program :
#include
"thingProperties.h"
#include "DHT.h"
#define DHT pin 3 // D5 on the nodemcu ESP8266
#define DHTTYPE DHT11
DHT dht(DHTpin,DHTTYPE);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is
found delay(1500);
// Defined in thingProperties.h
initProperties();
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
53
dht_sensor_getdata();
}
void onHumidityChange() {
// Do something
void onMsgChange() {
// Do something
}
void dht_sensor_getdata()
{
float hm= dht.readHumidity();
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature();
Serial.print("Temperature
"); Serial.println(temp);
humidity=hm;
temperature=temp;
msg="Temperature = " + String (temperature)+" Humidity = " + String(humidity);
}
Cloud Output :
Result :
54
Result :
Successfully implemented a cloud platform for Arduino data logging, ensuring efficient and
secure storage and access.
55
EX.NO: 11
LOG DATA USING RASPBERRY PI AND UPLOAD
DATE: TO THE CLOUD PLATFORM
Aim:
The aim of the experiment is to collect and log data using Raspberry Pi, then seamlessly upload
it to a cloud platform for real-time analysis and remote access, enhancing data monitoring and
accessibility.
Apparatus Required :
Theory :
The theory behind logging data using Raspberry Pi and uploading it to a cloud platform for gas
sensor monitoring, specifically for detecting gas leakages, involves integrating hardware and
software components to create a comprehensive monitoring system. Utilizing a Raspberry Pi
equipped with a gas sensor, the aim is to continuously monitor the air quality and detect any
abnormal gas concentrations. The Raspberry Pi is programmed to collect sensor data
periodically, process it, and then transmit the data to a cloud platform via an internet connection.
Cloud platforms such as Pushbullet can serve as a centralized hub for receiving, storing, and
visualizing the collected data in real-time, enabling remote monitoring and alerting
functionalities. The experiment aims to demonstrate the feasibility and effectiveness of
leveraging IoT technologies for proactive gas leakage detection, enhancing safety measures in
various environments.
Procedure
1. Connect the Circuit: Set up the circuit according to the provided circuit diagram.
2. Power on the Raspberry Pi and Open Thonny Software
3. Open New File and Write the Program.
4. Save the File as .py
5. Install Required Packages as per the Program.
6. Open Pushbullet and Create a New Account.
7. Click on Profile and Copy the API Key.
8. Paste the API Key into the File Named config.ini.
9. Run the Python Program. You will see the output in the command line and Pushbullet cloud storage.
56
Circuit diagram :
Program :
import time
import RPi.GPIO as GPIO
from pushbullet import
Pushbullet import configparser
# Define the GPIO pins connected to the analog outputs of the gas
sensors gas_pin = 11
# For pushbullet
config = configparser.ConfigParser()
config.read('config.ini')
access_token =
config['Pushbullet']['API_KEY'] pb =
Pushbullet(access_token)
def pulse_counter(channel):
global pulse_count
pulse_count += 1
57
def loop():
try:
while True:
gas_concentration_1 =
read_analog(gas_pin) if
gas_concentration_1 > 0:
print("GAS LEAKAGE DETECTED")
58
pb.push_note("GAS LEAKAGE DETECTED", "Gas leakage
detected!") else:
print("NO GAS LEAKAGE DETECTED")
time.sleep(2) # Adjust this sleep time based on your requirements
except KeyboardInterrupt:
GPIO.cleanup()
file Name:
config.ini
[Pushbullet]
API_KEY = replace your pushbulletapi key
Output :
Result:
Successfully implemented logging data from a gas sensor using Raspberry Pi, uploading it to the
cloud platform for real-time monitoring and analysis.
59
EX.NO: 12
DESIGN AN IOT BASED SYSTEM
DATE:
Aim:
To prepare an experiment on voice control home automation using Arduino.
Components Required
Arduino UNO
HC-05 Bluetooth Module
channel Relay Module(5v)
holders
Bulb
220v Electrical wire with a 2-pin male socket
Sun board Piece
Jumper wires
Nuts & bolts
And a Smartphone
Procedure:
60
Circuit Diagram:
Program:
String voice;
#define relay 12
void setup()
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
int relayVal;
void loop() {
{
61
delay(10); //Delay added to make thing stable
if (c == '#') {break;} //Exit the loop when the # is detected after the word
if (voice.length() > 0) {
Serial.println(voice);
//----------Control Light----------//
digitalWrite(relay, HIGH);
else if(voice == "turn off the light") // To turn OFF the bulb
digitalWrite(relay, LOW);
62
Output:
Result:
Thus the experiment for voice control home automation is done successfully.
63