0% found this document useful (0 votes)
5 views68 pages

Eiot Record

The document outlines various experiments related to microcontroller programming, including 8051 Assembly language, Arduino programming, and RP2040 with Python. Each experiment includes an aim, algorithm, program code, and results, demonstrating tasks such as LED blinking, data transfer, and sensor readings. The experiments were successfully implemented and tested in a laboratory setting at KGiSL Institution of Technology.
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)
5 views68 pages

Eiot Record

The document outlines various experiments related to microcontroller programming, including 8051 Assembly language, Arduino programming, and RP2040 with Python. Each experiment includes an aim, algorithm, program code, and results, demonstrating tasks such as LED blinking, data transfer, and sensor readings. The experiments were successfully implemented and tested in a laboratory setting at KGiSL Institution of Technology.
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/ 68

EXP NO : 01 To implement 8051 Assembly language experiment

DATE : using simulator

AIM:

To implement 8051 Assembly language experiment using simulator.

ALGORITHM:

1. Clear the port 1


2. Call delay
3. Put a value to port 1
4. Execute the program

PROGRAM :
To blink led
$MOD51
start: mov p1,#00
lcall delay
mov p1,#ffH
lcall delay
sjmp start
delay: mov R7,#05H
CNTUE: mov R6,#0AH
L1: djnz R6 L1
djnz R7 CNTUE
ret

KGiSL Institution of Technology 711722104115


OUTPUT:

RESULT:
The assembly language experiment using simulator has been done successfully.
KGiSL Institution of Technology 711722104115
EXP NO : 02 Data transfer between registers and memory
DATE :

AIM:

To implement the Data transfer between registers and memory.

ALGORITHM:

1. Add data to A register


2. Initiate data pointer
3. Move A value to the address
4. End the program

PROGRAM:

Data transfer from accumulator register to dptr register

$MOD51

MOV A, #02

MOV DPTR, #4500H

MOVX @DPTR, A

HERE: SJMP HERE

OBSERVATION:
A= 02

MEMORY LOCATION DATA


4500 02

KGiSL Institution of Technology 711722104115


OUTPUT:

RESULT:

The data transfer between registers and memory has been performed.

KGiSL Institution of Technology 711722104115


EXP NO : 03 Perform ALU Operations 8051 Micro controller
DATE :

AIM:
To implement and perform ALU Operations using 8051 Micro controller.

ALGORITHM:
1. Move the first number to A register
2. Add the second number with A register
3. Initiate data pointer
4. Store the result

ALGORITHM:
1. Move the first number to A register
2. Subtract the second number from A register
3. Initiate data pointer
4. Store the result
ALGORITHM:
1. Move the first number to A register
2. Move the second number to B register
3. Subtract the A and B
4. Initiate data pointer
5. Store the result

ALGORITHM:
1. Move the first number to A register
2. Perform logical OR with the second number
3. Initiate data pointer
4. Store the result

ALGORITHM:
1. Move the first number to A register
2. Perform logical AND with the second number
3. Initiate data pointer
4. Store the result

ALGORITHM:
1. Move the first number to A register
2. Perform logical XOR with the second number
3. Initiate data pointer
4. Store the result

KGiSL Institution of Technology 711722104115


8 BIT ADDITION
PROGRAM: Bit Addition (Immediate Addressing)

ADDRES LABE MNEMONIC HEX CODE COMMENTS


S L
$MOD51
4100 MOVA, 03 74,03 Get the data1 in Acc
4101 ADD A, #02 24,02 Add the data1 with
data2
4103 MOV DPTR, 90,45,00 Initialize destination
#4500H
4105 MOVX @DPTR, A F0 Store result destination
4108 STOP: SJMP STOP 80,FE Stop the program
OBSERVATION:
#data1= 03
#data2= 02
MEMORY DATA
LOCATION
4500 05

OUTPUT:

KGiSL Institution of Technology 711722104115


8 BIT SUBTRACTION
8 Bit Subtraction (Immediate Addressing)
ADDRES LABE MNEMONIC HEX COMMENTS
S L CODE
$MOD51
4100 MOV A, #03 74, data1 Store data1 in acc
4101 SUBB A, #02 94,data2 Subtract data2 from
data1
4103 MOV DPTR, # 90,45,00 Initialize memory
4500 location
4105 MOVX @ F0 Store difference in
DPTR, A 4500
4108 STOP: SJMP STOP 80,FE Stop

OBSERVATION:
#data1= 03
#data2= 02
MEMORY DATA
LOCATION
4500 01

OUTPUT:

KGiSL Institution of Technology 711722104115


PROGRAM: 8 Bit Multiplication
ADDRES LABE MNEMONIC HEX COMMENTS
S L CODE
$MOD51
4100 MOV A ,#03 74, 03 Store data1 in acc
4102 MOV B, #02 75,02 Store data2 in B reg
4104 MUL AB F5,F0 Multiply both
4106 MOV DPTR, 90,45,00 Initialize memory
#4500H location
4109 MOVX @DPTR, F0 Store lower order
A result
401A INC DPTR A3 Go to next location
410B MOV A,B E5,F0 Store higher order
410D MOV @DPTR, A F0 result
410E STOP: SJMP STOP 80,FE Stop

OBSERVATION:
#data1= 03
#data2= 02
MEMORY DATA
LOCATION
4500 (LSB) 01
4501 (MSB) 00

OUTPUT:

KGiSL Institution of Technology 711722104115


PROGRAM:LOGICAL OR OPERATION:

ADDRES HEX LABE MNEMONICS COMMENT


S CODE L
$MOD51
4100 74 2F MOV A,#2FH Move first data to A
reg
4102 44 45 ORL A,#45H OR first data1 with
data2
4104 90 45 00 MOV Store at location
DPTR,#4500H 4500
4107 F0 MOVX @DPTR,A
4108 80 FE STOP: SJMP STOP

OBSERVATION:
#data1=
2F
#data2=
4E
MEMORY DATA
LOCATION
4500 6F

OUTPUT:

KGiSL Institution of Technology 711722104115


LOGICAL AND OPERATION:
ADDRES HEX LABE MNEMONICS COMMENT
S CODE L
$MOD51
4100 74 87 MOV A,#87H Move first data to A
reg
4102 54 7E ANL A, #7EH AND first data1
with data2
4104 90 45 00 MOV DPTR, Store at location
#4500H 4500
4107 F0 MOVX @DPTR,A
4108 80 FE STOP: SJMP STOP

OBSERVATION:
#data1= 87
#data2=7E
MEMORY DATA
LOCATION
4500 06

OUTPUT:

KGiSL Institution of Technology 711722104115


LOGICAL XOR OPERATION:

ADDRES HEX LABE MNEMONICS COMMENT


S CODE L
$MOD51
4100 74 87 MOV A,#87H Move first data to A
reg
4102 54 7E XRL A,#7EH AND first data1
with data2
4104 90 45 00 MOV Store at location
DPTR,#4500H 4500
4107 F0 MOVX @DPTR,A
4108 80 FE STOP: SJMP STOP

OBSERVATION:
#data1 = 87
#data2 = 7E
MEMORY DATA
LOCATION
4500 F9

OUTPUT:

RESULT:

The arithmetic and logical programs have been executed successfully.

KGiSL Institution of Technology 711722104115


EXP NO : 04 To implement the basic Arduino Programming
DATE :

AIM:

To implement the basic Arduino Programming.

APPARATUS REQUIRED:

Arduino UNO Board, PC, Connecting wires

ALGORITHM:

1. Initialize serial communication at a baud rate of 9600 in the setup() function.


2. Enter the main loop.
3. Inside the loop, print "Hello World!" followed by a newline character to the serial
monitor using Serial.println().
4. Repeat step 3 indefinitely.

PROGRAM : 1

// To print the text in serial monitor

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);
}

void loop() {

// put your main code here, to run repeatedly:

Serial.println("Hello World!");
}

KGiSL Institution of Technology 711722104115


OUTPUT:

ALGORITHM:

1. Initialize serial communication.


2. Enter the main loop.
3. Read the analog value from LM35 temperature sensor connected to pin A1 using
analogRead().
4. Convert the analog value to voltage by multiplying it by the conversion factor 4.88
(5V / 1024).
5. Convert the voltage to temperature in degrees Celsius by dividing it by 10 (LM35
sensor output is 10mV per degree Celsius).
6. Print the temperature value to the serial monitor with appropriate labels.
7. Repeat steps 3 to 6 with a delay of 1000 milliseconds between readings.

KGiSL Institution of Technology 711722104115


PROGRAM : 2

To print the temperature values in serial monitor


CIRCUIT DIAGRAM

LM 35 ARDUINO UNO

GND GND

VCC 5V

OUT A0

const int lm35_pin = A1; /* LM35 O/P pin */


void setup()
{
Serial.begin(9600);
}
void loop() {
int temp_adc_val;
float temp_val;
temp_adc_val = analogRead(lm35_pin); /* Read Temperature */
temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */
temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print(" Degree Celsius\n");
delay(1000);
}
KGiSL Institution of Technology 711722104115
OUTPUT:

ALGORITHM:

1. Initialize serial communication.


2. Enter the main loop.
3. Read the digital value from the obstacle sensor connected to the obstaclePin using
digitalRead().
4. If the sensor detects an obstacle (HIGH signal), print "Stop something is ahead!!"
to the serial monitor.
5. If the sensor does not detect an obstacle (LOW signal), print "Path is clear" to the
serial monitor.
6. Repeat steps 3 to 5 with a delay of 2000 milliseconds between readings.

KGiSL Institution of Technology 711722104115


PROGRAM : 3

To print the IR sensor value in serial monitor


CIRCUIT DIAGRAM

IR SENSOR ARDIUNO UNO

GND GND

VCC 5V

OUT A0

void setup()
{
//pinMode(LEDpin, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
hasObstacle = digitalRead(obstaclePin);
if (hasObstacle == HIGH) {
Serial.println("Stop something is ahead!!");
//digitalWrite(LEDpin, HIGH);
}
else
if (hasObstacle == LOW){
Serial.println("Path is clear");
//digitalWrite(LEDpin, LOW);
}
delay(2000);
}

KGiSL Institution of Technology 711722104115


OUTPUT:

ALGORITHM:

1. Initialize serial communication.


2. Enter the main loop.
3. Read data from the DHT11 sensor connected to pin 4 using the DHT11 library.
4. Print the humidity and temperature readings to the serial monitor.
5. Repeat steps 3 to 4 with a delay of 2000 milliseconds between readings.

KGiSL Institution of Technology 711722104115


PROGRAM 4:
//DHT
#include <dht11.h>
#define DHT11PIN 4
dht11 DHT11;
void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);
delay(2000);

OUTPUT:

KGiSL Institution of Technology 711722104115


ALGORITHM:

1. Initialize serial communication.


2. Enter the main loop.
3. Read the analog value from the LDR (Light Dependent Resistor) sensor connected
to pin A0 using analogRead().
4. Print the LDR value to the serial monitor.
5. Repeat steps 3 to 4 with a delay of 1000 milliseconds between readings.

PROGRAM 5:

const int LDR =

A0; int input_val


