0% found this document useful (0 votes)
2 views65 pages

Es Record Final

The document outlines various assembly language experiments using the 8051 microcontroller, including data transfer, arithmetic operations, and logical manipulations. It also covers programming in Embedded C for basic arithmetic operations and introduces the Arduino platform for programming and interfacing with I2C devices. Finally, it explores different communication methods with IoT devices such as Zigbee, GSM, and Bluetooth.

Uploaded by

harishvenki2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views65 pages

Es Record Final

The document outlines various assembly language experiments using the 8051 microcontroller, including data transfer, arithmetic operations, and logical manipulations. It also covers programming in Embedded C for basic arithmetic operations and introduces the Arduino platform for programming and interfacing with I2C devices. Finally, it explores different communication methods with IoT devices such as Zigbee, GSM, and Bluetooth.

Uploaded by

harishvenki2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

EX NO .

1 WRITE 8051 ASSEMBLY LANGUAGE EXPERIMENTS USING SIMULATOR

DATE:

AIM:
To write an assembly language program using simulator.

APPARATUS REQUIRED:
1. 8051-Microcontroller Kit - 1.
2. DC Power supply – 5V.

PROGRAM:
ORG 0000H
MOV R0,#30H; get memory location in memory pointer R0
MOV dptr,#1000h;
MOV R2,#0AH
REPEAT:MOVX A,@DPTR;
XCH A,@R0;
MOVX @dptr,A;
INC R0;
INC DPTR;
DJNZ R2,REPEAT;
END
OBSERVATION:

Before Execution
1000h:0BH,17H,2DH,41,4AH,53,52H,0FH,1CH,0AH
30H: 01H,02H,3H,4H,5H,6H,7H,8H,9H,0AH

After Execution:
30H: 0BH, 17H, 2DH, 41, 4AH, 53, 52H, 0FH, 1CH, 0AH
1000H:01H,02H,3H,4H,5H,6H,7H,8H,9H,0AH

RESULT:
Thus the an assembly language program using simulator are performed using 8051 was
executed and verified successfully.

1
EX No .2 TEST DATA TRANSFER BETWEEN REGISTERS AND MEMORY.

DATE:

AIM:
To write an assembly language program to perform ALU operation two 8-bit numbers
using 8051.

APPARATUS REQUIRED:
 8051-Microcontroller Kit - 1.
 DC Power supply – 5V.

PROGRAMMING STEPS:
1. Take a two address pointer for source and address memory.
2. Load counter from first source memory.
3. Get the first data from source memory into accumulator.
4. Exchange the content of A and destination memory pointer.
5. Increment source and destination memory pointer.
6. Decrement the counter.
7. If the counter is not zero repeat the sequence.
8. End the program.

PROGRAM

ORG 4000H

MOV R0,#40H

MOV R1,#41H

MOV A,@R0

MOV R2,A

INC R0

BACK:MOV A, @R0

XCH A,@R1

MOV @R0,A

INC R0

INC R1

DJNZ R2,BACK

END

2
OBSERVATION:

Before Execution:

After Execution:

RESULT:
Thus the program for 8-bit data transfer between the register and memory are
performed using 8051 was executed and verified successfully.

3
EX N0 .3 PERFORM ALU OPERATIONS

DATE:

AIM:
To write an assembly language program to perform ALU operation two 8-bit numbers
using 8051.

APPARATUS REQUIRED:
 8051-Microcontroller Kit - 1.
 DC Power supply – 5V.

(I) ADDITION OF 8 BIT NUMBERS


ALGORITHM:
 C register is to be cleared for carry.
 Get the data to be added using register A.
 Add the two data.
 Store the result in the memory pointer.

PROGRAM:
ORG 4100H
MOV A, #DATA1
ADD A, #DATA2
MOV DPTR, #4500
MOVX @DPTR, A
HERE: SJMP HERE

OBSERVATION:

Input Output
Data 1 Data 2 Address Data
04 4500

(II) SUBTRACTION OF 8 BIT NUMBERS


ALGORITHM:

1. C register is to be cleared for carry.


2. Get the data to be subtracted with register A.
3. Subtract the two data.
4. Store the result in the memory pointer.

4
PROGRAM:
ORG 4100H
MOV A, #DATA1
SUBB A, #DATA2
MOV DPTR, #4500
MOVX @DPTR, A
HERE: SJMP HERE

OBSERVATION:

Input Output
Data 1 Data 2 Address Data
06 4500

(III) MULTIPLICATION OF 8 BIT NUMBERS


ALGORITHM:
1. Get the data in register A. Get the value to be multiplied in B register.
2. Multiply the data.
3. The high and low nibble of result is stored in A & B register .

PROGRAM:
ORG 4100H
MOV A, #DATA1
MOV B, #DATA2
MUL AB
MOV DPTR, #4500
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HERE: SJMP HERE

OBSERVATION:

Input Output
Data 1 Data 2 Address Data
04 4500
4501

5
(IV) DIVISION OF 8 BIT NUMBERS

ALGORITHM:

1. Get the divisor in register A.


2. Get the value to be divided in B register.
3. Divide the data.
4. The quotient is in register A and remainder is in register B.

PROGRAM:
ORG 4100H
MOV A, #DATA1
MOV B, #DATA2
DIV AB
MOV DPTR, #4500
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HERE: SJMP HERE

OBSERVATION:

Input Output
Data 1 Data 2 Address Data
06 4500
4501

RESULT:
Thus the program for 8-bit arithmetic operations are performed using 8051 was
executed and verified successfully.

6
Logical Manipulations (AND, OR, XOR, NOT)

ALGORITHM:
1. Initialize the SI register and store the data.
2. Move the contents from memory to AH and AL registers.
3. Perform AND, OR, NOT and XOR operations based on the values stored in AH and AL
register.
4. Store the results in the memory location.
PROGRAM:
MOV SI, 1200H
MOV AX, [SI]
MOV BX, [SI+2]
MOV CX, AX
OR AX,BX
AND CX,BX
XOR DX,BX
MOV DI, 1500H
MOV [DI], AX
MOV [DI+2], CX
MOV [DI+4], DX
HLT

OBSERVATION:
Input Output
Address Data Address Data
1200 FF 1500 FF

1201 FF 1501 FF

1202 00 1502 00

1203 00 1503 00

1504 FF

1505 FF

RESULT:
Thus the assembly language program for performing various logical operations
using 8086 was executed and verified successfully.
7
EX No .4 WRITE BASIC AND ARITHMETIC PROGRAMS USING EMBEDDED C

DATE:

AIM:

Write Basic And Arithmetic Programs Using Embedded C

Software required: -

Keil u vision 5

Theory: -

This experiment aims to perform basic arithmetic operation using the software keil u vision 5. The
program is by default present after installation of this software. Firstly the header files REG52.H,
stdio.h are declared for the intended 8051. Programming for debugging with Monitor-51is made.
Now the main function starts. The serial port for 1200 baud at 16MHz is set up. An embedded
program never exits (because there is no operating system to return to).

Program:-

#include <REG52.H>

void main(void)

Unsigned char x,y,z,a,b,c,d,e,f,p,q,r;

#addition

x=0*12;

y=0*34;

P0=0*00;

z=x+y;

P0=z;

#substraction

a=0*12;

b=0*34;

P1=0*00;

c=a-b;

8
P0=c;

#multiplication

d=0*12;

e=0*34;

P2=0*00;

f=e*d;

P0=f;

#division

p=0*12;

q=0*34;

P2=0*00;

r=p%q;

P0=r;

}Select open project from project

9
Select Keil_v5 present in Local Disk (C:)

10
OBSERVATION:

Result:

Thus the basic arithmetic operation using keil embedded C is performed.


11
EX NO: 5 INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING

DATE:

AIM:
To learn the basics of Arduino Platform and its Programming.
HARDWARE & SOFTWARE

1. Arduino board
2. USB Cable
3. Arduino IDE software
ARDUINO PLATFORM:

• Arduino is a Electronics Project prototype platform (open-source)


based on an easy-to- use hardware and software.

• Arduino UNO is a microcontroller board based on the ATmega328P.


• It has o 14 digital input/output pins (of which 6 can be used as PWM
outputs) o 6 analog inputs o a 16 MHz ceramic resonator o a USB
connection o a power jack o Reset button

The USB connection with the PC is necessary to program the board and not just to
power it up. The Uno automatically draw power from either the USB or an external
power supply. Connect the board to computer using the USB cable. The green power
LED (labelled PWR) should go on.

PROCEDURE:

1. Download & install the Arduino environment (IDE)


2. Connect the Arduino board to computer via the UBS cable.
3. Launch the Arduino IDE

Open sketch

Open the LED blink example sketch: File > Examples >01.Basics > Blink.

12
Select board type and port

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, disconnect the board and re-open the menu; the entry that disappears should
be the Arduino board. Reconnect the board and select that serial port.

13
Upload the program

Now, simply click the "Upload" button in the environment. Wait a few seconds - the RX
and TX leds on the board flashing. If the upload is successful, the message "Done
uploading." will appear in the status bar.

14
I2C Communication

I2C is short for Inter-IC. And it is a type of BUS. This is designed by Philips
semiconductors. I2C is a synchronous, multi slave, multi master packet switched, single-
ended serial bus. ie. multiple chips can be connect to the same bus.I2C uses only two
bidirectional open collector or open drain lines, Serial Data Line (SDA) and Serial Clock
Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V, although
systems with other voltages are permitted. I2C Serial Interface Adapter

15
It is also known as I2C Module. It has total of 20 male pins. 16 pins are faced to rear side
and 4 pins faced towards front side. The 16 pins for connect to 16x2 LCD and the 2 pins
out of 4 pins are SDA and SCL. SDA is the serial data pin and SCL is the clock pin. The rest
2 pins for power supply (Vcc and ground).There is a POT on the I2C Module. We can
control the contrast of the LCD display by rotating this POT. And there is a jumber fixed
on the module. When we remove the jumber, the backlight of the LCD display will go
OFF.

Connection
First solder the I2C Module. There is no label on the I2C Module for connecting to 16x2
LCD. So solder it with the help of the image given below

I2C Module on 16x2 LCD

After connect the I2C Module to Arduino Uno.

Arduino Uno I2C module

Analog Pin 4 - SDA

Analog pin 5 - SCL

5V - Vcc

GND - GND

Connect the Arduino to computer.

Add library

16
17
Interface I2C 16x2 LCD with Arduino Uno

18
PROGRAM

#include <Arduino.h>

#include <Wire.h>

#include

<LiquidCrystal_PCF8574.h

> int show = -1; void

setup() { int error;

Serial.begin(115200

);

Serial.println("LCD...

"); while (!Serial) ;

Serial.println("Probing for PCF8574 on address 0x27...");

Wire.begin();

Wire.beginTransmission(0

x27); error =

Wire.endTransmission();

Serial.print(

"Error: ");

Serial.print(

error); if

(error == 0)

19
Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); //

initialize the lcd

} else {

Serial.println(": LCD not found.");

} // if

} // setup()

