CS3691-Embedded System and IoT Lab Manual
CS3691-Embedded System and IoT Lab Manual
BONAFIDE CERTIFICATE
EX. PAGE.
NO
DATE TITLE NO
SIGNATURE
3 ALU OPERATIONS
ARITHMETIC PROGRAMS
4 (B)
USING EMBEDDED C
INTRODUCTION TO THE
5 (A)
ARDUINO PLATFORM
INTRODUCTION TO ARDUINO
5 (B)
PROGRAMMING
INTERFACING ARDUINO TO
6 (A)
ZIGBEE MODULE
INTERFACING ARDUINO TO
6 (B)
GSM MODULE
INTERFACING ARDUINO TO
6 (C)
BLUETOOTH MODULE
7 (B)
INTRODUCTION TO PYTHON
PROGRAMMING
8
INTERFACING SENSORS WITH
RASPBERRY PI
COMMUNICATE BETWEEN
9 ARDUINO AND
DATE RASPBERRY PI
10
CLOUD PLATFORM TO LOG
THE DATA
DESIGN AN IOT-BASED
12
SYSTEM
EXP NO: 1
8051 ASSEMBLY LANGUAGE PROGRAM USING KEIL
DATE : SIMULATOR
AIM:
To write 8051 Assembly Language Program for an 8-bit addition using Keil simulator and
execute it.
SOFTWARE REQUIRED:
A simulator is software that will execute the program and show the results exactly to the
program running on the hardware, if the programmer finds any errors in the program while
simulating the program in the simulator, he can change the program and re-simulate the code and get
the expected result, before going to the hardware testing. The programmer can confidently dump the
program in the hardware when he simulates his program in the simulator and gets the expected
results.
8051 controller is a most popular 8-bit controller which is used in a large number of
embedded applications and many programmers write programs according to their application. So
testing their programs in the software simulators is a way. Simulators will help the programmer to
understand the errors easily and the time taken for the testing is also decreased.
These simulators are very useful for students because they do need not to build the complete
hardware for testing their program and validate their program very easily in an interactive way.
2. EDSIM 51: This is a virtual 8051 interfaced with virtual peripherals like 7 segment display,
motor, keypad, UART etc. This simulator is exclusively for students developed by James Rogers,.
The features of this simulator are
Have virtual peripherals like ADC, DAC with scope to display, comparator etc.
Supports only assembly language
IDE is completely written in JAVA and supports all the OS.
Completely free and with user guide, examples, etc.
You can download this simulator from the https://www.edsim51.com/index.html.
3. 8051 IDE: This simulation software is exclusively for the Windows operating system (98/xp).
The features of this simulator are
Text editor, assembler, and software simulate in one single program.
Has facilities like Breakpoint setter, execute to break point, predefined simulator watch
window, etc.
It is available in both free version and paid version.
You can download this tool from https://www.acebus.com/win8051.htm
4. 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.
After saving the file, a new window will pop up asking you to select your microcontroller.
As discussed, we are using AT89C51/AT89C51ED2/AT89C52, so select this controller under the
Microchip section (as Atmel is now a part of Microchip).
Select ‘Yes’ in the next pop-up, as we do not need this file in our project.
From here, we need to create a file where we can write our C code. Navigate to File —> New.
Once the file is created, save it with .c extension in the same project folder.
Next, we have to add that .c or .asm file to our project workspace. Select Add Existing Files and
then select the created .c or .asm file to get it added.
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create New Project Select Device for
Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of simulation by clicking Run or step run.8.
PROGRAM:
ORG 0000H
CLR C
MOV A, #20H
ADD A, #21H
MOV R0, A
END
OUTPUT:
RESULT:
Thus, write 8051 Assembly Language Program for an 8-bit addition using Keil simulator
and executed successfully
EXP NO: 2
TEST DATA TRANSFER BETWEEN REGISTERS AND
DATE: MEMORY
AIM:
To write and execute an Assembly language program to transfer data between registers and
memory.
SOFTWARE REQUIRED:
PROCEDURE
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create a New Project Select Device for
the Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.
PROGRAM:
TYPE-I:
ORG 0000H
CLR C
MOV R0, #55H
MOV R1, #6FH
MOV A, R0
MOV 30H, A
MOV A, R1
MOV 31H, A
END
OUTPUT:
BEFORE EXECUTION:
AFTER EXECUTION:
PROGRAM:
TYPE-II:
ORG 0000H
CLR C
MOV R0, #30H
MOV R1, #40H
MOV R7, #06H
BACK: MOV A, @R0
MOV @R1, A
INC R0
INC R1
DJNZ R7, BACK
END
OUTPUT:
RESULT:
Thus, write and execute an Assembly language program to transfer data between registers
and memory was verified and executed successfully.
EXP NO: 3
ALU OPERATIONS
DATE:
AIM:
To write and execute the ALU program using the Keil simulator.
PROCEDURE
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create New Project Select Device for
Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of simulation by clicking Run or step run.
PROGRAM:
ORG 0000H
CLR C
//ADDITION
MOV A, #20H
ADD A, #21H
MOV 41H, A
//SUBTRACTION
MOV A, #20H
SUBB A, #18H
MOV 42H, A
//MULTIPLICATION
MOV A, #03H
MOV B, #04H
MUL AB
MOV 43H, A
//DIVISION
MOV A, #95H
MOV B, #10H
DIV AB
MOV 44H, A
MOV 45H, B
//AND
MOV A, #25H MOV
B, #12H
ANL A, B
MOV 46H, A
//OR
MOV A, #25H
MOV B, #15H
ORL A, B
MOV 47H, A
//XOR
MOV A, #45H
MOV B, #67H
XRL A, B
MOV 48H, A
//NOT
MOV A, #45H
CPL A
MOV 49H, A
END
OUTPUT:
BEFORE:
AFTER:
RESULT:
Thus, write and execute the ALU program using the Keil simulator was executed
successfully.
EXP NO: 4 (A)
WRITE BASIC PROGRAMS USING EMBEDDED C
DATE :
AIM:
To write a basic embedded C program to control a port 0 pin 0 connected to an 8051-
microcontroller using a Keil simulator.
SOFTWARE REQUIRED:
PROCEDURE
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create a New Project Select Device for
the Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.
PROGRAM:
#include<REG51.h>
int i,j;
sbit LED = P2^0;
void main() {
while(1) {
LED = 0;
for(j=0;j<10000;j++);
LED = 1;
for(j=0;j<10000;j++);
}
}
OUTPUT:
LED OFF
LED ON
RESULT:
Thus, write a basic embedded C program to control a port 0 pin 0 connected to an 8051-
microcontroller using a Keil simulator was verified.
EXP NO: 4 (B)
ARITHMETIC PROGRAMS USING EMBEDDED C
DATE :
AIM:
To write an embedded C program for addition, subtraction, multiplication, and division using
the Keil simulator.
SOFTWARE REQUIRED:
PROCEDURE
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project and Create New Project Select Device for
Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with the .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.
PROGRAM:
#include<REG51.H>
unsigned char a, b; void
main()
{
a=0x10;
b=0x04;
P0=a-b;
P1=a+b;
P2=a*b;
P3=a/b;
while(1);
OUTPUT:
Port P0 = 0C
Port P1 = 14
Port P2 = 40
Port P3 = 04
RESULT:
Thus, write an embedded C program for addition, subtraction, multiplication, and division
using the Keil simulator the output was verified and executed successfully.
EXP NO: 5 (A)
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 ATmega328 Microcontroller
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.
TYPES OF ARDUINO BOARDS
1) Arduino UNO
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 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 the most used and of standard form from the list of all available 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 miniUSB. The Arduino Nano includes an I/O pin set of 14 digital pins
and 8 analog pins. It also includes 6 Power pins and 2 Reset pins.
3) Arduino Mega
The Arduino Mega is based on the ATmega2560 Microcontroller. The ATmega2560 is an 8-bit
microcontroller. We need a simple USB cable to connect to the computer and the AC to DC adapter
or battery to get started with it. It has the advantage of working with more memory space. The
Arduino Mega includes 54 I/O digital pins and 16 Analog Input/Output (I/O), ICSP header, a reset
button, 4 UART (Universal Asynchronous Receiver/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. The
7 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, and
a 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 based
on 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.
6) Arduino Due
The Arduino Due is based on the 32-bit ARM core. It is the first Arduino board that has been
developed based on the ARM Microcontroller. It consists of 54 Digital Input/Output pins and 12
Analog pins. The Microcontroller present on the board is the Atmel SAM3X8E ARM Cortex-M3
CPU. It has two ports, namely, a native USB port and a Programming port. The micro side of the
USB cable should be attached to the programming port.
7) Arduino Lilypad
The Arduino LilyPad was initially created for wearable projects and e-textiles. It is based on the
ATmega168 Microcontroller. The functionality of Lilypad is the same as other Arduino Boards. It is
a round, lightweight board with a minimal number of components to keep the size of the board small.
The Arduino Lilypad board was designed by Sparkfun and Leah. It was developed by Leah Buechley.
It has 9 digital I/O pins.
8) Arduino Bluetooth
The Arduino Bluetooth board is based on ATmega168 Microcontroller. It is also named as Arduino
BT board. The components present on the board are 16 digital pins, 6 analog pins, reset button,
16MHz crystal oscillator, ICSP header, and screw terminals. The screw terminals are used for power.
The Arduino Bluetooth Microcontroller board can be programmed over the Bluetooth as a wireless
connection.
9) Arduino Diecimila
The Arduino Diecimila is also based on the ATmeg628 Microcontroller. The board consists of 6
analog pin inputs, 14 digital Input/Output pins, a USB connector, a power jack, an ICSP (In-Circuit
Serial Programming) header, and a reset button. We can connect the board to the computer using the
USB and can power on the board with the help of an AC to DC adapter. The Diecimila was initially
developed to mark the 10000 delivered boards of Arduino. Here, Diecimila means 10,000 in Italian.
SDA: It stands for Serial Data. It is a line used by the slave and master to send and receive data. It is called
as a data line, while SCL is called as a clock line.
SCL: It stands for Serial Clock. It is defined as the line that carries the clock data. It is used to synchronize
the transfer of data between the two devices. The Serial Clock is generated by the device and it is called as
master.
SPI: It stands for Serial Peripheral Interface. It is popularly used by the microcontrollers to communicate
with one or more peripheral devices quickly. It uses conductors for data receiving, data sending,
synchronization, and device selection (for communication).
MOSI: It stands for Master Output/ Slave Input. The MOSI and SCK are driven by the Master.
SS: It stands for Slave Select. It is the Slave Select line, which is used by the master. It acts as the enable line.
I2C: It is the two-wire serial communication protocol. It stands for Inter Integrated Circuits. The I2C is a serial
communication protocol that uses SCL (Serial Clock) and SDA (Serial Data) to receive and send data between
two devices.
3.3V and 5V are the operating voltages of the board.
INTRODUCTION TO ARDUINO IDE 2.0:
The Arduino IDE 2.0 is an open-source project, currently in its beta-phase. It is a big step from it's
sturdy predecessor, Arduino IDE 2.0, and comes with revamped UI, improved board & library
manger, autocomplete feature and much more.
In this tutorial, we will go through step by step, how to download and install the software.
Download the editor
Downloading the Arduino IDE 2.0 is done through the Arduino Software page. Here you will also
find information on the other editors available to use.
Requirements
• Windows - Win 10 and newer, 64 bits
• Linux - 64 bits
• Mac OS X - Version 10.14: "Mojave" or newer, 64 bits
Installation
Windows
Download URL: https://www.arduino.cc/en/software
To install the Arduino IDE 2.0 on a Windows computer, simply run the file downloaded from the
software page.
Follow the instructions in the installation guide. The installation may take several minutes.
You can now use the Arduino IDE 2.0 on your windows computer!
How to use the board manager with the Arduino IDE 2.0
The board manager is a great tool for installing the necessary cores to use your Arduino boards. In
this quick tutorial, we will take a look at how to install one, and choosing the right core for your
board!
Requirements
• Arduino IDE 2.0 installed.
Why use the board manager?
The board manager is a tool that is used to install different cores on your local computer. So, what is
a core, and why is it necessary that I install one?
Simply explained, a core is written and designed for specific microcontrollers. As Arduino have
several different types of boards, they also have different type of microcontrollers.
For example, an Arduino UNO has an ATmega328P, which uses the AVR core, while an Arduino
Nano 33 IoT has a SAMD21 microcontroller, where we need to use the SAMD core.
In conclusion, to use a specific board, we need to install a specific core.
Installing a core
Installing a core is quick and easy, but let's take a look at what we need to do.
1. Open the Arduino IDE 2.0.
2. With the editor open, let's take a look at the left column. Here, we can see a couple of icons.
Let's click the on the "computer chip" icon.
1. A list will now appear of all available cores. Now let's say we are using an Nano 33 IoT board,
and we want to install the core. Simply enter the name in the search field, and the right core
(SAMD) will appear, where the Nano 33 IoT features in the description. Click on the
"INSTALL" button.
4. This will begin an installation process, which in some cases may take several minutes.
5. When it is finished, we can take a look at the core in the boards manager column, where it
should say "INSTALLED".
You have now successfully downloaded and installed a core on your machine, and you can start using
your Arduino board!
3. Click on the verify tool (checkmark). Since we are verifying an empty sketch, we can be sure
it is going to compile. After a few seconds, we can see the result of the action in the console
(black box in the bottom).
1. Now we know that our code is compiled, and that it is working. Now, before we can upload
the code to our board, we will first need to select the board that we are using. We can do this
by navigating to Tools > Port > {Board}. The board(s) that are connected to your computer
should appear here, and we need to select it by clicking it. In this case, our board is displayed
as COM44 (Arduino UNO).
5. With the board selected, we are good to go! Click on the upload button, and it will start
uploading the sketch to the board.
6. When it is finished, it will notify you in the console log. Of course, sometimes there are some
complications when uploading, and these errors will be listed here as well.
you
have now uploaded a sketch to your Arduino board!
How to install and use a library with the Arduino IDE 2.0
A large part of the Arduino programming experience is the use of libraries. Thousands of libraries
can be found online, and the best-documented ones can be found and installed directly through the
editor. In this tutorial, we will go through how to install a library using the library manager in the
Arduino IDE 2.0. We will also show how to access examples from a library that you have installed.
Requirements
• Arduino IDE 2.0 installed.
Why uses libraries?
Libraries are incredibly useful when creating a project of any type. They make our development
experience much smoother, and there almost an infinite amount out there. They are used to interface
with many different sensors, RTCs, Wi-Fi modules, RGB matrices and of course with other
components on your board.
Arduino has many official libraries, but the real heroes are the Arduino community, who develop,
maintain and improve their libraries on a regular basis.
Installing a library
Installing a library is quick and easy, but let's take a look at what we need to do.
1. Open the Arduino IDE 2.0.
2. With the editor open, let's take a look at the left column. Here, we can see a couple of icons.
Let's click the on the "library" icon.
3. A list will now appear of all available libraries, where we can also search for the library we
want to use. In this example, we are going to install the RTCZero library. Click on the
"INSTALL" button to install the library.
4. This process should not take too long, but allow up to a minute to install it.
5. When it is finished, we can take a look at the library in the library manager column, where it
should say "INSTALLED".
You have now successfully downloaded and installed a library on your machine.
Including a library
To use a library, you first need to include the library at the top of the sketch.
Almost all libraries come with already made examples that you can use. These are accessible through
File > Examples > {Library} > {Example}. In this example, we are choosing the RTCZero >
SimpleRTC.
The chosen example will now open up in a new window, and you can start using it however you want
to.
RESULT:
Thus, study the basics of Arduino Uno board and Arduino IDE 2.0 software was successfully
installed.
EXP NO: 5 (B)
INTRODUCTION TO ARDUINO PROGRAMMING
DATE :
AIM:
To explain and develop an embedded application (Blinking LED) using Arduino Uno.
SOFTWAREREQUIREMENTS
Arduino IDE software
HARDWAREREQUIREMENTS
Arduino UNO
Breadboard
Jumper wires
Resistor
LED lights
USB cable
PROCEDURE:
STEP1: Download and install Arduino IDE software
STEP2:Connect Arduino UNO to breadboard Pin 6, Pin7, Pin8.
STEP3:3Resistorareconnectedinbreadboard 3 LED lights are connected in breadboard
STEP 4: Write a program
STEP5:Debug the program. You will see all LED lights are on
PROGRAM:
#define LED 13
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000); }
OUTPUT:
RESULT:
Thus, write and execute different Arduino programming for analog, digital signals and serial
communication was executed successfully
EX.NO: 06 (A) INTERFACING ARDUINO TO ZIGBEE MODULE
DATE:
AIM:
To write a program in interface ZigBee module with Arduino Uno board.
HARDWAREREQUIREMENTS
1xArduino Uno
2xXBeeProS2C modules (any other model can be used)
1xXbeeexplorerboard(optional)
1xXbeeBreakoutboard(optional)
USB cables
LEDs
SOFTWAREREQUIREMENTS
Arduino IDE
XCTU Software
PROCEDURE:
Connections:
If you are using the Arduino board to connect the transmitter ZigBee with the laptop, connections
will be the same as for programming the ZigBee.
**Step 1:**
Now, click on the search button. This will show you all the RF devices connected with your
laptop. In our case, it will show only one XBee module.
Step2:- Select the Serial port of the Explorer board/Arduino board and click on Next.
Step3:-In the next window, set the USB port parameters as shown below and click on Finish.
Step4:-Select the Discovered device and click on Add selected device. This process will add your
XBee module to XCTU dashboard.
Step5:-Now, you can configure your X Bee module in this window. Use either AT commands or
put the data manually. As you can see, there is R showing on the left panel which means Xbee is
in router mode. We have to make it Coordinator for the transmitter part.
.
Step6:-Choose the Product family of your device which is available on back of XBee module.
Select function set and firmware version as highlighted below and click on Update.
Step 7:-
Now, you have to give ID, MY and DL data to make connection with other XBee.ID
remain same for both the modules. Only MY and DL data interchange i.e. MY for the receiver
XBee becomes DL of the transmitter XBee (coordinator) and DL for the receiver XBee
becomes MY of the transmitter XBee. Make CE as Coordinator and then hit the Write
button. As shown below.
ATDL ATMY ATID
XBee1 coordinator 1234 5678 2244
XBee 2 end device 5678 1234 2244
Step 8:- After writing the above data to the transmitter part, plug out it from the explorer board
and plug it in the second XBee module .Repeat the same process as above only changes are the
DL, MY, and CE. As we will make the second XBee as End device so in CE drop down menu,
select the End device and hit the Write button.
Step9:-Now, our XBee modules are ready to interface with the Arduino board. We will connect
the transmitter XBee to the laptop and receiver XBee with the Arduino board. Then give
commands to the receiver part using laptop.
PROGRAM:
intled=13;
int received=0;
inti;
voidsetup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}
voidloop()
{
if(Serial.available()>0)
{
received=Serial.read();
if(received=='a')
{ digitalWrite(led,HIGH);
delay(2000);
digitalWrite(led, LOW);
}
elseif(received=='b')
{
for(i=0;i<5;i++)
{
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
}
}
}
OUTPUT:
RESULT:
Thus, write a program in interface ZigBee module with Arduino Uno board output was
verified and executed successfully.
EX.NO:06 (B) INTERFACING ARDUINO TO GSM MODULE
DATE:
AIM
To write a program in interface Arduino to GSM module.
HARDWAREREQUIREMENTS
Arduino UNO
2 GSIM
12V Power supply
900 GSM module
Jumper wires
SOFTWAREREQUIREMENTS
Arduino IDE
PROCEDURE:
Step 8: Type 's', the message will send to your mobile and reply to the message is also applicable.
PROGRAM
#include<Software Serial.h>
Software Serial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
Void loop()
{
if (Serial.available() > 0)
{
switch (Serial.read())
{
case 's':
mySerial.println("AT+CMGF=1"); // Sets the GSM Module in Text Mode
delay(1000); // Delay of 1 second
mySerial.println("AT+CMGS=\"+919616288208\"\r"); // Replace x with the mobile
number
delay(1000);
mySerial.println("Technolab creation"); // The SMS text you want to send
delay(100);
mySerial.println((char)26); // ASCII code of CTRL+Z for indicating the end of SMS to the
module
delay(1000);
break;
case 'r':
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
break;
}
}
if (mySerial.available() > 0)
{
Serial.write(mySerial.read());
}
}
OUTPUT :
RESULT:
Thus, write a program in interface Arduino to GSM module output was verified and executed
successfully.
EX.NO:06 (C) INTERFACING ARDUINO TO BLUETOOTH
MODULE
DATE:
AIM:
To write a program to interfacing Arduino and Bluetooth module.
HARDWARE REQUIREMENTS
SOFTWARE REQUIREMENTS
Arduino IDE
PROCEDURE
Step1:Connection
Step 6: Search for a new device. Your Bluetooth module will appear as HC-05, and add it.
Step 8: After making a pairing, you can now program the Arduino and upload a sketch to send or
receive data from the computer.
Step 9: Upload the code.
Step 10: We will use the Software Serial library to make pin D10 & D11 as TX & RX instead of
using the default RX and TX (D0 & D1 on most Arduino boards).
Step 11: LED connected to D13. To blink on/off, by pressing #1 from the PC keyboard, the LED
blinks on. If you press 0, the LED blinks off.
PROGRAM:
#include <SoftwareSerial.h>
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin = 13; // LED on D13 will show blink on/off
int BluetoothData;
// the data given from the computer
void setup()
{
Genotronex.begin(9600);
Genotronex.println("Bluetooth On, please press 1 or 0 to blink LED...");
pinMode(ledpin, OUTPUT);
}
void loop() {
if (Genotronex.available())
{
BluetoothData = Genotronex.read();
if (BluetoothData == '1') {
digitalWrite(ledpin, 1);
Genotronex.println("LED On D13 ON!");
}
if (BluetoothData == '0')
{
digitalWrite(ledpin, 0);
Genotronex.println("LED On D13 Off!");
}
}
delay(100); // prepare for the next data...
}
```
.
OUTPUT
RESULT:
Thus, write a program to interfacing Arduino and Bluetooth module was verified and
executed successfully.
EXP NO: 7 (A)
STUDY OF THE RASPBERRY PI
DATE: PLATFORM
The Raspberry Pi Pico W is a compact and affordable microcontroller board developed by the
Raspberry Pi Foundation. Building upon the success of the Raspberry Pi Pico, the Pico W variant
brings wireless connectivity to the table, making it an even more versatile platform for embedded
projects. In this article, we will provide a comprehensive overview of the Raspberry Pi Pico W,
highlighting its key features and capabilities.
Features:
• RP2040 microcontroller with 2MB of flash memory
• On-board single-band 2.4GHz wireless interfaces (802.11n)
• Micro USB B port for power and data (and for reprogramming the flash)
• 40 pins 21mmx51mm ‘DIP’ style 1mm thick PCB with 0.1″ through-hole pins also with edge
castellations
• Exposes 26 multi-function 3.3V general purpose I/O (GPIO)
• 23 GPIO are digital-only, with three also being ADC-capable
• Can be surface mounted as a module
• 3-pin ARM serial wire debug (SWD) port
• Simple yet highly flexible power supply architecture
• Various options for easily powering the unit from micro-USB, external supplies, or batteries
• High quality, low cost, high availability
• Comprehensive SDK, software examples, and documentation
• Dual-core Cortex M0+ at up to 133MHz
• On-chip PLL allows variable core frequency
• 264kByte multi-bank high-performance SRAM
Raspberry Pi Pico W:
The Raspberry Pi Pico W is based on the RP2040 microcontroller, which was designed by Raspberry
Pi in-house. It combines a powerful ARM Cortex-M0+ processor with built-in Wi-Fi connectivity,
opening up a range of possibilities for IoT projects, remote monitoring, and wireless communication.
The Pico W retains the same form factor as the original Pico, making it compatible with existing Pico
accessories and add-ons.
RP2040 Microcontroller:
At the core of the Raspberry Pi Pico W is the RP2040 microcontroller. It features a dual-core ARM
Cortex-M0+ processor running at 133MHz, providing ample processing power for a wide range of
applications. The microcontroller also includes 264KB of SRAM, which is essential for storing and
manipulating data during runtime. Additionally, the RP2040 incorporates 2MB of onboard flash
memory for program storage, ensuring sufficient space for your code and firmware.
Wireless Connectivity:
The standout feature of the Raspberry Pi Pico W is its built-in wireless connectivity. It includes an
onboard Cypress CYW43455 Wi-Fi chip, which supports dual-band (2.4GHz and 5GHz) Wi-Fi
802.11b/g/n/ac. This allows the Pico W to seamlessly connect to wireless networks, communicate
with other devices, and access online services. The wireless capability opens up new avenues for IoT
projects, remote monitoring and control, and real-time data exchange.
RESULT:
AIM:
To write a program to implement LED blinking application using Raspberry PI.
HARDWAREREQUIREMENTS:
Raspberry Pi3 Model B
5mm LED x 1
1KΩResistor(1/4Watt) x 1
Mini Breadboard x 1
Connecting wires
Miscellaneous(Computer,Ethernetcable,PowerSupplyforRaspberryPietc.)
SOFTWAREREQUIREMENTS:
Vim Editor(Command Line Editor)Login into your Raspberry Pi using SSH
PROCEDURE:
Step1: Connect the LED to the Raspberry Pi.
Step 2: Anode of the LED is connected to the 3.3V supply pin of the Raspberry Pi through the 1KΩ
resistor.
Step 3: The cathode of the LED is connected to GPIO25 (Physical Pin 22). Step 4: To install
the Vim Editor (by default, Raspbian has Vi editor and to get full features of Vim).
Step 5: Enter the following code in the SSH Terminal:
sudo apt-get install vim
Step 6: Now open a blank Python file using Vim editor with the file name being blinkLed.py.
Step 8: Save the blinkLed.py file and close the Vim Editor. To check the code, use the following
command in the SSH Terminal (Putty):
sudo python blinkLed.py
PROGRAM:
#!/usr/bin/env python
import RPi.GPIO as GPIO # RPi.GPIO can be referred to as GPIO from now
import time
ledPin = 22 # pin 22
def setup():
GPIO.setmode(GPIO.BOARD) # GPIO Numbering of Pins
GPIO.setup(ledPin, GPIO.OUT) # Set ledPin as output
GPIO.output(ledPin, GPIO.LOW) # Set ledPin to LOW to turn off the LED
def loop():
while True:
print('LED on')
GPIO.output(ledPin, GPIO.HIGH) # LED on
time.sleep(1.0) # wait for 1 second
print('LED off')
GPIO.output(ledPin, GPIO.LOW) # LED off
time.sleep(1.0) # wait for 1 second
def endprogram():
GPIO.output(ledPin, GPIO.LOW) # LED off
GPIO.cleanup() # Release resources
if __name__ == '__main__':
# Program starts from here
setup()
try:
loop()
except KeyboardInterrupt:
# When 'Ctrl+C' is pressed, the endprogram() will be executed.
endprogram()
OUTPUT:
RESULT:
Thus, write a program to implement LED blinking application using Raspberry PI was
executed successfully.
EXP NO: 8
INTERFACING SENSORS WITH RASPBERRY PI
DATE:
AIM:
To write a program how to interface IR sensor with Raspberry Pi.
HARDWAREREQUIREMENTS
Raspberry Pi
Breadboard
IR sensor
Jumper wires
SOFTWAREREQUIREMENTS
Raspberry pi VNC viewer
PROCEDURE
Step 2: IR sensor, Raspberry Pi OUT- pin 8, GND- pin 39, VCC - pin 2.
PROGRAM :
RESULT:
Thus, write a program how to interface IR sensor with Raspberry Pi was implemented and
executed successfully.
EXP NO: 9
COMMUNICATE BETWEEN ARDUINO AND
DATE: RASPBERRY PI
AIM:
To Write a program to wireless Communication between Arduino &RaspberryPi using LoRa
Module SX1278.
HARDWAREREQUIREMENTS:
RaspberryPi 4
Arduino Uno
SX1278433MHzLoRaTransmitter-ReceiverModule
DHT11
SOFTWARE REQUIREMENTS:
Cayene IoT platform Raspberry PI
PROCEDURE:
GND GND
NSS D10
DIO0 D2
SCK D13
MISO D12
MOSI D11
RST D9
DHT11Sensor ArduinoUno
VCC 3.3V
GND GND
DATA A0
Step2: Connect Raspberry pi and Module
RaspberryPi Lora –SX1278Module
3.3V 3.3V
Ground Ground
GPIO10 MOSI
GPIO9 MISO
GPIO11 SCK
GPIO8 Nss/Enable
GPIO4 DIO0
GPIO17 DIO1
GPIO18 DIO2
GPIO27 DIO3
GPIO22 RST
sign-in/Signup into your Cayenneac count and then go to the Cayenne dashboard and click on
‘Add new’ and then click on ‘Device/Widget.’
Step6: Upload the Arduino code to the Arduino board and launch the python code in Pi.
Step7: You should see the temperature and humidity values received in pi though the shell window.
PROGRAM:
Python Code (Raspberry Pi):
mqttc = mqtt.Client(client_id=clientid)
mqttc.username_pw_set(username, password=password) mqttc.connect("mqtt.mydevices.com",
port=1883, keepalive=60) mqttc.loop_start()
BOARD.setup()
class LoRaRcvCont(LoRa): def __init__(self,
verbose=False):
super(LoRaRcvCont, self).__init__(verbose)
self.set_mode(MODE.SLEEP)
self.set_dio_mapping([0] * 6)
def start(self):
self.reset_ptr_rx()
self.set_mode(MODE.RXCONT)
while True:
sleep(0.5)
rssi_value = self.get_rssi_value()
status = self.get_modem_status()
sys.stdout.flush()
def on_rx_done(self):
print("\nReceived:")
self.clear_irq_flags(RxDone=1)
payload = self.read_payload(nocheck=True)
data = bytes(payload).decode("utf-8", 'ignore')
print(data)
temp = data[0:4] humidity = data[4:6]
print("Temperature:")
print(temp)
print("Humidity:")
print(humidity)
mqttc.publish(topic_dht11_temp,payload=temp,retain=True)
mqttc.publish(topic_dht11_humidity, payload=humidity, retain=True)
print("Sent to Cayenne")
self.set_mode(MODE.SLEEP)
self.reset_ptr_rx()
self.set_mode(MODE.RXCONT)
try:
lora.start() except
KeyboardInterrupt:
sys.stdout.flush()
print("")
sys.stderr.write("KeyboardInterrupt\n")
finally:
sys.stdout.flush()
print("")
lora.set_mode(MODE.SLEEP)
BOARD.teardown()
```
Arduino Code:
#include <SPI.h>
#include <RH_RF95.h>
#include <DHT.h>
void setup() {
Serial.begin(9600);
dht.begin(); if
(!rf95.init())
Serial.println("Initialization failed");
}
void loop()
{
temp = dht.readTemperature();
hum = dht.readHumidity();
String humidity = String(hum);
String temperature = String(temp);
String data = temperature + humidity;
Serial.print(data);
char d[5];
data.toCharArray(d, 5);
Serial.println("Sending
to rf95_server");
rf95.send(d, sizeof(d));
rf95.waitPacketSent();
delay(400);
}
OUTPUT:
RESULT:
Thus, write a program to wireless Communication between Arduino &RaspberryPi using
LoRa Module SX1278 was executed successfully.
EXP NO: 10
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:
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
Step7: the following query expressions will all find our log:
# Noequalsignor colon:
"This is a warning!"# with equal sign:
jsonPayload.message="Thisisawarning!"#withcolon: jsonPayload.message:"This
is"#Amoreexplicitonewithlogicaloperators: jsonPayload.message = "This is a
warning!"
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)
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
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:
Thus, write a program how logs to Google Cloud Logging and how to check the logs in the Logs
Explorer output was verified and executed successfully.
EXP NO: 11
Log Data using Raspberry PI and upload it to the cloud
DATE: 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:
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.
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
PROGRAM:
import httplib
import urllib
import time
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:
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:
Thus, write a program to log data using Raspberry pi and upload to the cloud platform was
executed successfully.
EXP NO: 12
Design an IOT-based system
DATE:
AIM:
To write a program to develop a commercial IOT application.
HARDWAREREQUIREMENTS:
Node MCUESP8266 Board or Wemos D1 Mini
BME680 Sensor
Connecting Wires
Breadboard
Micro-USB Cable
SOFTWAREREQUIREMENTS:
Arduino IDE tool
PROCEDURE:
Step1: Connect Wemos D1 Mini or ESP8266 & BME680 Sensor.
Connect the BME680 SCL & SDA Pinto D4 & D3ofWemosBoard. Supply the sensor as 3.3V VCC
through 3.3V Pin of Wemos Board.
Step 2: Connect the SDO to GND. Connecting the SDO pin from the BME680 to the GND is
important because the original code was programmed to use the alternative I2 Caddress(0x77).
Access this I2C address from the BME680 sensor by connecting the SDO pin to the Ground.
Certainly, here are the steps with spaces and line breaks for better readability:
Step 4: Go to Tools "Board: Node MCU 1.0 (ESP-12E Module)" ESP8266 Boards (3.0.0) Node
MCU 1.0 (ESP-12E Module).
Step 5: Go to Tools Port "COM10" COM10.
Step 6: Upload your code and see the output in the serial monitor.
Step 7: Setting up the Blynk application in the Google Play Store Blynk.
PROGRAM:
#include "bsec.h"
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "***********************"; // You should get AuthToken in the Blynk App. char
ssid[] = "***********************"; // Your WiFi credentials.
char pass[] = "***********************";
BsecVirtualSensor sensorList[10] = {
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STATIC_IAQ,
BSEC_OUTPUT_CO2_EQUIVALENT,
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY
};
if (iaqSensor.run())
{
// If new data is available
output = String(time_trigger);
output += "," + String(iaqSensor.rawTemperature);
output += ", " + String(iaqSensor.pressure);
output += ", " + String(iaqSensor.rawHumidity);
output += ", " + String(iaqSensor.gasResistance);
output += ", " + String(iaqSensor.iaq); output += ", " +
String(iaqSensor.iaqAccuracy); output += "," +
String(iaqSensor.temperature); output += ", " +
String(iaqSensor.humidity); output += ", " +
String(iaqSensor.staticIaq); output += "," +
String(iaqSensor.co2Equivalent); output += "," +
String(iaqSensor.breathVocEquivalent);
Serial.println(output);
Serial.print("Pressure: ");
Serial.print(iaqSensor.pressure);
Serial.println(" Pa");
Serial.print("Temperature: ");
Serial.print(iaqSensor.temperature);
Serial.println(" *C");
Serial.print("Humidity: ");
Serial.print(iaqSensor.humidity);
Serial.println(" %");
Serial.print("IAQ:");
Serial.print(iaqSensor.iaq);
Serial.println(" PPM");
Serial.print("CO2 Equivalent: ");
Serial.print(iaqSensor.co2Equivalent);
Serial.println(" PPM");
Serial.print("Breath VOC Equivalent: ");
Serial.print(iaqSensor.breathVocEquivalent);
Serial.println(" PPM");
Serial.println();
Blynk.run(); // Initiates Blynk
Blynk.virtualWrite(V1, (iaqSensor.pressure) / 1000); // For Pressure Blynk.virtualWrite(V2,
iaqSensor.temperature); // For Temperature
Blynk.virtualWrite(V3, iaqSensor.humidity); // For Humidity
Blynk.virtualWrite(V4, iaqSensor.iaq); // For Index of Air Quality
Blynk.virtualWrite(V5, iaqSensor.co2Equivalent); // For CO2
Blynk.virtualWrite(V6, iaqSensor.breathVocEquivalent); // For Breath VOC
}
else
{
checkIaqSensorStatus();
}
}
if (iaqSensor.bme680Status != BME680_OK)
{
if (iaqSensor.bme680Status < BME680_OK)
{
output = "BME680 error code: " + String(iaqSensor.bme680Status);
Serial.println(output);
for (;;)
errLeds(); /* Halt in case of failure */
}
else
{
output = "BME680 warning code: " + String(iaqSensor.bme680Status);
Serial.println(output);
}
}
}
void errLeds(void)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); delay(100);
digitalWrite(LED_BUILTIN, LOW);
OUTPUT
RESULT:
Thus, write a program to develop a commercial IOT application was output was verified and
executed successfully.