= 0; void setup()
{

Serial.begin(9600);

void loop()

input_val = analogRead(LDR);

Serial.print("LDR Value is: ");

Serial.println(input_val);

delay(1000);
}

KGiSL Institution of Technology 711722104115


OUTPUT:

RESULT:

Thus the Arduino programs have been successfully implemented.

KGiSL Institution of Technology 711722104115


EXP NO: 05 Introduction to RP2040 with python programming
DATE :

AIM:
To implement the RP2040 carrier board with python programming.

COMPONENDS RECQUIRED:

• RP2040 carrier board


• Sensors
• Power chard

ALGORITHM:

1. Initialize two pins (2 and 3) as output pins for LEDs.

2. Enter an infinite loop.

3. Turn on LED2 and wait for 200 milliseconds.

4. Turn on LED3.

5. Turn off LED2 and wait for 200 milliseconds.

6. Turn off LED3.

7. Repeat steps 3-6 indefinitely to create a blinking pattern between the two LEDs.

PROGRAM:

1. LED blink(Digital Output)

from machine import Pin

from time import *

led2=Pin(2,Pin.OUT)

KGiSL Institution of Technology 711722104115


led3=Pin(3,Pin.OUT)

while True:

led2.value(1)

sleep_ms(200)

led3.value(1)

led2.value(0)

sleep_ms(200)

led3.value(0)

OUTPUT:

KGiSL Institution of Technology 711722104115


ALGORITHM:

1. Initialize an LCD display with GPIO pins for control signals and data lines.

2. Set the initial count to 0.

3. Print "Hi hello" on the first line of the LCD display.

4. Print "my count :" on the second line of the LCD display.

5. Enter an infinite loop.

6. Increment the count variable by 1.

7. Update the LCD display with the current count value.

8. Wait for 1 second before repeating the loop.

PROGRAM

1. Print text

from machine import Pin

from gpio_lcd import GpioLcd

import time

count=0

lcd = GpioLcd(rs_pin = Pin(8),

enable_pin = Pin(9),

d4_pin = Pin(10),

d5_pin = Pin(11),

d6_pin = Pin(12),

d7_pin = Pin(13))
lcd.move_to(0,0)

lcd.putstr("Hi hello")
KGiSL Institution of Technology 711722104115
lcd.move_to(0,1)

lcd.putstr("my count :")

while True:

count=count+1

lcd.move_to(13,1)

lcd.putstr(str(count))

time.sleep(1)

OUTPUT:

ALGORITHM:

1. Initialize a pin (Pin 6) as an output pin for the buzzer.

2. Enter an infinite loop.

3. Turn on the buzzer by setting its value to 1.

4. Wait for 0.2 seconds.

KGiSL Institution of Technology 711722104115


5. Turn off the buzzer by setting its value to 0.

6. Wait for 1 second before repeating the loop

PROGRAM BUZZER

from machine import Pin

import time

Buzzer = Pin(6, Pin.OUT)

while True:

Buzzer.value(1)

time.sleep(0.2)

Buzzer.value(0)

time.sleep(1)

OUTPUT:

KGiSL Institution of Technology 711722104115


ALGORITHM:

1. Initialize three pins (2, 3, and 6) as output pins for LEDs.

2. Define the memory address for the Serial I/O (SIO) module.

3. Enter an infinite loop.

4. Write the value 0x0200000c to the SIO register offset 0x014 to turn on LED1.

5. Wait for 500 milliseconds.

6. Write the value 0x0200000c to the SIO register offset 0x018 to turn off LED1 and
turn on LED2.

7. Wait for 500 milliseconds.

8. Repeat steps 4-7 indefinitely to create a blinking pattern between LED1 and LED2.

PROGRAM SIO_LED

from machine import mem32,Pin

from time import sleep_ms

led1=Pin(2,mode=Pin.OUT)

led2=Pin(3,mode=Pin.OUT)

led3=Pin(6,mode=Pin.OUT)

addrSIO = 0xd0000000
while True:

mem32[addrSIO + 0x014] = 0x0200000c

sleep_ms(500)

mem32[addrSIO + 0x018] = 0x0200000c

sleep_ms(500)

KGiSL Institution of Technology 711722104115


OUTPUT:

RESULT:

Thus experiments to implement the RP2040 carrier board with python programming is
conducted successfully.

KGiSL Institution of Technology 711722104115


EXP NO :06 Write basic arithmetic program using Embedded C
DATE :

AIM:
To implement the basic arithmetic program using Embedded C.

APPARATUS REQUIRED:
PC, RIDE Software

ALGORITHM:
1. Set variable a to the hexadecimal value 0x10 (16 in decimal).
2. Set variable b to the hexadecimal value 0x04 (4 in decimal).
3. Subtract the value of b from a and store the result in Port 0 (P0).
4. Add the values of a and b together and store the result in Port 1 (P1).
5. Multiply the values of a and b together and store the result in Port 2 (P2).
6. Divide the value of a by b and store the result in Port 3 (P3).

PROGRAM:

#include <reg51.h>

unsigned char a, b;
unsigned int c;

void main() {
a = 0x10;
b = 0x04;

P0 = a - b;
P1 = a + b;
P2 = a * b;
P3 = a / b;
while(1);

KGiSL Institution of Technology 711722104115


OUTPUT:

RESULT:
The basic arithmetic program using Embedded C is performed.

KGiSL Institution of Technology 711722104115


EXP NO : 07 Interfacing sensors with Raspberry PI
DATE :

AIM

To implement the interfacing Sensors with RP2040

APPARATUS RECQUIRED:

• RP2040 carrier board


• Sensors
• Power chords

ALGORITHM:

1. Import the necessary modules: Pin from machine and time.


2. Define the conversion factor for converting ADC readings to voltage.
3. Initialize the ADC object adc2 on pin 27.
4. Enter an infinite loop.
5. Read the ADC value using adc2.read_u16().
6. Convert the ADC value to temperature using the conversion factor.
7. Print the temperature value.
8. Pause for 0.8 seconds before repeating the loop.

PROGRAM TEMPERATURE SENSOR (LM35)


from machine import Pin
import time
conversion_factor =
3.3/(65536) adc2=
machine.ADC(27)

while True:
val2 = adc2.read_u16()
temp = (val2 * conversion_factor)*100
print("===============================")
print("temperature:
",temp) time.sleep(0.8)
KGiSL Institution of Technology 711722104115
OUTPUT:

ALGORITHM:

1. Import the Pin and utime modules.


2. Set up a potentiometer value reading (POT_Value) using an analog pin (ADC).
3. Define the conversion factor for the analog-to-digital conversion.
4. Enter an infinite loop.
5. Read the potentiometer value using POT_Value, scale it using the conversion
factor, and print the result.
6. Wait for 1 second using utime.sleep(1).
7. Repeat steps 5 and 6 indefinitely.

PROGRAM:
Potentiometer
from machine import Pin
import utime

POT_Value =
machine.ADC(28)
conversion_factor =
KGiSL Institution of Technology 711722104115
3.3/(65535)

while True:
#print(POT_Value.read_u1
6() )

OUTPUT:

ALGORITHM:

1. Import the Pin and time modules.


2. Set up pins for relay (Relay), LED (l), and another LED (l1).
3. Enter an infinite loop.
4. Turn on l and turn off l1.
5. Pause for 0.1 seconds.
6. Toggle the relay state.
7. Turn on l1 and turn off l.
8. Pause for 0.1 seconds before repeating.

KGiSL Institution of Technology 711722104115


PROGRAM: Relay

from machine import Pin


import time
Relay = Pin(7, Pin.OUT)
l= Pin(2, Pin.OUT)
l1= Pin(3, Pin.OUT)
while True:
Relay.value(0)
l.on()
l1.off()
time.sleep(0.1)
Relay.value(1)
l1.on()
l.off()
time.sleep(0.1)

OUTPUT:

RESULT:

The interfacing of sensors with Raspberry pi has been performed.

KGiSL Institution of Technology 711722104115


KGiSL Institution of Technology 711722104115
EXP NO: 08 Explore different communication methods with IoT
DATE : Device (Zigbee,GSM,Bluetooth)

AIM:

To implement the different communications with IOT Device like Zigbee, GSM,
Bluetooth.

APPARATUS REQUIRED:
Arduino UNO Kit, Bluetooth Interface, Zigbee Interface -2, Connecting wires

ALGORITHM:

1. Connect Arduino pins 10 and 11 to Bluetooth module's Tx and Rx pins


respectively. Also, connect GND to GND and 5V to VCC.
2. Initialize a SoftwareSerial object named 'bt' with pins 10 (Rx) and 11 (Tx).
3. Begin serial communication with both Arduino and the Bluetooth module at a baud
rate of 9600.
4. Send initial garbage data to Bluetooth module.
5. Check if there's any data available on the Bluetooth module's serial port.
6. If data is available, read it and send it to the Serial monitor.
7. Check if there's any data available on the Serial monitor.
8. If data is available, read it and send it to the Bluetooth module.

KGiSL Institution of Technology 711722104115


PROGRAM:

Bluetooth:
bluetooth
/* Arduino Bluetooth
10 Tx
11 Rx
gnd gnd
5v vcc */

#include<SoftwareSerial.h>

/* Create object named bt of the class SoftwareSerial */


SoftwareSerial bt(10,11); /* (Rx,Tx) */

void setup() {
bt.begin(9600); /* Define baud rate for software serial communication */
Serial.begin(9600); /* Define baud rate for serial communication */
bt.write("garbage");
}

void loop()
{

if (bt.available()) /* If data is available on serial port */

Serial.write(bt.read()); /* Print character received on to the serial monitor */


/*delay(5);8*/
if (Serial.available())

bt.write(Serial.read());

KGiSL Institution of Technology 711722104115


OUTPUT:

ALGORITHM:
1. Initialize communication with SIM900A and Serial Monitor.
2. Print "SIM900A Ready" and "Type s to send message".
3. Check for input from Serial Monitor.
4. If 's' is received, call SendMessage() function.
5. Check for input from SIM900A.
6. If data available, send it to Serial Monitor.
7. Set GSM Module in Text Mode.
8. Set SMS Number and Content.
9. Send message and print confirmation.

PROGRAM: GSM CODE FOR SENDING SMS


// Download Library of SoftwareSerial link :
https://github.com/PaulStoffregen/SoftwareSerial #include
<SoftwareSerial.h>
SoftwareSerial SIM900A(10,11); // SoftSerial( RX , TX );
// 10 pin connect to TX of GSM SIM 900 Module
// 11 pin connect to RX of GSM SIM 900 Module
// gsm gnd to Arduino gnd

KGiSL Institution of Technology 711722104115


KGiSL Institution of Technology 711722104115
void setup()
{
SIM900A.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor
(Arduino) Serial.println ("SIM900A Ready");
delay(100);
Serial.println ("Type s to send message ");
}
void loop()
{
if
(Serial.available()>
0)
switch(Serial.read()
)
{
case 's':
SendMessage
(); break;
}
if (SIM900A.available()>0)
Serial.write(SIM900A.read(
));
}
void SendMessage()
{
Serial.println ("Sending Message");
SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in
Text Mode delay(1000);
Serial.println ("Set SMS Number");
SIM900A.println("AT+CMGS=\"9790685877\"\r"); //Write Mobile number to
send message delay(1000);
Serial.println ("Set SMS
Content");
SIM900A.println("hi");// Messsage
content delay(100);
Serial.println ("Finish");
KGiSL Institution of Technology 711722104115
SIM900A.println((char)26);// ASCII code of
CTRL+Z delay(1000);
Serial.println ("Message has been sent ->SMS Selesai dikirim");
}

OUTPUT:

ALGORITHM:
1. Initialize communication with SIM900A and Serial Monitor.
2. Print "SIM900A Ready" and "Type r to receive message".
3. Check for input from Serial Monitor.
4. If 'r' is received, call ReceiveMessage() function.
5. Check for input from SIM900A.
6. If data available, send it to Serial Monitor.
7. Print "SIM900A Membaca SMS".
8. Set up SIM900A to receive live SMS.
9. Print "Unread Message done".

KGiSL Institution of Technology 711722104115


PROGRAM CODE FOR SENDING SMS
// Techatronic.com
// Download Library of SoftwareSerial link given
//https://github.com/PaulStoffregen/Softwar
Serial
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(10,11); // SoftSerial( RX , TX );
// 10 pin connect to TX of GSM SIM 900 Module
// 11 pin connect to RX of GSM SIM
900 Module void setup()
{
SIM900A.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor
(Arduino) Serial.println ("SIM900A Ready");
delay(100);
Serial.println ("Type r to receive message");
}
void loop()
{
if
(Serial.available()>
0)
switch(Serial.read()
)
{
case 'r':
RecieveMessage();
break;
}
if (SIM900A.available()>0)
Serial.write(SIM900A.read(
));
}
void RecieveMessage()
{
Serial.println ("SIM900A
KGiSL Institution of Technology 711722104115
Membaca SMS"); delay (1000);
SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to
receive a live SMS delay(1000);
Serial.write ("Unread Message done");
}

OUTPUT:

Verified.

ZIGBEE:
1. Click Discover radio modules from the toolbar.
2. In the Discover radio modules dialog, select the serial port(s) in which you want
to look for radio modules. If you do not know the serial ports where your modules
are attached, select all ports. Click Next.
3. In the Set port parameters window, maintain the default values and click Finish.
4. As XCTU locates radio modules, they appear in the Discovering radio modules…
dialog box. Once the discovery process has finished, click Add selected devices.
5. At this point, assuming you have three modules connected to your computer, you
should see something like this in the Radio Modules section on the left
6. Communicate between Coordinator and Enduser.

RESULT:
The programs for Bluetooth, GSM and Zigbee has been performed.

KGiSL Institution of Technology 711722104115


KGiSL Institution of Technology 711722104115
EXP NO: 09 Setup a cloud platform to log the data
DATE :

AIM

To implement and setup the cloud platform to log on the data.

APPARATUS:

PC, Blynk Account

PROCEDURE:

1. Create a Blynk account using Blynk.Console or Blynk.App for iOS or Android.


2. Switch to Developer Mode in Blynk.Console or Blynk.App
3. Have a supported hardware (ESP32, Arduino, Raspberry Pi, etc).
4. Add components.

ALGORITHM:
1. Import necessary libraries: time, network, Pin from machine, and BlynkLib.
2. Set up the Wi-Fi connection.
3. Define the Blynk authentication token (BLYNK_AUTH).
4. Connect to the Blynk server.
5. Initialize the pins connected to the relays.
6. Define virtual pin handlers for controlling relays.
7. Continuously run the Blynk service and update a virtual pin every 2 seconds.

PROGRAM:

import time
import network
from machine import Pin
import BlynkLib

wlan =
KGiSL Institution of Technology 711722104115
network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("ArNet","12345678")

BLYNK_AUTH =

'yMsd4X4WnSiZQ9pZsXiOuJTy5nopIz4i' # Wait for

network connection
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >=
3: break
wait -= 1
print('waiting for connection...')
time.sleep(1)

# Handle connection
error if wlan.status()
!= 3:
raise RuntimeError('network connection
failed') else:
print('connected')
ip = wlan.ifconfig()[0]
print('IP: ', ip)

# Connect to Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Initialize the relay pins


relay1_pin = Pin(2,
Pin.OUT) relay2_pin =
Pin(3, Pin.OUT) relay3_pin
= Pin(6, Pin.OUT)
relay4_pin = Pin(7,
Pin.OUT)

KGiSL Institution of Technology 711722104115


# Register virtual pin
handler @blynk.on("V1")
#virtual pin V1
def v1_write_handler(value): #read the
value if int(value[0]) == 1:
relay1_pin.value(1) #turn the
relay1 on else:
relay1_pin.value(0) #turn the relay1 off
@blynk.on("V2") #virtual pin V2
def v2_write_handler(value): #read the
value if int(value[0]) == 1:
relay2_pin.value(1) #turn the
relay2 on else:
relay2_pin.value(0) #turn the relay2 off

@blynk.on("V3") #virtual pin V3


def v3_write_handler(value): #read the
value if int(value[0]) == 1:
relay3_pin.value(1) #turn the
relay3 on else:
relay3_pin.value(0) #turn the relay3 off

@blynk.on("V4") #virtual pin V4


def v4_write_handler(value): #read the
value if int(value[0]) == 1:
relay4_pin.value(1) #turn the
relay4 on else:

KGiSL Institution of Technology 711722104115


relay4_pin.value(0) #turn the relay4
off while True:
blynk.run()
blynk.virtual_write(5, 33)
time.sleep(2)

OUTPUT:

RESULT:

The cloud platform has been setup to log data.

KGiSL Institution of Technology 711722104115


EXP NO: 10
Log Data using Raspberry PI and upload to the cloud
DATE : platform

AIM:

To log data using Raspberry PI and upload to the cloud platform

APPARATUS:

PC, Raspberry Pi, Connecting wires

ALGORITHM:

1. mport necessary modules: utime, network, Pin, BlynkLib.


2. Configure Wi-Fi connection and Blynk authentication token.

3. Wait for network connection and print IP address.


4. Initialize ultrasonic sensor pins.
5. Continuously read distance measurements from the ultrasonic sensor:
• Trigger the sensor and measure the time for the echo signal.

• Calculate the distance and print/send it to the Blynk server.


6. Repeat the process indefinitely with a 2-second delay between iterations.

PROGRAM:

import
utime import
network
from machine import
Pin import BlynkLib

wlan =
network.WLAN(network.STA_IF)
wlan.active(True)
KGiSL Institution of Technology 711722104115
wlan.connect("ArNet","12345678")

BLYNK_AUTH =

'yMsd4X4WnSiZQ9pZsXiOuJTy5nopIz4i' #

Wait for network connection


wait = 10
while wait > 0:
if wlan.status() < 0 or
wlan.status() >= 3: break
wait -= 1
print('waiting for
connection...')
time.sleep(1)

# Handle
connection error if
wlan.status() != 3:
raise RuntimeError('network
connection failed') else:
print('connected')
ip =
wlan.ifconfig()[0]
print('IP: ', ip)

# Connect to Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Initialize the
ultrasonic pins trigger
= Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)

KGiSL Institution of Technology 711722104115


while True:
trigger.low()
utime.sleep_us
(2)
trigger.high()
utime.sleep_us
(5)
trigger.low()
while echo.value() == 0:
signaloff =
utime.ticks_us() while
echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon -
signaloff distance =
(timepassed * 0.0343) / 2
print("Total
distance",distance,"cm")
print("sensor")
blynk.run()
blynk.virtual_write(4,
distance) utime.sleep(2)

OUTPUT:

RESULT:

The program to Log Data using Raspberry PI and upload to the cloud platform has been
performed successfully.

KGiSL Institution of Technology 711722104115


KGiSL Institution of Technology 711722104115
KGiSL Institution of Technology 711722104115
EXP NO: 11 Communicate between Arduino and Raspberry Pi
DATE :

AIM
To write and execute the program to Communicate between Arduino and
Raspberry PI using any wireless medium (Bluetooth)

APPARATUS REQUIRED

S.NO. Hardware & Software Quantit


Requirement y
1 Thonny IDE 1
2 Raspberry Pi Pico Development 1
Board
3 Arduino Uno Development Board 1
4 Jumper Wires Few
5 Micro USB Cable 1
6 Micro USB Cable 2

ALGORITHM
1. Set up a software serial communication with pins 2 and 3.
2. In the setup() function, initialize the software serial communication at a baud rate
of 9600.
3. Send the character 'A', then wait for 1 second.
4. Send the character 'B', then wait for 1 second. Repeat indefinitely.

ALGORITHM:

1. Initialize UART communication on UART0 with a baud rate of 9600.


2. Define a GPIO pin 16 as an output pin for controlling an LED.
3. Enter an infinite loop to continuously monitor UART communication.
4. If there is incoming data on UART, read the data.
5. If the received data contains 'A', turn on the LED, print a message, and send a
confirmation message via UART.
6. If the received data contains 'B', turn off the LED, print a message, and send a
confirmation message via UART.
KGiSL Institution of Technology 711722104115
CONNECTIONS IN ARDUINO

Arduino UNO Arduino Development Bluetooth


Pin Board Module
2 - Tx
3 - Rx
- GND GND
- 5V 5V

PROGRAM:
MASTER ARDUINO :
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3);
//rx,tx void setup() {
mySerial.begin(9600);
}
void loop() {
mySerial.write('
A');
delay(1000);
mySerial.write('
B');
delay(1000);
}

CONNECTIONS IN RASPBERRY PI

Raspberry Pi Pico Raspberry Pi Pico Development Bluetooth


Pin Board Module
GP16 LED -
Vcc - +5V
GND - GND
GP1 - Tx
GP0 - Rx

KGiSL Institution of Technology 711722104115


PROGRAM:
SLAVE RASPBERRY PI PICO

from machine import Pin,


UART uart = UART(0,
9600)
led = Pin(16,
Pin.OUT) while
True:
if uart.any() > 0:
data = uart.read()
print(data)
if "A" in data:
led.value(1)
print('LED on \n')
uart.write('LED on
\n') elif "B" in
data:
led.value(0)
print('LED off \n')
uart.write('LED off
\n')

OUTPUT:

RESULT:

The communication between Arduino and Raspberry Pi is successfully conducted.

KGiSL Institution of Technology 711722104115


KGiSL Institution of Technology 711722104115
EXP NO: 12 Design an IOT based system
DATE :

AIM:

To implement an IOT based Home Automation with ESP32 using Thinkspeak.

APPARATUS RECQUIRED:

• ESP 32 node MCU


• Home Devices

ALGORITHM:

1. Set up WiFi credentials and device names.


2. Connect to WiFi network and initialize WiFi mode.
3. Define GPIO pins connected to relays, LED, and Bluetooth.
4. Define callback functions to control relays based on brightness levels.
5. Define functions to connect to WiFi and add devices for voice control.
6. Implement functions to control relays via Bluetooth commands.
7. Define functions to toggle all relays on or off.
8. Initialize serial communication and preferences for relay states.
9. Set up GPIO pins as outputs and initialize relay states.
10. Check WiFi connection status and control relays accordingly.
11. Continuously loop to handle WiFi and Bluetooth control

PROGRAM:

// WiFi Credentials
const char* ssid = "Home";
const char* password = "Password123";
// device names
String Device_1_Name =
"device one"; String
Device_2_Name = "device
two"; String Device_3_Name
KGiSL Institution of Technology 711722104115
= "device three"; String
Device_4_Name = "device
four";

#include <WiFi.h>
#include
<Espalexa.h>
#include
<Preferences.h>
#include
<IRremote.h>

Preferences
pref; Espalexa
espalexa;

// define the GPIO connected with


Relays and switches #define RelayPin1
14 //D23
#define RelayPin2
15 //D22 #define
RelayPin3 13 //D21
#define RelayPin4
27 //D19

#define wifiLed 2
//D2 #define RX2Pin
16 //
RX2 #define TX2Pin
17 //
TX2

// Relay State
bool toggleState_1 = LOW; //Define integer to remember
the toggle state for relay 1 bool toggleState_2 = LOW;
//Define integer to remember the toggle state for relay 2
bool toggleState_3 = LOW; //Define integer to remember
the toggle state for relay 3 bool toggleState_4 = LOW;
//Define integer to remember the toggle state for relay 4
KGiSL Institution of Technology 711722104115
String bt_data = ""; // variable for storing
bluetooth data int currSpeed = 0;
bool first_run =
true; int
wifiFlag = 0;
decode_results
results;

// prototypes
boolean connectWifi();

//callback functions
void firstLightChanged(uint8_t
brightness); void
secondLightChanged(uint8_t
brightness); void
thirdLightChanged(uint8_t
brightness); void
fourthLightChanged(uint8_t
brightness)

boolean wifiConnected = false;


//our callback functions
void firstLightChanged(uint8_t brightness)
{
//Control the
device if
(brightness ==
255)
{
digitalWrite(RelayPin1,
LOW);
Serial.println("Device1
ON"); toggleState_1 = 1;
}
else
{
digitalWrite(RelayPin1,
KGiSL Institution of Technology 711722104115
HIGH);
Serial.println("Device1
OFF"); toggleState_1 = 0;
}
pref.putBool("Relay1", toggleState_1);
}

void secondLightChanged(uint8_t brightness)


{
//Control the
device if
(brightness ==
255)
{
digitalWrite(RelayPin2,
LOW);
Serial.println("Device2
ON"); toggleState_2 = 1;
}
else
{
digitalWrite(RelayPin2, HIGH);

Serial.println("Device2
OFF"); toggleState_2 = 0;
}
pref.putBool("Relay2", toggleState_2);
}

void thirdLightChanged(uint8_t brightness)


{
//Control the
device if
(brightness ==
255)
{
digitalWrite(RelayPin3,
LOW);
Serial.println("Device3
ON"); toggleState_3 = 1;
}
KGiSL Institution of Technology 711722104115
else
{
digitalWrite(RelayPin3,
HIGH);
Serial.println("Device3
OFF"); toggleState_3 = 0;
}
pref.putBool("Relay3", toggleState_3);
}
void fourthLightChanged(uint8_t brightness)
{
//Control the
device if
(brightness ==
255)
{
digitalWrite(RelayPin4,
LOW);
Serial.println("Device4
ON"); toggleState_4 = 1;
}
else
{
digitalWrite(RelayPin4,
HIGH);
Serial.println("Device4
OFF"); toggleState_4 = 0;
}
pref.putBool("Relay4", toggleState_4);
}

// connect to wifi – returns true if successful


or false if not boolean connectWifi()
{
boolean state
= true; int i =
0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,
KGiSL Institution of Technology 711722104115
password);
Serial.println("");
Serial.println("Connecting
to WiFi");

// Wait for
connection
Serial.print("Connec
ting...");
while (WiFi.status() !=
WL_CONNECTED) {
delay(500);
Serial.print(
"."); if (i >
20) {
state = false; break;
}
i+
+;
}
Serial.println
(""); if
(state) {
Serial.print("Connecte
d to ");
Serial.println(ssid);
Serial.print("IP
address: ");
Serial.println(WiFi.loc
alIP());
}
else {
Serial.println("Connection failed.");
}
return state;
}

void addDevices(){
// Define your devices here.
espalexa.addDevice(Device_1_Name, firstLightChanged); //simplest
definition, default state off espalexa.addDevice(Device_2_Name,
KGiSL Institution of Technology 711722104115
secondLightChanged); espalexa.addDevice(Device_3_Name,
thirdLightChanged); espalexa.addDevice(Device_4_Name,
fourthLightChanged);

espalexa.begin();
}

void sendFeedback(int relay, int value){


EspalexaDevice* d = espalexa.getDevice(relay); //the
index is zero-based if(relay == 4){
d->setPercent(map(value, 0, 4, 0, 100)); //set value "brightness" in percent
}
else{
d->setPercent(value);
}
}
void bluetooth_control()
{
if(Serial2.available())
{ bt_data =
Serial2.readString();
//Serial.println(bt_data.substring(bt_data.lastIndexOf(",") + 1));
if (bt_data.substring(bt_data.lastIndexOf(",") + 1) == "A1"){
digitalWrite(RelayPin1, LOW); toggleState_1 = 1; // if "A1" received Turn
on Relay1 pref.putBool("Relay1", toggleState_1);
sendFeedback(0, 100);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"A0"){ digitalWrite(RelayPin1, HIGH); toggleState_1 = 0; //
if "A0" received Turn off Relay1

KGiSL Institution of Technology 711722104115


pref.putBool("Relay1",
toggleState_1);
sendFeedback(0, 0);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"B1"){ digitalWrite(RelayPin2, LOW); toggleState_2 = 1; //
if "B1" received Turn on Relay2 pref.putBool("Relay2",
toggleState_2);
sendFeedback(1, 100);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"B0"){ digitalWrite(RelayPin2, HIGH); toggleState_2 = 0; //
if "B0" received Turn off Relay2 pref.putBool("Relay2",
toggleState_2);
sendFeedback(1, 0);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"C1"){ digitalWrite(RelayPin3, LOW); toggleState_3 = 1; //
if "C1" received Turn on Relay3 pref.putBool("Relay3",
toggleState_3);
sendFeedback(2, 100);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"C0"){ digitalWrite(RelayPin3, HIGH); toggleState_3 = 0; //
if "C0" received Turn off Relay3 pref.putBool("Relay3",
toggleState_3);
sendFeedback(2, 0);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"D1"){ digitalWrite(RelayPin4, LOW); toggleState_4 = 1; //
if "D1" received Turn on Relay4 pref.putBool("Relay4",
toggleState_4);
sendFeedback(3, 100);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) ==
"D0"){ digitalWrite(RelayPin4, HIGH); toggleState_4 = 0; //
if "D0" received Turn off Relay4 pref.putBool("Relay4",
toggleState_4);
sendFeedback(3, 0);
}
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) == "Z1"){ // if
"Z1" received Turn on all Relays all_SwitchOn();
}
KGiSL Institution of Technology 711722104115
else if(bt_data.substring(bt_data.lastIndexOf(",") + 1) == "Z0"){ // if
"Z0" received Turn off all Relays all_SwitchOff();
}
}
}

void all_SwitchOn(){
toggleState_1 = 1; digitalWrite(RelayPin1, LOW); pref.putBool("Relay1",
toggleState_1); sendFeedback(0, 100); delay(100);
toggleState_2 = 1; digitalWrite(RelayPin2, LOW); pref.putBool("Relay2",
toggleState_2); sendFeedback(1, 100); delay(100);
toggleState_3 = 1; digitalWrite(RelayPin3, LOW); pref.putBool("Relay3",
toggleState_3); sendFeedback(2, 100); delay(100);
toggleState_4 = 1; digitalWrite(RelayPin4, LOW); pref.putBool("Relay4",
toggleState_4); sendFeedback(3, 100); delay(100);
}
void all_SwitchOff(){
toggleState_1 = 0; digitalWrite(RelayPin1, HIGH); pref.putBool("Relay1", toggleState_1);
sendFeedback(0, 0); delay(100);

toggleState_2 = 0; digitalWrite(RelayPin2, HIGH); pref.putBool("Relay2",


toggleState_2); sendFeedback(1, 0); delay(100); toggleState_3 = 0;
digitalWrite(RelayPin3, HIGH); pref.putBool("Relay3", toggleState_3);
sendFeedback(2, 0); delay(100); toggleState_4 = 0; digitalWrite(RelayPin4, HIGH);
pref.putBool("Relay4", toggleState_4); sendFeedback(3, 0); delay(100);
}

void getRelayState()
{
//Serial.println("reading data
from NVS"); toggleState_1 =
pref.getBool("Relay1", 0);
digitalWrite(RelayPin1,
!toggleState_1);
(toggleState_1 == false) ? sendFeedback(0, 0) :
sendFeedback(0, 100); delay(200);
toggleState_2 = pref.getBool("Relay2", 0);
digitalWrite(RelayPin2, !toggleState_2);
(toggleState_2 == false) ? sendFeedback(1, 0) :
KGiSL Institution of Technology 711722104115
sendFeedback(1, 100); delay(200);
toggleState_3 = pref.getBool("Relay3", 0);
digitalWrite(RelayPin3, !toggleState_3);
(toggleState_3 == false) ? sendFeedback(2, 0) :
sendFeedback(2, 100); delay(200);
toggleState_4 = pref.getBool("Relay4", 0);
digitalWrite(RelayPin4, !toggleState_4);
(toggleState_4 == false) ? sendFeedback(3, 0) :
sendFeedback(3, 100); delay(200);
}

void setup()
{
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RX2Pin, TX2Pin);
//Open namespace in read-
write mode
pref.begin("Relay_State",
false);
pinMode(RelayPin1,
OUTPUT);
pinMode(RelayPin2,
OUTPUT);
pinMode(RelayPin3,
OUTPUT);
pinMode(RelayPin4,
OUTPUT);

pinMode(wifiLed, OUTPUT);
//During Starting all Relays should TURN
OFF digitalWrite(RelayPin1,
!toggleState_1); digitalWrite(RelayPin2,
!toggleState_2); digitalWrite(RelayPin3,
!toggleState_3); digitalWrite(RelayPin4,
!toggleState_4);

digitalWrite(wifiLed, LOW);

KGiSL Institution of Technology 711722104115


// Initialise wifi connection
wifiConnected =
connectWifi();
if (wifiConnected)

{
addDevices();
}
else
{
Serial.println("Cannot connect to WiFi. So in Manual Mode");
}
delay(1000);
getRelayState(); //fetch data from NVS Flash Memory
// delay(1000);
}

void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
//Serial.print("WiFi Not Connected
"); digitalWrite(wifiLed, LOW);
//Turn off WiFi LED
}
else
{
//Serial.print("WiFi
Connected ");
digitalWrite(wifiLed,
HIGH);
//WiFi Control
if
(wifiConnect
ed){
espalexa.loop
(); delay(1);
}
else {
wifiConnected = connectWifi(); // Initialise wifi
connection if(wifiConnected){
addDevices();
KGiSL Institution of Technology 711722104115
}
}
}

bluetooth_control(); //Bluetooth Control


}

OUTPUT:

RESULT:

The WiFi and Bluetooth controlled relay system implemented on Raspberry Pi for home
automation is done successfully.

KGiSL Institution of Technology 711722104115

You might also like