CS3691 - Embedded Systems and Iot Lab Manual
CS3691 - Embedded Systems and Iot Lab Manual
Exp. Page
Date Name of the Experiment No.
No
Cycle – I
1.a
1.b
1.c
1.d
2
3.a
3.b
3.c
4.a
4.b
Cycle – II
5
7
8
9.a
9.b
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 4
EX. NO : 01
DATE :
8 BIT ADDITION USING ARITHMETIC OPERATION 8051
MICROCONTROLLER (USING SIMULATOR)
AIM:
To write an ALP program to add, Subtract, multiply and divide two 8-bit
numbers using 8051 microcontroller.
Addition Program ALGORITHM:
➢Clear carry.
➢Load accumulator A with any desired 8-bitdata.
➢Add accumulator with 8-bitnumbers.
➢Store the result using DPTR.
➢Stop theprogram.
FLOW CHART
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 6
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION
Addition program
0000 74, 07 MOV A, #07 Move data to Acc
Subtraction program
0000 74, 07 MOV A, #07 Move data to Acc
Multiplication program
0000 74, FF MOV A,#0FFH Move data to Acc
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION
Division program
0000 74, 0D MOV A,#13 Move data to Acc
OUTPUT:
INPUT OUTPUT
ADDITION
ACC R0
B Reg
SUBTRACTION
ACC R1
B Reg
MULTIPLICATION
ACC R3
B Reg R4
DIVISION
ACC R3
B Reg R4
RESULT:
Thus the 8051 ALP for Addition, Subtraction, Multiplication and Division of two 8
bit numbers is executed.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 8
EX. NO :2
DATE :
LOGICAL OPERATIONS and 2’s Complement
USING8051 MICROCONTROLLER
AIM:
To perform logical operation using 8051 microcontroller AND, OR & EX-OR.
ALGORITHM:
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION
OR Operation program
0000 C3 CLR C Clear the carry
0001 74,07 MOV A, #07 Move data to Acc
0003 44,03 ORL A, #03 OR Acc with immediate
0005 F4 MOV R1, A Move result to R1 Reg
0006 80,FE HERE: SJMP HERE Short jump here
ADD
DATA1 R0
DATA 2
OR
DATA1 R1
DATA 2
XOR
DATA1 R2
DATA 2
2’s COMPLEMENT
DATA1 R3
RESULT:
Thus the assembly language program to perform logical operations AND, OR
& EX-OR and 2’s Complement using 8051 Performed and the result is stored.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 11
EX. NO : 03
DATE :
8 BIT ARITHMETIC OPERATION USING 8051 MICROCONTROLLER
C PROGRAMMING (Using Keil uVision5 )
Write Basic and arithmetic Programs Using Embedded C
AIM:
//subtraction
a=0x03; //first 8-bit number
//multiplication
d=0x03; //first 8-bit number
//division
p=0x03; //first 8-bit number
while(1);
}
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 13
RESULT:
INPUT OUTPUT
ADDITION
DATA1 PORT 0
DATA 2
SUBTRACTION
DATA1 PORT 1
DATA 2
MULTIPLICATION
DATA1
PORT 2
DATA 2
DIVISION
DATA1 PORT 3
DATA 2
RESULT:
Thus the 8051 C – Programming for Addition, Subtraction, Multiplication and Division of two 8 bit
numbers is executed in Keil.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 14
EX. NO : 04
DATE :
ARDUINO PROGRAMMING (LED BLINKING AND ANALOG READ)
EXP 4a
Hardware Procedure:
Software Procedure:
2. Click on file
3. Click on New
5. Click on Save
6. Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 15
Apparatus:
Hardware Procedure:
LED pin is Connected to Arduino Uno pin of 11 & 12.
POT pin is connected to the Arduino pin A1.
Power jack is connected to the Arduino.
USB connector is connected to Arduino Uno to monitor.
Connect the 12V power supply to development board.
Check the output from the development board.
Software Procedure:
1. Click on Arduino IDE
2. Click on file
3. Click on New
4. Write a Program as per circuit Pin connections
5. Click on Save
6. Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 17
Program:
#define LED 11
#define LD 12
#define POT A0
void setup()
pinMode(LED, OUTPUT);
pinMode(LD,OUTPUT);
pinMode(POT, INPUT);
void loop()
int x = analogRead(POT);
digitalWrite(LED,HIGH);
digitalWrite(LD,LOW);
else
digitalWrite(LED,LOW);
digitalWrite(LD,HIGH);
}
}
RESULT: LED is successfully controlled by Arduino microcontroller Board.
RESULT: Analog POT Value (Sensors data) are successfully measured by Arduino.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 18
EXP 5a
Aim: To communication with IOT devices Using Arduino Uno board via GSM and Bluetooth
Apparatus:
Hardware Procedure:
Connect LM35 or LDR to Arduino Uno pin of A0.
Read the sensor value from the Arduino pin A0.
Power jack is connected to the Arduino.
USB connector is connected to Arduino Uno to monitor.
Connect the Bluetooth or Zigbee or GSM board with Arduino Uno.
Check the output from the development board.
Software Procedure:
8. Click on Arduino IDE
9. Click on file
10. Click on New
11. Write a Program as per circuit Pin connections
12. Click on Save
13. Click on Verify
14. Click on Upload the code into Arduino Uno by using USB cable.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 19
Program:
Communication using Bluetooth HC05 – Arduino Uno with Mobile App (IoT
Device)
int val;
void setup()
{
Serial.begin(9600);
pinMode(A0,INPUT);
}
void loop()
{
val=analogRead(A0);
Serial.print("Value =");
Serial.println(val);
delay(500);
}
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 20
Program:
#define sw1 11
int swstate1;
void setup()
{
Serial.begin(9600);
pinMode(sw1,INPUT);
}
void loop()
{
swstate1 = digitalRead(sw1);
delay(500);
if(swstate1 == 1)
{
Serial.println("sending SMS");
SendMessage();
delay(1000);
}
else
{
Serial.println("Waiting for Emergency switch");
}
delay(500);
}
void SendMessage()
{
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 21
Serial.println("AT"); //Sets the GSM Module in Text Mode
delay(100);
Serial.println((char)13);// ASCII code of enter
delay(1000);
Serial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(100);
Serial.println((char)13);// ASCII code of enter
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial.println("ATE=0"); //Sets the GSM Module in Text Mode
delay(100);
Serial.println((char)13);// ASCII code of enter
delay(1000);
Serial.println("AT+CMGS=\"+919994085790\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("CS 3691 – EMBEDDED SYSTEMS AND IOT LAB");// The SMS text
you want to send
delay(100);
//mySerial.println("ATD+60XXXXXXXXX;");
Serial.println((char)26);// ASCII code of CTRL+Z
delay(5000);
Serial.println("ATD+919994085790;"); // Replace x with mobile number
delay(1000);
}
void RecieveMessage()
{
Serial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
RESULT:
Thus communication with IOT devices Using Arduino Uno board via GSM and
Bluetooth is completed.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 22
EXP 6
Apparatus:
Hardware Procedure:
Connect LED to GPIO 25
Connect LM35 or LDR to RP2040 of A0.
Read the sensor value from the Arduino pin A0.
Power jack is connected to the Arduino.
USB connector is connected to RP2040 to monitor.
Software Procedure:
o Click on Thonny
o Click on file
o Click on New
o Write a Program as per circuit Pin connections
o Click on Save
o Click on Verify
o Click on Upload the code into RP2040by using USB cable.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 23
Program:
import time
from machine import Pin
led=Pin(25,Pin.OUT) #create LED object from pin13,Set Pin13 to output
while True:
led.value(1) #Set led turn on
time.sleep(1)
led.value(0) #Set led turn off
time.sleep(1) #delay(1 sec)
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 24
Program:
import machine
import utime
sensor_temp = machine.ADC(0)
conversion_factor = 3.3 / (65535)
while True:
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
print("Temperature: {}".format(temperature))
utime.sleep(2)
RESULT: LED is successfully controlled by RP2040 and Analog LM35 Value (Sensors
data) are successfully measured by RP2040.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 25
EXP 7
Setup a cloud platform and upload the Temperature and Humidity using DHT11
Sensor and LDR Sensor to Thingspeak cloud and Firebase Cloud
Aim: To Interface DHT11 and LDR interface with NodeMCU and upload data to Thingspeak cloud and
Firebase Console.
Apparatus:
Hardware Procedure:
The DHT 11 has 4 Pins. Pin 1 is VCC, Pins 2 is Data, Pin 3 is NOT USED, Pin 4 is
Ground.
Connect DHT 11 Pin 1 to 3.3v
Connect DHT 11 Pin 2 to Raspberry PI Pin 16/GPIO 23 and connect a 4.7 or 10k resistor
from DHT 11 Pin 2 to DHT Pin 1
Connect DHT 11 Pin 4 to Ground
The photo resistor has 2 pins
Connect one pin to 3.3.v
Connect the Other Pin to Raspberry Pi Pin 18/GPIO 24
Connect a 1uF Capacitor to the same pin that the photo resistor is connected to on
GPIO24. The Ground (White Stripe) side of the capacitor should go to Ground.
Software Procedure:
o Click on Thonny
o Click on file
o Click on New
o Write a Program as per circuit Pin connections
o Click on Save
o Click on Verify
o Click on Upload the code into RP 4 by using USB cable.
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 26
o Create Channel in Thingspeak.com
o And Monitor the data uploaded in cloud
#include <DHT.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST "esiotlabpro-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "F6sgxiyuFaFkVWY9imfB1IhVO2m2HYCQq9FX49xQ"
#define WIFI_SSID "GJC"
#define WIFI_PASSWORD "iforgott"
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
String n;
String m;
String o;
String p;
void setup()
{
Wire.begin(2,0);
delay(5000);
dht.begin();
pinMode(D2,INPUT);
pinMode(D3,INPUT);
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
delay(2000);
}
void sensorUpdate()
{
float t = dht.readTemperature();
Firebase.set("TEMP",t);
Serial.println(t);
float h = dht.readHumidity();
Firebase.set("HUMD",h);
Serial.println(h);
if ( isnan(t))
{
Serial.println(F("Failed to read from DHT sensor!"));
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 28
return;
}
}
void loop()
{
sensorUpdate();
if ((digitalRead(D2)==HIGH))
{
Firebase.set("LDR1","OFF");
}
else
{
Firebase.set("LDR1","ON");
}
}
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
const char* ssid = "GJC";
const char* password = "iforgott";
WiFiClient client;
unsigned long myChannelNumber = 1013594;
const char * myWriteAPIKey = "UNDAT6YLR7NAMHTB";
void setup()
{
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}
void loop()
{
int Value=analogRead(A0);
Serial.println(Value);
delay(100);
ThingSpeak.writeField(myChannelNumber,1,Value, myWriteAPIKey);
delay(100);
}
RESULT: Sensor Data are successfully upload to Firebase and Thingspeak cloud
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 30
EXP 8
Setup a cloud platform and upload the Temperature and Humidity using DHT11
Sensor and LDR Sensor to Thingspeak cloud using Raspberryi pi 4 controller
Aim: To Interface DHT11 with Raspberry pi and LDR interface with Raspberry pi 4 and
upload data to Thingspeak cloud.
Apparatus:
Hardware Procedure:
The DHT 11 has 4 Pins. Pin 1 is VCC, Pins 2 is Data, Pin 3 is NOT USED, Pin 4 is
Ground.
Connect DHT 11 Pin 1 to 3.3v
Connect DHT 11 Pin 2 to Raspberry PI Pin 16/GPIO 23 and connect a 4.7 or 10k resistor
from DHT 11 Pin 2 to DHT Pin 1
Connect DHT 11 Pin 4 to Ground
The photo resistor has 2 pins
Connect one pin to 3.3.v
Connect the Other Pin to Raspberry Pi Pin 18/GPIO 24
Connect a 1uF Capacitor to the same pin that the photo resistor is connected to on
GPIO24. The Ground (White Stripe) side of the capacitor should go to Ground.
Software Procedure:
o Click on Thonny
o Click on file
o Click on New
o Write a Program as per circuit Pin connections
o Click on Save
o Click on Verify
CS 3691 – EMBEDDED SYSTEMS AND IOT LAB 31
o Click on Upload the code into RP 4 by using USB cable.
o Create Channel in Thingspeak.com
o And Monitor the data uploaded in cloud
import sys
import RPi.GPIO as GPIO
import os
from time import sleep
import Adafruit_DHT
import urllib2
DEBUG = 1
# Setup the pins we are connect to
RCpin = 24
DHTpin = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(RCpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def getSensorData():
RHW, TW = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)
# return dict
return (str(RHW), str(TW),str(TWF))
def RCtime(RCpin):
LT = 0
if (GPIO.input(RCpin) == True):
LT += 1
return (str(LT))
# main() function
def main():
print 'starting...'
baseURL """