void loop() {

if (show == 0)

lcd.setBackligh

t(255);

lcd.home();

lcd.clear();

lcd.print("Hell

o LCD");

delay(1000);

20
OUTPUT:

LCD found in Serial Monitor.

LCD not found in Serial Monitor.

Hello LCD in LCD Display.

RESULT:
Thus the Program to Display in LCD is executed successfully using Arduino
Platform & IDE.

21
EX NO: 6 EXPLORE DIFFERENT COMMUNICATION METHODS WITH IOT DEVICES
(ZIGBEE, GSM, BLUETOOTH)
DATE:

AIM:

To Explore different communication methods with IoT devices (Zigbee, GSM, Bluetooth)

HARWARE REQUIRED:

Different communication modules

Connecting wires

Add library Mesh network

Open code from Example→painless mesh→basic

22
Connection diagram

PROGRAM

#include "painlessMesh.h"

#define MESH_PREFIX "whateverYouLike"

#define MESH_PASSWORD "somethingSneaky"

#define MESH_PORT 5555

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2

line display String datar; int show = -1;

Scheduler userScheduler; // to control your personal task

painlessMesh mesh;

23
// User stub void sendMessage() ; // Prototype so

PlatformIO doesn't complain

Task taskSendMessage( TASK_SECOND * 1 , TASK_FOREVER, &sendMessage );

void sendMessage() { String msg = "engineering"; msg += mesh.getNodeId();

mesh.sendBroadcast( msg ); taskSendMessage.setInterval( random(

TASK_SECOND * 1, TASK_SECOND * 2 ));

// Needed for painless library void

receivedCallback( uint32_t from, String &msg )

{ Serial.printf(" msg=%s\n",msg.c_str());

datar=msg.c_str();

void newConnectionCallback(uint32_t nodeId) {

Serial.printf("--> startHere: New Connection, nodeId = %u\n",

nodeId); }

void changedConnectionCallback() {

Serial.printf("Changed connections\n");

24
}

void nodeTimeAdjustedCallback(int32_t offset) {

Serial.printf("Adjusted time %u. Offset = %d\n",

mesh.getNodeTime(),offset); }

void setup() {

Serial.begin(

9600); int

error;

Wire.begin();

Wire.beginTransmission(0x27);

error = Wire.endTransmission();

Serial.print("Error: ");

Serial.print(error);

if (error == 0) {

Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); // initialize

the lcd

25
} else {

Serial.println(": LCD not found.");

lcd.setBacklight(255);

lcd.home();

mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see

startup messages

mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );

mesh.onReceive(&receivedCallback);

mesh.onNewConnection(&newConnectionCallback);

mesh.onChangedConnections(&changedConnectionCallback);

mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);

userScheduler.addTask( taskSendMessage );

taskSendMessage.enable();

void loop() {

mesh.update();

lcd.clear();

lcd.print("data:")
26
;

lcd.setCursor(0,

1);

lcd.print(datar);

delay(1000);

BLUETOOTH:

Bluetooth (IEEE 802.15 STANDARD) is a wireless LAN technology designed


to connect devices of different functions such as telephones, notebooks,
computers (desktop and laptop), cameras, printers when they are at a
short distance from each other.

HC-05 is a Bluetooth device used for wireless communication with Bluetooth


enabled devices (like smartphone). It communicates with microcontrollers
using serial communication (USART) –RX & TX Pins.

BLUE TOOTH communication

27
Wiring diagram

PROGRAM

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27);

int show = -1;

String data;

String inputString = ""; // a String to hold incoming

data bool stringComplete = false; // whether the string is

complete void setup() {

Serial.begin(

28
9600); int

error;

Serial.println("welcome!");

Serial.println("Hello, world?");

if (error == 0) {

Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); // initialize

the lcd

} else {

Serial.println(": LCD not found.");

lcd.setBackligh

t(255);

lcd.home();

void loop() { // run over

and over lcd.clear();

lcd.print("Bluetooth");

delay(2000);
29
Serial.println("Bluetooth OK");

delay(3000);

Serial.println((char)26);// ASCII code of CTRL+Z

delay(3000);}

GSM MODULE

Global System for Mobile communication (GSM) is digital cellular


system used for mobile devices. It is an international standard for
mobile which is widely used for long distance communication.
There are various GSM modules available in market like SIM900, SIM700.
SIM900A module allows users to send/receive data over GPRS, send/receive
SMS and make/receive voice calls.
The GSM/GPRS module uses USART communication to communicate with
microcontroller or PC terminal. AT commands are used to configure the
module in different modes and to perform various functions like calling,
posting data to a site.

AT COMMAND: BASIC
Command Description Response

AT Checking communication OK

CALL COMMAND:
Command Description Response

ATD<Mob. Dial / call a OK (if successful), BUSY (if busy), NO


number
No.>; CARRIER (if no connection)

ATA Answer a call OK

ATH Hang up call OK

30
SMS COMMAND:
Command Description Response

> ”Type message here”


AT+CMGS=”9881xxxxxx” Send message

Connection diagram

GSM PROGRAM

#include <Wire.h>

#include

<LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574

lcd(0x27); int show = -1;

void setup() {

Serial.be
31
gin(9600)

; int

error; if

(error ==

0) {

Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); // initialize

the lcd

} else {

Serial.println(": LCD not found.");

lcd.setBackligh

t(255);

lcd.home();

lcd.clear();

lcd.print("GSM INTERFACE CONTROLLER");

lcd.setCursor(0,

1);

lcd.print(data);

delay(10000);

32
lcd.clear();

lcd.print("CHECK

GSM STATUS");

lcd.setCursor(0, 1);

} void loop() { // run

over and over

lc

d.

cl

r(

);

lcd.print("CHECK GSM STATUS");

delay(5000);

lcd.clear();

lcd.print("sms

mode");

Serial.println("AT"); //Sets the GSM Module in Text

Mode delay(2000); // Delay of 1000 milli seconds or

1 second Serial.println("AT+CMGF=1");

delay(2000);
33
Serial.println("AT+CMGS=\"7708954811\"\r"); // Replace x with mobile number

delay(2000);

Serial.println("WELCOME TO CALIBER VIRTUAL TECHNOLOGIES");

delay(1000);

Serial.println((char)26);// ASCII code of CTRL+Z

delay(3000);

RESULT:

Thus the different methods of communication with IoT devices were explored successfully.

34
EX NO .7 INTRODUCTION TO RASPBERRY PI PLATFORM & PYTHON PROGRAMMING

DATE:

AIM:

To introduce the Raspberry PI platform

PROCEDURE:

To get started with the Raspberry Pi Pico and the Thonny Python IDE, which has out-of-
thebox support for Micropython and Pico.

To set up with scripting in Thonny for the Raspberry Pi Pico.

We'll install Thonny, configure for Pico and write our first script. To follow along we'll
need:

• A Raspberry Pi Pico

• A USB micro B
lead Contents
• Install Thonny
• Set up Thonny
• REPL interface
• Writing a Script
• Installing a Package

Install Thonny
Thonny comes pre-installed. For those on another operating system, download Thonny
here and run the installer.

Once the installer finishes, run Thonny.

Set up Thonny

Hold the BOOTSEL button on your Pico, and connect your Pico to your computer via USB.

Go to Run > Select interpreter and choose MicroPython (Raspberry Pi Pico).


35
It's also a good idea to install or update firmware. This will update Pico with the latest
version of MicroPython, or install MicroPython if it wasn't already.

REPL interface (Shell)

We can immediately start executing code in the REPL - Enter this code in the shell tab:
print("Hello, World!")

The command will be sent to the Pico, which will execute the command and display back
the message.

We can also take control of the on-board LED by executing the following code:

36
from machine

import Pin led =

Pin(25, Pin.OUT)

led.toggle()

This code will toggle the LED. If you keep executing led.toggle() the LED will keep changing
state.

37
Writing a Script

Create a new script with File > New and paste in the following code:

from machine

import Pin from

time import sleep

led = Pin(25,

Pin.OUT) n = 0;

while True:

led.toggle()

print("13 x {} =

{}".format(n,

13*n)) # print the

thirteen-times

table n=n+1

sleep(0.5)

Save the script - you will be prompted to save to computer OR the pico. Select save to Pico
and name the file main.py

Return to the REPL and press Ctrl+D (or use the Stop/Restart button) to restart your Pico.
The LED should flash at a steady rate and the shell should begin printing multiples of
thirteen.

38
Installing a Package

Packages are reusable pieces of code that another programmer has written for a
common task, such as interfacing with a specific piece of hardware. Thonny has support
for installing micropython packages from the Python Package Index - aka 'PyPI'
directly onto the Raspberry Pi Pico.

To install a package, ensure the Pico is plugged in and go to Tools > Manage Packages,
which will show the Manage Packages dialog.
39
Enter the name of the package, would like to install into the search bar and click 'Search
on PyPI'.

In the search results list, click the title of the package would like to install. A title that's in
bold simply indicates a direct search match on the text that entered in the search bar.

The Manage Packages dialog will show an overview of the package have clicked. Click
Install to install the package on the Pico.

Confirm the package has been installed by checking the 'Raspberry Pi Pico' section of the
File View in Thonny. The view should show a new folder named 'lib', and inside this
folder will be one or more folders containing the metadata and source code of the
library you just installed.

RESULT:

Thus the Platform for Raspberry Pi pico is completed successfully.

40
EX NO .8 INTERFACEING SENSORS WITH RASPBERRY PI

DATE:

AIM:

To interface sensors with Raspberry Pi

HARDWARE REQUIRED

DHT11

Sensor

16*2 LCD

Display

Raspberry Pi Pico

Wiring diagram

PROGRAM

#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )

#error For RASPBERRY_PI_PICO_W only


41
#endif

#define _RP2040W_AWS_LOGLEVEL_ 1

#include <pico/cyw43_arch.h>

#include <AsyncWebServer_RP2040W.h>

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line
display

int show = -1;

#include "DHTStable.h"

DHTStable DHT;

#define DHT11_PIN 3

void setup()

// ThingSpeak.begin(client);

Serial.begin(115200);

Wire.begin();

Wire.beginTransmission(0x27);

// error = Wire.endTransmission();

Serial.print("Error: ");

//Serial.print(error);

42
lcd.begin(16, 2); //

initialize the lcd

lcd.setBacklight(255);

lcd.home(); lcd.clear();

lcd.print("welcome");

delay(1000);

void loop()

// check_status();

delay(1000);

Serial.print("DHT11, \t");

int chk =

DHT.read11(DHT11_PIN);

switch (chk)

case DHTLIB_OK:

Serial.print("OK,\t");

break;

case DHTLIB_ERROR_CHECKSUM:

Serial.print("Checksum

error,\t"); break;

case DHTLIB_ERROR_TIMEOUT:

43
Serial.print("Time out

error,\t"); break;

default:

Serial.print("Unknown

error,\t"); break;

// DISPLAY DATA

Serial.print(DHT.getHumidity(), 1);

Serial.print(",\t");

Serial.println(DHT.getTemperature(), 1);

//ThingSpeak.writeField(myChannelNumber, FieldNumber, DHT.getTemperature(),


myWriteAPIKey);

lcd.clear();

lcd.print("Temperature

"); lcd.setCursor(0, 1);

lcd.print(" ");

lcd.print(DHT.getTempera

ture()); delay(1000);

RESULT:
Thus the sensor is interface with Raspberry pi and verified successfully.

44
EX NO .9 COMMUNICATION BETWEEN RASPBERRY PI AND
ARDUINO USING WIRELESS MEDIUM

DATE:

AIM:

To communicate the Raspberry pi and Arduino in Wireless medium

HARDWARE REQUIRED:

 Arduino Uno
 Bluetooth
 HC-05
 Raspberry PI pico
 POWER ADAPTER
 Connecting wires

PROCEDURE

Connection for raspberry pi

45
Connection for Arduino

PROGRAM

/*

Software serial multple serial test

Receives from the hardware serial, sends to software serial.

Receives from software serial, sends to hardware serial.

The circuit:

* RX is digital pin 10 (connect to TX of other device)

* TX is digital pin 11 (connect to RX of other device)

46
*/

#include <SoftwareSerial.h>

SoftwareSerial mySerial(17, 16); // RX, TX

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#include <SoftwareSerial.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2
line display int show = -1;

String data;

String inputString = ""; // a String to hold incoming

data bool stringComplete = false; // whether the string is

complete void setup() {

// Open serial communications and wait for port

to open: Serial.begin(9600); int error;

Serial.println("Goodnight moon!");

// set the data rate for the

SoftwareSerial port

mySerial.begin(9600);

mySerial.println("Hello, world?"); if

(error == 0) {

Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); // initialize

the lcd

} else {

Serial.println(": LCD not found.");

47
}

lcd.setBackligh

t(255);

lcd.home();

void loop() { // run over and

over while

(mySerial.available()) {

// get the new byte: char

inChar =

(char)mySerial.read();

// add it to the inputString:

inputString += inChar;

// if the incoming character is a newline, set a flag so the main loop can

// do something

about it: if

(inChar == '\n') {

stringComplete =

true;

} if

(stringComplete) {

Serial.println(input

String);

// clear the string:

data=inputString;

48
inputString = "";

stringComplete =

false;

lcd.clear();

lcd.print("data:");

lcd.setCursor(0, 1);

lcd.print(data);

delay(1000);

RESULT:

Thus the Arduino and Raspberry pi is communicated through Wireless medium and it is
verified successfully.

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

DATE:

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

THINGSPEAK

1. Introduction:

To setup account with Thing Speak and basics. Thing Speak is an open cloud data platform
where you can store and retrieve data.

2. Thing Speak Basics and account setup –

URL: https://thingspeak.com/

Create an account in Thing Speak. Once have a Thing Speak account login to the account.

Create a new channel by clicking on the button as shown in below image – A channel is
the source for your data. Where we can store and retrieve data. A channel can have
maximum 8 fields. It means you can store 8 different data to a channel.

50
Enter basic details of the channel

Here we are creating channel to store data from DHT11 temperature and humidity sensor
so we need two fields.

Scroll down and save the channel.

51
Channel ID

Channel Id is the identity of the channel. Note down this.

API Keys

API (Application Programming Interface) keys are the keys to access to specific channel.
In simple language can understand that these are password to access the channel. The
access of channel in two ways-

1. To update channel / data logging : API Write Key will be used to access in this mode.

2. To retrieve data : API Read Key will be used to access in this mode.

Click on the API tab to know your API keys. We have blurred our API Keys for security
reasons.

52
3. Accessing Channel:

Following URLs to access the channel.

3.1 To Update channel / data uploading / data logging

URL: http://api.thingspeak.com/update?api_key=YOUR-API&field1=VAR-
1&field2=VAR-2 make the following replacements in

the above mentioned URL-

1. YOUR-API : Your API Write Key

2. VAR-1 : Temperature Data

3. VAR-2 : Humidity Data

Response : If we get a positive number that means the data has been uploaded to the
channel.
The number is index of the last entry have made.

3.2 Retrieve channel / data reading

URL: http://api.thingspeak.com/channels/YOUR-CHANNEL-
ID/fields/FIELD.json?results=NOS-OF-RESULTS&api_key=YOUR-API

make the following replacements in the above mentioned URL-

1.YOUR-CHANNEL-ID – Your channel ID

2. FIELD – Field you want to retrieve. Write 1 for Field1, 2 for Field2

3. NOS-OF-RESULTS = The number of rows want to retrieve.


53
4. YOUR-API : Your API Read Key

5. Reading data through ThingSpeak website.

Login to account. Select the channel and click on the Private view as shown in the
following image.

RESULT:

Thus the procedure to set up a cloud platform for IoT application is


verified using Think speak.

54
EX NO .11 LOG DATA USING RASPBERRY PI UPLOAD TO CLOUD

DATE:

AIM:

To log data using Rapberry pi and upload to cloud

HARDWARE REQUIRED

DHT11 Sensor

Raspberry PI Pico

CONNECTION

PROGRAM

#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )

55
#error For RASPBERRY_PI_PICO_W only

#endif

#define _RP2040W_AWS_LOGLEVEL_ 1

#include <pico/cyw43_arch.h>

#include <AsyncWebServer_RP2040W.h>

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line
display

int show = -1;

#include "DHTStable.h"

DHTStable DHT;

#define DHT11_PIN 1

char ssid[] = "project2"; // your network SSID (name)

char pass[] = "12345678"; // your network password (use for WPA, or use as key for
WEP), length must be 8+

int status = WL_IDLE_STATUS;

#include "ThingSpeak.h"

WiFiClient client;

unsigned long myChannelNumber = 2228779; // Channel ID

here const int FieldNumber = 1;

56
const char * myWriteAPIKey = "VE9ODLVKN2O12KYK"; // Your Write API Key here

AsyncWebServer server(80); void printWifiStatus()

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your board's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("Local IP Address: ");

Serial.println(ip);

void setup()

ThingSpeak.begin(client);

Serial.begin(115200);

Wire.begin();

Wire.beginTransmission(0x27);

// error = Wire.endTransmission();

Serial.print("Error: ");

//Serial.print(error);

lcd.begin(16, 2); // initialize

the lcd lcd.setBacklight(255);

lcd.home(); lcd.clear();

lcd.print("welcome");

delay(1000);

57
// check for the WiFi module:

if (WiFi.status() == WL_NO_MODULE)

Serial.println("Communication with WiFi module failed!"); while (true);

Serial.print(F("Connecting to SSID: "));

Serial.println(ssid);

status = WiFi.begin(ssid, pass);

delay(1000);

// attempt to connect to WiFi

network while ( status !=

WL_CONNECTED)

del

ay(

50

0);

// Connect to WPA/WPA2 network

status = WiFi.status();

} lcd.clear();

lcd.print("wifi

connected");

58
delay(1000);

printWifiStatus();

void loop()

// check_status();

delay(1000);

Serial.print("DHT11, \t");

int chk =

DHT.read11(DHT11_PIN);

switch (chk)

case DHTLIB_OK:

Serial.print("OK,\t");

break;

case DHTLIB_ERROR_CHECKSUM:

Serial.print("Checksum

error,\t"); break;

case DHTLIB_ERROR_TIMEOUT:

Serial.print("Time out

error,\t"); break;

default:

59
Serial.print("Unknown

error,\t"); break;

// DISPLAY DATA

Serial.print(DHT.getHumidity(), 1);

Serial.print(",\t");

Serial.println(DHT.getTemperature(), 1);

ThingSpeak.writeField(myChannelNumber, FieldNumber, DHT.getTemperature(),


myWriteAPIKey);

lcd.clear();

lcd.print("Temperature ");

lcd.setCursor(0, 1);

lcd.print(" ");

lcd.print(DHT.getTempera

ture()); delay(1000);

RESULT:

Thus the DHT11 Sensor data is read. data is uploaded in cloud and verified successfully.

60
EX NO .12 DESIGN A IOT BASED SYSTEM

DATE:

AIM:

To design an IOT based system

HARDWARE REQUIRED:

WiFi Module or ESP 8266 Module.

Connecting cable or USB cable.

Gas Sensor

PROCEDURE:

The Wifi module can be programmed with the Arduino software (download).

STEP 1: Start the process.

STEP 2: Start ->Arduino IDE

STEP 3: Then write the coding in Arduino Software.

STEP 4: Compile the coding in Arduino Software.

STEP 5: Connect the USB cable to WiFi module through USB Socket.

STEP 6: Select tools -> select board -> Generic ESP8266 -> select port.

STEP 7: Upload the coding in ESP Module.

STEP 8: Stop the process.

61
CONNECTION

PROGRAM

#include <Arduino.h>

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line
display

#include <WiFiClient.h>;

#include <ThingSpeak.h>;

#include

<ESP8266WiFi.h>;

62
unsigned long myChannelNumber = 2228779; //Your Channel Number (Without

Brackets) char myWriteAPIKey[] = "VE9ODLVKN2O12KYK"; char ssid[] = "project2";

char pass[] = "12345678"; int show = -1; float h=0,t=0;

WiFiCli

ent

client;

void

setup(

) { int

error;

Serial.begin(115200);

Serial.println("LCD..."

); while (!Serial);

Serial.println("Probing for PCF8574 on address 0x27...");

Wire.begin();

Wire.beginTransmission(0x2

7); error =

Wire.endTransmission();

Serial.print("Error: ");

Serial.print(error);

if (error == 0) {

Serial.println(": LCD

found."); show = 0;

lcd.begin(16, 2); // initialize

the lcd
63
} else {

Serial.println(": LCD not found.");

} // if

lcd.setBackligh

t(255);

lcd.home();

lcd.clear();

ThingSpeak.begin(client); if

(WiFi.status() !=

WL_CONNECTED)

Serial.print("Attempting to connect to

SSID: "); Serial.println(ssid);

lcd.clear();

lcd.print("con..project");

while (WiFi.status() != WL_CONNECTED)

WiFi.begin(ssid,

pass);

Serial.print(".");

delay(5000);

Serial.println("\nConne

cted."); lcd.clear();

lcd.print("wifi
64
connected");

delay(1000);

} // setup()

void loop() {

Int

h=analogRea

d(A0);

lcd.clear();

lcd.print("lpg");

lcd.print(h);

delay(1000);

ThingSpeak.setField( 1, h);

ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

RESULT:

Thus an IOT based system is designed and verified successfully.

65

You might also like