IOT - Lab 2024 New
IOT - Lab 2024 New
AIM:
To Write and simulate basic arithmetic program using ASM in 8051 microcontroller.
HARDWARE/SOFTWARE REQUIREMENTS:
1) Keil µ vision version 3
PROCEDURE:
1) Open project and go to new Micro Vision Project.
2) Give a name to project and save it.
3) Select a device for project “target 1”.
4) Select the device name and category as 89C51 under Atmel Category and click on.
5) The project and its folders can be seen on the left side in the project window.
6) Now go to file and add new file from the menu.
7) Save the file with the specific name with .asm extension.
8) Add this .asm extension file to source group folder in the project window by right clicking on
source group folder and selecting existing files to source group 1.
9) Build the project from the build target option in the project tab.
10) Once the project is build with no errors click debug to start debug session.
11) Click on debug mode and then run F5.
12) Give the output in the registered windows and also from peripherals that is I/O ports.
PROGRAM:
MOV A , #05H
MOV R0 , #04H
ADD A , R0
MOV A , #09H
MOV R0 , #06H
SUBB A , R0
MOV A , #0AH
MOV R0 , #02H
DIV A, R0
1
5) AND OPERATION
MOV A , #0FH
MOV R0 , #0FH
ANL A , R0
6) OR OPERATION
MOV A , #00H
MOV R0 , #0FH
ORL A , R0
7) XOR OPERATION
MOV A , #0FH
MOV R0 , #00H
XRL A , R0
2
OUTPUT:
3
3) MULTIPLICATION OF TWO 8 BIT NUMBERS
4
5) AND OPERATION
6) OR OPERATION
5
7) XOR OPERATION
RESULT: Thus the basic arithmetic program using ASM in 8051 microcontroller has been
executed.
6
EXPT.NO:02
DATE: BASIC ARITHMETIC PROGRAM USING EMBEDDED C
AIM:
To Write and simulate basic arithmetic program using embedded C in 8051 microcontroller.
HARDWARE/SOFTWARE REQUIREMENTS:
1) Keil µ vision version 3
PROCEDURE:
1) Open project and go to new Micro Vision Project.
2) Give a name to project and save it.
3) Select a device for project “target 1”.
4) Select the device name and category as 89C51 under Atmel Category and click on.
5) The project and its folders can be seen on the left side in the project.
6) Now go to file and add new file from the menu.
7) Type the embedded C program to be simulated.
8) Save the file with a specific name with .c extension.
9) Add this .c extension file to source group folder in the project window by right clicking on
source group 1 folder and selecting the existing files to source group 1.
10) Built the project from the build target option in the project tab. Once the project is built with
no errors click debug to start debug session.
11) Click on debug mode and then run F5.
12) Give the output in the registered windows and also from peripherals that is I/O ports.
PROGRAM:
#include <reg51.h>
void main()
{
P1 = 0 x 01;
P2 = 0 x 02;
P3 = 0 x 03;
}
b) SIMPLE ADDITION PROGRAM
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x 01;
b = 0 x 02;
c = a + b;
P1 = c;
}
7
c) ADDITION WITH CARRY
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x FF;
b = 0 x 90;
c = a + b;
P1 = c;
P2 = c >> 8;
}
d) SIMPLE SUBTRACTION PROGRAM
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x 02;
b = 0 x 01;
c = a - b;
P1 = c;
}
e) SIMPLE MULTIPLICATION PROGRAM
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x 06;
b = 0 x 03;
c = a * b;
P1 = c;
}
8
f) SIMPLE DIVISION PROGRAM
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x 06;
b = 0 x 03;
c = a / b;
P1 = c;
}
g) SIMPLE MODULO DIVISION PROGRAM
#include <reg51.h>
void main()
{
int a, b, c;
a = 0 x 07;
b = 0 x 02;
c = a % b;
P1 = c;
}
h) SIMPLE PROGRAM FOR PRE INCREMENT
#include <reg51.h>
void main()
{
int a, c;
a = 0 x 07;
c = ++a;
P1 = c;
}
9
i) SIMPLE PROGRAM FOR POST INCREMENT
#include <reg51.h>
void main()
{
int a, c;
a = 0 x 07;
c = a++;
P1 = c;
}
j) SIMPLE PROGRAM FOR PRE DECREMENT
#include <reg51.h>
void main()
{
int a, c;
a = 0 x 07;
c = --a;
P1 = c;
}
k) SIMPLE PROGRAM FOR POST DECREMENT
#include <reg51.h>
void main()
{
int a, c;
a = 0 x 07;
c = a--;
P1 = c;
}
10
OUTPUT:
a) DISPLAY THE GIVEN VALUE TO ALL THE PORT
11
c) ADDITION WITH CARRY
12
e) SIMPLE MULTIPLICATION PROGRAM
13
g) SIMPLE MODULO DIVISION PROGRAM
14
i) SIMPLE PROGRAM FOR POST INCREMENT
15
k) SIMPLE PROGRAM FOR POST DECREMENT
RESULT:
Thus the Embedded C program simulated using 8051 microcontroller in Keil µ vision version.
16
EXPT.NO:03 WRITE 8051 ASSEMBLY LANGUAGE EXPERIMENTS USING
DATE: SIMULATOR
AIM:
To Write and simulate basic ascending, descending, smallest, largest, comparison and swapping
program using ASM in 8051 microcontroller.
HARDWARE/SOFTWARE REQUIREMENTS:
Keil µ vision version 3
PROCEDURE:
1) Open project and go to new Micro Vision Project.
2) Give a name to project and save it.
3) Select a device for project “target 1”.
4) Select the device name and category as 89C51 under Atmel Category and click on.
5) Now go to file and add new file from the menu.
6) Save the file with the specific name with .asm extension.
7) Add this .asm extension file to source group folder in the project window by right clicking on
source group folder and selecting existing files to source group 1.
8) Built the project from the build target option in the project tab. Once the project is built with
no errors click debug to start debug session.
9) Click on debug mode and then run F5.
10) Give the output in the registered windows and also from peripherals that is I/O ports.
PROGRAM:
ORG 0000H;
MOV R0, #50H;
MOV A, @R0;
MOV R2, A;
DEC R2;
INC R0;
MOV B, @R0;
INC R0;
BACK: MOV A, @R0;
CJNE A, B, LOOP;
SJMP LOOP 1;
LOOP: JC LOOP 1;
MOV B, A;
LOOP 1: INC R0;
DJNZ R2, BACK;
NEXT: MOV 60H, B;
END;
17
b) SMALLEST NUMBER FROM AN ARRAY OF 10 NUMBERS
ORG 0000H;
MOV R0, #50H;
MOV A, @R0;
MOV R2, A;
DEC R2;
INC R0;
MOV B, @R0;
INC R0;
BACK: MOV A, @R0;
CJNE A, B, LOOP;
SJMP LOOP 1;
LOOP: JNC LOOP 1;
MOV B, A;
LOOP 1: INC R0;
DJNZ R2, BACK;
NEXT: MOV 60H, B;
END;
18
c) ARRANGE THE NUMBERS IN ASCENDING ORDER
ORG 0000h
MOV R2, #0Ah
AGAIN1: MOV R1, #0Ah
DEC R1
MOV R0, #30h
AGAIN2: MOV a,@R0
INC R0
MOV b,@R0
CJNE a, b, nex1
NEX1: JC Next
XCH a, b
MOV @R0, b
DEC R0
MOV @R0, a
INC R0
NEXT: DJNZ R1, Again2
DJNZ R2, Again1
SJMP $
END
19
d) ARRANGE THE NUMBERS IN DESCENDING ORDER
ORG 0000h
MOV R2, #0Ah
AGAIN 1: MOV R1, #0Ah
DEC R1
MOV R0, #30H
AGAIN 2: MOV a,@R0
INC R0
MOV b,@R0
CJNE a, b, nex1
NEX 1: JNC Next
XCH a, b
MOV @R0, b
DEC R0
MOV @R0,a
INC R0
NEXT: DJNZ R1, Again2
DJNZ R2, Again1
SJMP $
END
20
e) Assume that P1 is an input port connected to a temperature sensor. Write a
program to read the temperature and test it for the value of 75. According to the test
results, place the temperature value into the registers indicated by the following.
If T = 75 then A = 75
If T < 75 then R1 = T
If T >75 then R2 = T
SOLUTION:
21
OUTPUT:
22
c) ARRANGE THE NUMBERS IN ASCENDING ORDER
23
e) COMPARISON
24
f) PROGRAM TO SWAP TWO NOS
RESULT:
Thus the basic arithmetic program using ASM in 8051 microcontroller has been executed.
25
EXPT.NO:04 WRITE BASIC AND ARITHMETIC PROGRAMS USING
DATE: EMBEDDED C
AIM:
To Write and simulate basic arithmetic program using embedded C in 8051 microcontroller.
HARDWARE/SOFTWARE REQUIREMENTS:
1) Keil µ vision version 3
PROCEDURE:
1) Open project and go to new Micro Vision Project.
2) Give a name to project and save it.
3) Select a device for project “target 1”.
4) Select the device name and category as 89C51 under Atmel Category and click on.
5) The project and its folders can be seen on the left side in the project.
6) Now go to file and add new file from the menu.
7) Type the embedded C program to be simulated.
8) Save the file with a specific name with .c extension.
9) Add this .c extension file to source group folder in the project window by right clicking on
source group 1 folder and selecting the existing files to source group 1.
10) Built the project from the build target option in the project tab or by pressing epsilon on the
keyboard.
11) Once the project is built with no errors click debug to start debug session.
12) Click on debug mode and then run F5.
13) Give the output in the registered windows and also from peripherals that is I/O ports.
PROGRAM:
#include <reg51.h>
Void main (void)
{
Unsigned char z;
For (z=0; z<=255; z++)
{
P1= z;
}
}
b) WRITE AN 8051 C PROGRAM TO SEND HEX VALUES FOR ASCII
CHARACTERS OF 0,1,2,3,4,5,A,B,C AND D TO PORT P1.
#include <reg51.h>
Void main (void)
{
Unsigned char my num[] = “012345ABCD”;
Unsigned char z;
For (z=0; z<=10; z++){
26
P1= mynum[z];
}
}
c) WRITE AN 8051 C PROGRAM TO TOGGLE ALL THE BITS OF P1
CONTINUOUSLY.
#include <reg51.h>
Void main (void)
{
For (; ;);
{
P1 = 0 x 55;
P2 = 0 x AA;
}
}
d) WRITE AN 8051 C PROGRAM TO SEND VALUES OF -4 TO +4 TO PORT P1.
#include <reg51.h>
Void main (void)
{
char my num[] = {+1,-1,+2,-2,+3,-3,+4,-4};
Unsigned char z;
For (z=0; z<=8; z++){
P1= mynum[z];
}}
27
OUTPUT:
28
c) 8051 C PROGRAM TO TOGGLE ALL THE BITS OF P1 CONTINUOUSLY.
29
e) 8051 C PROGRAM TO TOGGLE BIT D0 OF THE PORT P1(P1.0) 50,000 TIMES.
RESULT:
Thus the Embedded C program simulated using 8051 microcontroller in Keil µ vision version 3.
30
EXPT.NO 5
DATE: INTRODUCTION TO ARDUINO PLATFORM AND
PROGRAMMING
AIM:
To upload and execute basic programs on Arduino board using Arduino IDE.
THEORY:
Arduino is an open-source electronics platform based on easy-to-use hardware and software.
Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message -
and turn it into an output - activating a motor, turning on an LED, publishing something online. You
can tell your board what to do by sending a set of instructions to the microcontroller on the board. To
do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE),
based on Processing.
Over the years Arduino has been the brain of thousands of projects, from everyday objects to
complex scientific instruments. A worldwide community of makers - students, hobbyists, artists,
programmers, and professionals - has gathered around this open-source platform, their contributions
have added up to an incredible amount of accessible knowledge that can be of great help to novices
and experts alike.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it reached a wider
community, the Arduino board started changing to adapt to new needs and challenges, differentiating
its offer from simple 8-bit boards to products for IoT applications, wearable, 3D printing, and
embedded environments.
31
Advantages:
• Inexpensive
• Cross-platform
• Simple, clear programming environment
• Open source and extensible software
• Open source and extensible hardware
PROCEDURE:
32
PROGRAM:
1. Print a string
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
Serial.println("hello world");
}
................................................................
2. Blink LED
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
................................................................
33
OUTPUT:
1. Print a String:
RESULT:
Thus some basic Arduino Programming has been done and executed in Arduino Uno board using
Arduino IDE.
34
EXPT.NO 6 a
DATE: EXPLORE DIFFERENT COMMUNICATION METHODS WITH IOT
DEVICES-ZIGBEE
AIM:
To perform an experiment to configure two ZigBee XBee S2C modules as coordinator and router and
communicate between them using XCTU software.
THEORY:
ZigBee/XBee PRO S2C 802.15.4 RF Modules are an embedded solutions providing wireless end-
point connectivity to devices. These devices use the IEEE 802.15.4 networking protocol for fast point-to-
multi point or peer-to-peer networking. They designed for high-throughput applications requiring low
latency and predictable communication timing.
XBee and XBee-PRO ZigBee modules are ideal for hobbyists and educational research as well as
applications in the energy and control markets where manufacturing efficiencies are critical. The Serial
Peripheral Interface (SPI) provides a high-speed interface and optimizes the integration with embedded
microcontrollers, lowering development costs and reducing time to market. Digi’s ZigBee compatible
module is based on the Ember EM35x (EM357 and EM3587) system on chip (SoC) radio ICs from
Silicon Labs, utilizing 32-bit ARM Cortex M3 processor.
PROCEDURE:
1. XBee connection with USB adapter: Connect the XBee module to XBee USB adapter
2. Open XCTU software 6.1.1 software. Click on the search button of XCTU. It directs the XBee
connected to the USB adapter. Start the configuration of the XBee module.
3. Open the XCTU software& then click on the search on the top.
35
4. To know the com port where radios are connected open the device manager and note down the
com port. Select the ports and click on next.
5. Leave the port parameters to default. (i.e. 9600-8-N-1) and click on finish
• 9600- Baud rate
• 8- Data bit
• Parity- None and 1- stop bit
6. The radios (XBees) are discovered by XCTU& click on Add selected device to see the XBee listed on
the left side of the XCTU.
7. Click on the First radio to load the setting. You can see the product family as XBP24C and Function
set as 802.15.4 TH PRO.
8. To upgrade the latest firmware, click on the Upgrade Firmware and leave the function set to default
and select the Newest version. Click on the finish to upgrade.
9. Now configure the first radio as COORDINATOR. First set Pan ID for the network. This can be any
Hex value from 0 to FFFF. (Set it as 1234).
10. To operate the Radio in the broadcast mode set the DL (Destination address) as FFFF. Type the name
of the first radio in NI (Node Identifier). Any name can be provided. Here the NI set as
COORDINATOR.
36
11. To make the Radio as COORDINATOR, Set the CE parameter to Enable and click on the Write
button (Pencil Icon) to save the information.
12. Now click on the second radio and configure this as ROUTER.
13. Enter the Pan Id as 1234 which is the same as COORDINATOR. Set the JV channel Verification to
enable so that it joins the COORDINATOR. Leave the CE to Disable and click on the Write to save
the changes.
14. Communication between Coordinator and Router: The Radios are configured, now you can do the
communication between the COORDINATOR and Router, Click on the search button of the second
window of XCTU. Select the com port of the second radio. That is the ROUTER radio. Click on the
router radio to load the settings.
37
38
OUTPUT:
1. The new window has a ROUTER and the old window has a COORDINATOR.
• Left side- ROUTER
• Right side- COORDINATOR
39
2. Click on the Console terminal window of both radio and Serial close button.
3. Now type the message in the Console log window to see received by other radio. The transmitter
message in BLUE and Received message in RED.
RESULT:
Thus two ZigBee XBee S2C modules have been configured as coordinator and router and
communicate between them has been established between them using XCTU software.
40
EXPT.NO. 7.a
INTRODUCTION TO RASPBERRY PI PLATFORM
DATE:
AIM:
To study about Raspberry Pi Pico RP2040 microcontroller board and Thonny IDE.
INTRODUCTION:
Designed by Raspberry Pi, RP2040 features a dual-core Arm Cortex-M0+ processor with 264kB
internal RAM and support for upto 16MB of off-chip flash. A wide range of flexible I/O options
includes I2C, SPI, and - uniquely - Programmable I/O (PIO). These support endless possible
applications for this small and affordable package.
Whether you have a Raspberry Pi Pico or another RP2040-based microcontroller board, everything
you need to get started is here. You’ll find support for getting started with C/C++ or MicroPython on
Raspberry Pi Pico, and links to resources for other boards that use RP2040. There are also links to the
technical documentation for both the Raspberry Pi Pico microcontroller board and our RP2040
microcontroller chip.
RP2040 is the debut microcontroller from Raspberry Pi. It brings our signature values of high
performance, low cost, and ease of use to the microcontroller space. With a large on-chip memory,
symmetric dual-core processor complex, deterministic bus fabric, and rich peripheral set augmented
with our unique Programmable I/O (PIO) subsystem, it provides professional users with unrivalled
power and flexibility. With detailed documentation, a polished MicroPython port, and a UF2 bootloader
in ROM, it has the lowest possible barrier to entry for beginner and hobbyist users. RP2040 is a
stateless device, with support for cached execute-in-place from external QSPI memory. This design
decision allows you to choose the appropriate density of non-volatile storage for your application, and
to benefit from the low pricing of commodity Flash parts.
RP2040 is manufactured on a modern 40nm process node, delivering high performance, low
dynamic power consumption, and low leakage, with a variety of low-power modes to support extended-
duration operation on battery power.
Key features:
• Dual ARM Cortex-M0+ @ 133MHz
• 264kB on-chip SRAM in six independent banks
• Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
• DMA controller
• Fully-connected AHB crossbar
• Interpolator and integer divider peripherals
• On-chip programmable LDO to generate core voltage
• 2 on-chip PLLs to generate USB and core clocks
• 30 GPIO pins, 4 of which can be used as analogue inputs
Peripherals:
• 2 UARTs
• 2 SPI controller
41
• 2 I2C controllers
• 16 PWM channels
• USB 1.1 controller and PHY, with host and device support
• 8 PIO state machines
Raspberry pi Pico
Raspberry Pi Pico W and Pico WH
Raspberry Pi Pico W adds on-board single-band 2.4GHz wireless interfaces (802.11n) using the
Infineon CYW43439 while retaining the Pico form factor. The on-board 2.4GHz wireless interface has
the following features:
• Wireless (802.11n), single-band (2.4 GHz)
• WPA3
• Soft access point supporting up to four clients
The antenna is an onboard antenna licensed from ABRACON (formerly ProAnt). The wireless
interface is connected via SPI to the RP2040 microcontroller. Due to pin limitations, some of the
wireless interface pins are shared. The CLK is shared with VSYS monitor, so only when there isn’t an
SPI transaction in progress can VSYS be read via the ADC. The Infineon CYW43439 DIN/DOUT and
IRQ all share one pin on the RP2040. Only when an SPI transaction isn’t in progress is it suitable to
check for IRQs. The interface typically runs at 33MHz. For best wireless performance, the antenna
should be in free space. For instance, putting metal under or close by the antenna can reduce its
performance both in terms of gain and bandwidth. Adding grounded metal to the sides of the antenna
can improve the antenna’s bandwidth.
42
RASPBERRY PI PICO PINOUT FEATURES:
• Micro-USB B port for power and data (and for reprogramming the Flash)
• 12MHz Crystal Oscillator with two PLLs provide a system clock up to 133MHz, and a fixed
48MHz clock for USB or ADC.
• Code may be executed directly from 2MB of on-board Flash memory through a dedicated SPI
• Raspberry Pi Pico is a microcontroller board based on the Raspberry Pi RP2040 - 32 bit
microcontroller chip
• 3-pin ARM Serial Wire Debug (SWD) port.
• FourRP2040 GPIO pins are used for internal board functions, these are:
43
➢ GPIO29 IP (ADC3) Used to measure VSYS/3
➢ GPIO25 OP Connected to onboard LED
➢ GPIO24 IP VBUS sense - high if VBUS is present, else low
➢ GPIO23 OP Controls the on-board SMPS Power Save pin
RP2040 MICROCONTROLLER BASIC ARCHITECTURE:
Power Supply
At its simplest, RP2040 requires two different voltage supplies, 3.3V (for the IO) and 1.1V (for the chip's
digital core).
44
while delivering significantly higher performance.
• The low-power processor is suitable for a wide variety of applications, including sensors and
wearables.
• Single-cycle IO to speed access to GPIO and peripherals.
• Improved debug and trace capability and a 2-stage pipeline.
• The exceptional code density of Cortex-M0+ significantly reduces memory requirements, ideal for
use in wearables for healthcare, fitness, and more.
• With its three highly optimized low-power modes, the processor conserves energy to match
processing demands.
45
SOFTWARE REQUIRED & PROGRAMMING LANGUAGE:
RESULT:
Thus the basic architecture, pin details of Raspberry Pi Pico RP2040 microcontroller board and Thonny
IDE for python programming has been studied.
46
EXPT.NO 7.b
Python Programming in Raspberry Pi
DATE:
AIM:
To execute basic python programs in Raspberry Pi Pico board
1. Raspberry Pi Pico W
2. Thonny IDE
PROCEDURE:
1. Connect Raspberry Pi board to PC using USB-serial communication cable
2. Type the program in Thonny IDE.
3. Button LED – check for LED to glow on pressing the switch
4. Buzzer – check for the buzzer to beep
5. LED – check for LEDs connected to pin 2 and pin 3 to glow
6. POT – connect the potentiometer to the Raspberry Pi board (Vcc-3.3V, Gnd-Gnd, Data in- GPIO 28)
and run the program. Check for the potentiometer values displayed in Thonny IDE.
PROGRAM:
1.Button_LED:
while True:
else:
led1.value(0)
led2.value(1)
else:
led2.value(0)
...................................................................
47
2.Buzzer:
while True:
Buzzer.value(1)
print(" Buzzer ON")
time.sleep(0.2)
Buzzer.value(0)
print(" Buzzer OFF")
time.sleep(1)
...................................................................
3.LED:
led2=Pin(2,Pin.OUT)
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)
...................................................................
4.POT:
POT_Value = machine.ADC(28)
conversion_factor = 3.3/(65535)
while True:
#print(POT_Value.read_u16() )
print(POT_Value.read_u16() * conversion_factor)
utime.sleep(1)
...................................................................
48
OUTPUT:
1.Button_LED:
2.Buzzer:
3.LED:
4.POT:
RESULT:
Thus the python programs to have been executed in Raspberry Pi Pico board.
49
EXPT.NO:08
DATE: INTERFACING SENSORS WITH RASPBERRY PI
AIM:
To execute programs for interfacing sensors with Raspberry Pi Pico.
HARDWARE/SOFTWARE REQUIREMENTS:
1. Raspberry Pi Pico W
2. Thonny IDE
PROCEDURE:
1. Connect Raspberry Pi board to PC using USB-serial communication cable
2. Type the program in Thonny IDE.
3. TEMP – connect the temperature sensor LM35 to the Raspberry Pi board (Vcc-3.3V, Gnd-Gnd,
Data in- GPIO 28) and run the program. Check for the room temperature values displayed in
Thonny IDE.
4. ULTRASONIC – the Ultrasonic distance sensor is HC-SR04 interfaced to pin 14, pin 15 on the
Raspberry Pi board. Run the program and check for the distance values displayed in Thonny IDE.
5. LIGHT DETECTOR – connect the Photo detector LM35 to the Raspberry Pi board (Vcc-3.3V,
Gnd-Gnd, Data in- GPIO 28) and run the program. In Thonny IDE check for the voltage values
corresponding to the light received on the sensor.
6. IR SENSOR – connect the InfraRed Sensor to the Raspberry Pi board (Vcc-3.3V, Gnd-Gnd, Data
in- GP28) and run the program. In Thonny IDE check for ‘1’ and ‘0’values corresponding to open
and close of IR receiver.
PROGRAM:
1.TEMP:
while True:
val2 = adc2.read_u16()
temp = (val2 * conversion_factor)*100
print("===============================")
print("temperature: ",temp)
time.sleep(0.8)
50
...................................................................
2.ULTRASONIC:
while True:
distance = sensor.distance_cm()
D = int(distance)
print('Distance:', distance, 'cm')
sleep(0.4)
...................................................................
3.LIGHT DETECTOR
while True:
val2 = adc2.read_u16()
ldr = (val2 * conversion_factor)
print("===============================")
print("LDR Voltage : ",ldr)
time.sleep(0.8)
...................................................................
4.IR SENSOR
...................................................................
51
OUTPUT:
1.TEMP:
2. ULTRASONIC:
3. LIGHT DETECTOR:
52
4. IR SENSOR:
RESULT:
Thus the python programs for interfacing sensors with Raspberry Pi Pico have been executed.
53
EXPT.NO:09 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING
DATE: ANY WIRELESS MEDIUM
AIM:
To Communicate between Arduino and Raspberry PI usingwireless medium-ESP01(WIFI Module)
HARDWARE/SOFTWARE REQUIREMENTS:
1. Raspberry PI
2. ESP01
3. Arduino UNO
PROCEDURE:
DIAGRAM:
54
PROGRAM:
#include <SoftwareSerial.h>
#define RX 3
#define TX 2
String AP = "A54"; // AP NAME
String PASS = "12345678"; // AP PASSWORD
String HOST = "192.168.253.207";
String PORT = "1234";
intcountTrueCommand;
intcountTimeCommand;
boolean found = false;
intvalSensor = 1;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK"); //AT+CWMODE=1 TO SET MODULE AS
STATION
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK"); //CONNECT TO
ARDUINO
String ip = "AT+CIFSR"; //CONNECT TO IP ADDRESS
sendCommand(ip,5,"OK");
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
break;
}*/
}
void loop() {
valSensor = getSensorData();
String getData = String(valSensor);
sendCommand("AT+CIPMUX=1",5,"OK"); // TO ENABLE MULTIPLE CONNECTIONS
sendCommand("AT+CIPSTART=0,\"UDP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
}
intgetSensorData(){
return random(1000); // Replace with your own sensor code
}
55
void sendCommand(String command, intmaxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand< (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
import network
import socket
import time
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("A54","12345678")
# rgb led
led1=machine.Pin(2,machine.Pin.OUT)
led2=machine.Pin(3,machine.Pin.OUT)
56
# Wait for connect or fail
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('waiting for connection...')
time.sleep(1)
localIP = wlan.ifconfig()[0]
localPort = 1234
bufferSize = 1024
while True:
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0]
address = bytesAddressPair[1]
m=str(message.decode())
m=m.strip()
print(m)
57
OUTPUT:
RESULT:
Thus the communication between Arduino and Raspberry PI using wireless medium-ESP01(WIFI Module) has
been done.
58
EXPT.NO:10 SETUP A CLOUD PLATFORM TO LOG THE DATA
DATE:
AIM:
To Setup a cloud platform to log the datafrom Arduino UNO using ESP01(WIFI Module).
HARDWARE/SOFTWARE REQUIREMENTS:
1. ESP01
2. Arduino UNO
3. Think speak cloud
PROCEDURE:
PROGRAM:
#include <SoftwareSerial.h>
#define RX 3
#define TX 2
String AP = "A54"; // AP NAME
String PASS = "0123456789"; // AP PASSWORD
String API = "N2UXO5PAQ1BQWD9S"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
String field = "field1";
intcountTrueCommand;
intcountTimeCommand;
boolean found = false;
intvalSensor = 1;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(115200);
59
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
valSensor = getSensorData();
String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor);
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
}
intgetSensorData(){
return random(1000); // Replace with your own sensor code
}
countTimeCommand++;
60
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
61
OUTPUT:
62
RESULT:
Thus, a cloud platform has been set to log the data from Arduino UNO using ESP01(WIFI Module).
63
EXPT.NO:11 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 (Fire base cloud).
HARDWARE/SOFTWARE REQUIREMENTS:
1. Raspberry pi
2. Fire base cloud
PROCEDURE:
2. Copy the urlfrom the cloud and paste in the program for both control and monitor.
4. Similarly run the control program to set keys value as controls -> led as on and off in the cloud.
5. The led in the Raspberry Pico W can found on or off depending on the control values given in the cloud.
PROGRAM:
import time
import utime
import network
import urequests
import _thread
adc2 = machine.ADC(28)
adc=""
firebase.setURL("https://project-2731037790370440547-default-rtdb.firebaseio.com")
ssid = 'Xperia_6305'
password ='0123456789'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
wait = 10
break
64
wait -= 1
time.sleep(1)
if wlan.status() != 3:
time.sleep(2)
else:
print('connected')
status = wlan.ifconfig()
time.sleep(2)
#lcd.clear()
while True:
time.sleep(3)
print("put")
val1 = adc2.read_u16()
adc = str(val1)
import time
import utime
import network
import urequests
import _thread
firebase.setURL("https://project-2731037790370440547-default-rtdb.firebaseio.com")
relay1=Pin(2,Pin.OUT) #7
relay1.low()
ssid = 'Xperia_6305'
65
password = '0123456789'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
wait = 10
break
wait -= 1
time.sleep(1)
if wlan.status() != 3:
lcd.move_to(0,0)
time.sleep(2)
lcd.clear()
else:
print('connected')
status = wlan.ifconfig()
time.sleep(2)
#lcd.clear()
while True:
time.sleep(3)
words=firebase.led
d=words['led']
direct=d
print(direct)
66
if(direct=="on"):
relay1.high()
if(direct=="off"):
relay1.low()
67
OUTPUT:
Control:
68
OUTPUT:
Monitor
RESULT:
Thus the program to Log Data using Raspberry Pi and uploading it in to the cloud platform (Fire base cloud) has
been done.
69
EXPT.NO12 DESIGN AN IOT BASED SYSTEM
DATE:
AIM:
To Design an IOT based system (Home Automation).
HARDWARE/SOFTWARE REQUIREMENTS:
1. Arduino board
2. Blynk cloud
PROCEDURE:
BLOCK DIAGRAM:
PROGRAM:
#define BLYNK_TEMPLATE_ID "TMPL3V82ukdjI"
#define BLYNK_TEMPLATE_NAME "automation"
#define BLYNK_AUTH_TOKEN "XbrlPUuxL7O9LKBOjm5_Ujwhjxuofi4J"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
70
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "A54"; //wifi name
char pass[] = "0123456789"; //password of wifi
BlynkTimer timer;
digitalWrite(Relay1,HIGH);
digitalWrite(Relay2,HIGH);
digitalWrite(Relay3,HIGH);
digitalWrite(Relay4,HIGH);
// Debug console
Serial.begin(115200);
void loop()
{
Blynk.run();
}
72
OUTPUT:
73
RESULT: