ESIoT Lab Manual
ESIoT Lab Manual
AIM:
To write 8051 Assembly Language Program for an 8-bit addition using Keil simulator and
execute it.
SOFTWARE REQUIRED:
A simulator is software that will execute the program and show the results exactly to the
program running on the hardware, if the programmer finds any errors in the program while
simulating the program in the simulator, he can change the program and re-simulate the code and
get the expected result, before going to the hardware testing. The programmer can confidently
dump the program in the hardware when he simulates his program in the simulator and gets the
expected results.
8051 controller is a most popular 8-bit controller which is used in a large number of
embedded applications and many programmers write programs according to their application. So
testing their programs in the software simulators is a way. Simulators will help the programmer to
understand the errors easily and the time taken for the testing is also decreased.
These simulators are very useful for students because they do need not to build the complete
hardware for testing their program and validate their program very easily in an interactive way.
2. EDSIM 51: This is a virtual 8051 interfaced with virtual peripherals like 7 segment display,
motor, keypad, UART etc. This simulator is exclusively for students developed by James Rogers,.
The features of this simulator are
✓ Have virtual peripherals like ADC, DAC with scope to display, comparator etc.
✓ Supports only assembly language
✓ IDE is completely written in JAVA and supports all the OS.
✓ Completely free and with user guide, examples, etc.
3. 8051 IDE: This simulation software is exclusively for the Windows operating system (98/xp).
The features of this simulator are
✓ Text editor, assembler, and software simulate in one single program.
✓ Has facilities like Breakpoint setter, execute to break point, predefined simulator watch
window, etc.
✓ It is available in both free version and paid version.
4. KEIL µVision: KEIL is the most popular software simulator. It has many features like
interactive IDE and supports both C and assembly languages for compilation and simulation.
After saving the file, a new window will pop up asking you to select your microcontroller.
As discussed, we are using AT89C51/AT89C51ED2/AT89C52, so select this controller under the
Microchip section (as Atmel is now a part of Microchip).
Select ‘Yes’ in the next pop-up, as we do not need this file in our project.
From here, we need to create a file where we can write our C code. Navigate to File —> New.
Once the file is created, save it with .c extension in the same project folder.
Next, we have to add that .c or .asm file to our project workspace. Select Add Existing Files and
then select the created .c or .asm file to get it added.
The workspace and project file are ready.
PROCEDURE:
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create New Project Select Device for
Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of simulation by clicking Run or step run.
PROGRAM:
ORG 0000H
CLR C
MOV A, #20H
ADD A, #21H
MOV R0, A
END
PROCEDURE:
STEP 1 : Initialize Port 1 as an output port.
STEP 2 : Enter an infinite loop labeled as "LOOP."
STEP 3 : The delay subroutine is called "DELAY."
Initialize register R2 with the value 0xFF (255 in decimal).
Enter a loop labeled as "DELAY_LOOP."
STEP 4 : The program continues to loop indefinitely, creating a blinking LED effect on P1.0.
PROGRAM 1 :
ORG 0x00
MOV P1, #0x00 ; Initialize Port 1 as output LOOP:
SETB P1.0 ; Turn on LED at P1.0
DELAY:
MOV R2, #0xFF DELAY_LOOP:
DJNZ R2, DELAY_LOOP
RET
OUTPUT:
PROCEDURE:
STEP 1 : Initialize Port 0: Set up Port 0 as an output port to control the 7- segment display.
STEP 2 : Enter the Main Loop (MAIN)
STEP 3 : Display Subroutine (DISPLAY)
STEP 4 : Display Subroutine (DISPLAY)
STEP 5 : Delay Subroutine (DELAY)
STEP 6 : Return from the delay subroutine
PROGRAM:
ORG 0x00
MOV P1, #0x00 ; Initialize Port 1 as output LOOP:
SETB P1.0 ; Turn on LED at P1.0
ACALL DELAY ; Call the delay subroutine
CLR P1.0 ; Turn off LED at P1.0
ACALL DELAY ; Call the delay subroutine
SJMP LOOP
DELAY:
MOV R2,#0xFF;
DELAY_LOOP:
DJNZ R2, DELAY_LOOP
RET
OUTPUT:
Thus the 8051 Assembly Language Program for an 8-bit addition using Keil simulator was
executed successfully.
EXP NO:
TEST DATA TRANSFER BETWEEN REGISTERS
DATE AND MEMORY
AIM:
To write and execute an Assembly language program to transfer data between registers and
memory.
SOFTWARE REQUIRED:
DEFINITION:
Transfer a value from a register to memory and then from memory back to another register. We'll
use the ‘MOV’ (move) instruction for this purpose.
ALGORITHM:
RESULT:
Thus the Assembly language program to transfer data between registers and memory was executed.
EXP NO:
ALU OPERATIONS
DATE
AIM:
To write and execute the ALU program using the Keil simulator.
PROCEDURE:
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create New Project Select Device for
Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of simulation by clicking Run or step run.
PROGRAM:
ORG 0000H
CLR C
//ADDITION
MOV A, #20H
ADD A, #21H
MOV 41H, A
//SUBTRACTION
MOV A, #20H
SUBB A, #18H
MOV 42H, A
//MULTIPLICATION
MOV A, #03H
MOV B, #04H
MUL AB
MOV 43H, A
//DIVISION
MOV A, #95H
MOV B, #10H
DIV AB
MOV 44H, A
MOV 45H, B
//AND
MOV A, #25H
MOV B, #12H
ANL A, B
MOV 46H, A
//OR
MOV A, #25H
MOV B, #15H
ORL A, B
MOV 47H, A
//XOR
MOV A, #45H
MOV B, #67H
XRL A, B
MOV 48H, A
//NOT
MOV A, #45H
CPL A
MOV 49H, A
END
OUTPUT:
RESULT:
Thus the ALU program using the Keil simulator was written and executed.
EXP NO:
WRITE BASIC PROGRAMS USING EMBEDDED C
DATE
AIM:
To write a basic embedded C program to blink an LED connected to a micro controller pin.
SOFTWARE REQUIRED:
PROCEDURE:
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μVision Project and Create a New Project Select Device for
the Target.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.
ALGORITHM:
main(void) {
// Set the LED pin as output DDRB |= (1
<< LED_PIN);
while (1) {
// Toggle the LED pin PORTB ^= (1 <<
LED_PIN);
return 0;
}
OUTPUT:
ARITHMETIC PROGRAM:
Addition of Two Numbers
ALGORITHM :
main() {
int num1, num2, sum;
return 0;
}
OUTPUT:
RESULT:
Thus a basic embedded C program to blink an LED connected to a micro controller pin was written
and executed.
EXP NO:
INTRODUCTION TO THE ARDUINO PLATFORM
DATE
AIM:
To study the basics of Arduino Uno board and Arduino IDE 2.0 software.
INTRODUCTION TO ARDUINO:
Arduino is a project, open-source hardware, and software platform used to design and build electronic
devices. It designs and manufactures microcontroller kits and single-board interfaces for building
electronics projects. The Arduino boards were initially created to help students with the non-technical
background. The designs of Arduino boards use a variety of controllers and microprocessors.
Arduino is an easy-to-use open platform for creating electronic projects. Arduino boards play a vital
role in creating different projects. It makes electronics accessible to non-engineers, hobbyists, etc.
The various components present on the Arduino boards are a Microcontroller, Digital Input/output
pins, USB Interface and Connector, Analog Pins, reset buttons, Power buttons, LEDs, Crystal
oscillators, and Voltage regulators. Some components may differ depending on the type of board.
The most standard and popular board used over time is Arduino UNO. The ATmega328
Microcontroller present on the UNO board makes it rather powerful than other boards. There are
various types of Arduino boards used for different purposes and projects. The Arduino Boards are
organized using the Arduino (IDE), which can run on various platforms. Here, IDE stands for
Integrated Development Environment. Let's discuss some common and best Arduino boards.
TYPES OF ARDUINO BOARDS:
1) Arduino UNO
Arduino UNO is based on an ATmega328P microcontroller. It is easy to use compared to other
boards, such as the Arduino Mega board, etc. The Arduino UNO includes 6 analog pin inputs, 14
digital pins, a USB connector, a power jack, and an ICSP (In-Circuit Serial Programming) header. It
is the most used and of standard form from the list of all available Arduino Boards.
2) Arduino Nano
The Arduino Nano is a small Arduino board based on ATmega328P or ATmega628 Microcontroller.
The connectivity is the same as the Arduino UNO board. The Nano board is defined as a sustainable,
small, consistent, and flexible microcontroller board. It is small in size compared to the UNO board.
The devices required to start our projects using the Arduino Nano board are Arduino IDE and mini-
USB. The Arduino Nano includes an I/O pin set of 14 digital pins and 8 analog pins. It also includes
6 Power pins and 2 Reset pins.
3) Arduino Mega
The Arduino Mega is based on the ATmega2560 Microcontroller. The ATmega2560 is an 8-bit
microcontroller. We need a simple USB cable to connect to the computer and the AC to DC adapter
or battery to get started with it. It has the advantage of working with more memory space. The
Arduino Mega includes 54 I/O digital pins and 16 Analog Input/Output (I/O), ICSP header, a reset
button, 4 UART (Universal Asynchronous Reciever/Transmitter) ports, USB connection, and a
power jack.
4) Arduino Micro
The Arduino Micro is based on the ATmega32U4 Microcontroller. It consists of 20 sets of pins. The
7 pins from the set are PWM (Pulse Width Modulation) pins, while 12 pins are analog input pins.
The other components on board are a reset button, a 16MHz crystal oscillator, an ICSP header, and
a micro-USB connection. The USB is built in the Arduino Micro board.
5) Arduino Leonardo
The basic specification of the Arduino Leonardo is the same as the Arduino Micro. It is also based
on the ATmega32U4 Microcontroller. The components present on the board are 20 analog and digital
pins, a reset button, a 16MHz crystal oscillator, an ICSP header, and a micro USB connection.
6) Arduino Due
The Arduino Due is based on the 32-bit ARM core. It is the first Arduino board that has been
developed based on the ARM Microcontroller. It consists of 54 Digital Input/Output pins and 12
Analog pins. The Microcontroller present on the board is the Atmel SAM3X8E ARM Cortex-M3
CPU. It has two ports, namely, a native USB port and a Programming port. The micro side of the
USB cable should be attached to the programming port.
The Arduino IDE 2.0 is an open-source project, currently in its beta-phase. It is a big step from it's
sturdy predecessor, Arduino IDE 2.0, and comes with revamped UI, improved board & library
manger, autocomplete feature and much more.
In this tutorial, we will go through step by step, how to download and install the software.
Download the editor
Downloading the Arduino IDE 2.0 is done through the Arduino Software page. Here you will also
find information on the other editors available to use.
Requirements
• Windows - Win 10 and newer, 64 bits
• Linux - 64 bits
• Mac OS X - Version 10.14: "Mojave" or newer, 64 bits
Installation
Windows
Download URL: https://www.arduino.cc/en/software
To install the Arduino IDE 2.0 on a Windows computer, simply run the file downloaded from the
software page.
Follow the instructions in the installation guide. The installation may take several minutes.
You can now use the Arduino IDE 2.0 on your windows computer!
How to upload a sketch with the Arduino IDE 2.0
In the Arduino environment, we write sketches that can be uploaded to Arduino boards. In this
tutorial, we will go through how to select a board connected to your computer, and how to upload
a sketch to that board, using the Arduino IDE 2.0.
Requirements
• Arduino IDE 2.0 installed.
Verify VS Upload
There are two main tools when uploading a sketch to a board: verify and upload. The verify tool
simply goes through your sketch, checks for errors and compiles it. The upload tool does the same,
but when it finishes compiling the code, it also uploads it to the board.
A good practice is to use the verifying tool before attempting to upload anything. This is a quick
way of spotting any errors in your code, so you can fix them before actually uploading the code.
Uploading a sketch
Installing a core is quick and easy, but let's take a look at what we need to do.
1. Open the Arduino IDE 2.0.
2. With the editor open, let's take a look at the navigation bar at the top. At the very left, there
is a checkmark and an arrow pointing right. The checkmark is used to verify, and the
arrow is used to upload.
3. Click on the verify tool (checkmark). Since we are verifying an empty sketch, we can be sure
it is going to compile. After a few seconds, we can see the result of the action in the console
(black box in the bottom).
4. Now we know that our code is compiled, and that it is working. Now, before we can upload
the code to our board, we will first need to select the board that we are using. We can do this
by navigating to Tools > Port > {Board}. The board(s) that are connected to your computer
should appear here, and we need to select it by clicking it. In this case, our board is displayed
as COM44 (Arduino UNO).
5. With the board selected, we are good to go! Click on the upload button, and it will start
uploading the sketch to the board.
6. When it is finished, it will notify you in the console log. Of course, sometimes there are
some complications when uploading, and these errors will be listed here as well.
How to install and use a library with the Arduino IDE 2.0
A large part of the Arduino programming experience is the use of libraries. Thousands of libraries
can be found online, and the best-documented ones can be found and installed directly through the
editor. In this tutorial, we will go through how to install a library using the library manager in the
Arduino IDE 2.0. We will also show how to access examples from a library that you have installed.
Requirements
• Arduino IDE 2.0 installed.
Why use libraries?
Libraries are incredibly useful when creating a project of any type. They make our development
experience much smoother, and there almost an infinite amount out there. They are used to interface
with many different sensors, RTCs, Wi-Fi modules, RGB matrices and of course with other
components on your board.
Arduino has many official libraries, but the real heroes are the Arduino community, who develop,
maintain and improve their libraries on a regular basis.
Installing a library
Installing a library is quick and easy, but let's take a look at what we need to do.
1. Open the Arduino IDE 2.0.
2. With the editor open, let's take a look at the left column. Here, we can see a couple of icons.
Let's click the on the "library" icon.
3. A list will now appear of all available libraries, where we can also search for the library we
want to use. In this example, we are going to install the RTCZero library. Click on
the "INSTALL" button to install the library.
4. This process should not take too long, but allow up to a minute to install it.
5. When it is finished, we can take a look at the library in the library manager column, where it
should say "INSTALLED".
You have now successfully downloaded and installed a library on your machine.
Including a library
To use a library, you first need to include the library at the top of the sketch
Almost all libraries come with already made examples that you can use. These are accessible
through File > Examples > {Library} > {Example}. In this example, we are choosing the RTCZero >
SimpleRTC.
The chosen example will now open up in a new window, and you can start using it however you
want to.
RESULT:
Thus the basics of Arduino Uno board and Arduino IDE 2.0 software was studied successfully.
EXP NO:
INTRODUCTION TO ARDUINO PROGRAMMING
DATE
AIM:
To write and execute different Arduino programming for analog, digital signals and serial
communication.
5 Joystick Module 1
CONNECTION:
PROGRAM:
DIGITAL WRITE:
void setup()
{
pinMode(2, OUTPUT);
}
void loop()
{
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
}
CONNECTION:
DIGITAL READ:
void setup() { pinMode(2, OUTPUT);
pinMode(5, INPUT_PULLUP);
}
void loop() {
int sw=digitalRead(5); if(sw==1)
{
for(int i=0; i<5; i++)
{
digitalWrite(2, HIGH); delay(1000); digitalWrite(2, LOW); delay(1000);
}
}
else
{
digitalWrite(2, LOW);
}
}
CONNECTION:
ANALOG READ:
void setup() {
pinMode(2, OUTPUT);
Serial.begin(9600);
}
void loop() {
int joystick=analogRead(A0);
Serial.println(joystick);
if(joystick>800)
digitalWrite(2, HIGH);
else
digitalWrite(2, LOW);
delay(500);
}
CONNECTION:
ANALOG WRITE:
void setup()
{
pinMode(3, OUTPUT);
}
void loop()
{
for(int i=0; i<256;i++)
{
analogWrite(3,i);
delay(20);
}
for(int i=255; i>=0;i--)
{
analogWrite(3,i);
delay(20);
}
}
CONNECTION:
SERIAL COMMUNICATION:
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop()
{ if(Serial.available()>0)
{
char data=Serial.read();
Serial.println(data);
if(data=='1')
{
digitalWrite(4,HIGH);
}
else if(data=='2')
{
digitalWrite(4,LOW);
}
}
}
RESULT:
Thus the different Arduino programming for analog, digital signals and serial communication was
written and executed.
EXP NO: DIFFERENT COMMUNICATION METHODS WITH IOT
DATE DEVICES (ZIGBEE, GSM, BLUETOOTH)
AIM:
To Explore different communication methods with IoT devices (Zigbee, GSM, Bluetooth).
ZIGBEE:
Zigbee is a low-power wireless communication protocol designed for short-range
communication between devices. It operates on the 2.4 GHz frequency band and supports mesh
networking, allowing devices to communicate with each other through intermediate nodes. Zigbee is
commonly used in home automation, industrial control, and smart energy applications.
BLUETOOTH:
Bluetooth is a short-range wireless communication technology that operates on the 2.4 GHz
frequency band. It is commonly used for connecting IoT devices to smartphones, tablets, and other
nearby devices. Bluetooth Low Energy (BLE) is a power-efficient version of Bluetooth that is ideal
for battery-powered IoT devices. Bluetooth is widely used in applications such as wearable devices,
healthcare monitoring, and home automation.
Each communication method has its advantages and limitations, and the choice depends on
the specific requirements of the IoT application. Factors to consider include range, power
consumption, data rate, security, and interoperability with other devices or systems.
RESULT:
Thus the different communication methods with IoT devices (Zigbee, GSM, Bluetooth) was
successfully explored.
EXP NO:
BLUETOOTH COMMUNICATION
DATE
AIM:
To write a program to control an LED using a Bluetooth module.
CONNECTIONS:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //rx,tx
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop() {
if(mySerial.available()>0)
{
char data=mySerial.read();
Serial.println(data);
if(data=='1'){
digitalWrite(4,HIGH);
Serial.println("LED ON");
}
else if(data=='2'){
digitalWrite(4,LOW);
Serial.println("LED OFF");
}
}
}
RESULT:
Thus a program to control an LED using a Bluetooth module was executed successfully.
EXP NO:
ZIGBEE COMMUNICATION
DATE
AIM:
To write a program to control an LED using a Zigbee module.
5 Zigbee Module 2
CONNECTIONS:
TRANSMITTER:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //rx,tx
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
}
void loop() {
mySerial.write('A');
Serial.println('A');
delay(100);
mySerial.write('B');
Serial.println('B');
delay(100);
}
CONNECTIONS:
RECEIVER:
Arduino UNO Pin Zigbee Module Arduino Development Board
- 5V 5V
- G GND
2 Tx -
3 Rx -
4 - LED1
RECEIVER SIDE:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //rx,tx
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop() {
if(mySerial.available()>0)
{
char data=mySerial.read();
Serial.println(data);
if(data=='A')
digitalWrite(4,HIGH);
else if(data=='B')
digitalWrite(4,LOW);
}
}
RESULT:
Thus a program to control an LED using a Zigbee module was successfully executed.
EXP NO: INTRODUCTION TO THE RASPBERRY PI
DATE PLATFORM
The Raspberry Pi Pico W is a compact and affordable microcontroller board developed by the
Raspberry Pi Foundation. Building upon the success of the Raspberry Pi Pico, the Pico W variant
brings wireless connectivity to the table, making it an even more versatile platform for embedded
projects. In this article, we will provide a comprehensive overview of the Raspberry Pi Pico W,
highlighting its key features and capabilities.
Features:
Raspberry Pi Pico W:
The Raspberry Pi Pico W is based on the RP2040 microcontroller, which was designed by Raspberry
Pi in-house. It combines a powerful ARM Cortex-M0+ processor with built-in Wi-Fi connectivity,
opening up a range of possibilities for IoT projects, remote monitoring, and wireless communication.
The Pico W retains the same form factor as the original Pico, making it compatible with existing Pico
accessories and add-ons.
RP2040 Microcontroller:
At the core of the Raspberry Pi Pico W is the RP2040 microcontroller. It features a dual-core ARM
Cortex-M0+ processor running at 133MHz, providing ample processing power for a wide range of
applications. The microcontroller also includes 264KB of SRAM, which is essential for storing and
manipulating data during runtime. Additionally, the RP2040 incorporates 2MB of onboard flash
memory for program storage, ensuring sufficient space for your code and firmware.
Wireless Connectivity:
The standout feature of the Raspberry Pi Pico W is its built-in wireless connectivity. It includes an
onboard Cypress CYW43455 Wi-Fi chip, which supports dual-band (2.4GHz and 5GHz) Wi-Fi
802.11b/g/n/ac. This allows the Pico W to seamlessly connect to wireless networks, communicate
with other devices, and access online services. The wireless capability opens up new avenues for IoT
projects, remote monitoring and control, and real-time data exchange.
RESULT:
What is MicroPython?
MicroPython is a Python 3 programming language re-implementation targeted for microcontrollers
and embedded systems. MicroPython is very similar to regular Python. Apart from a few exceptions,
the language features of Python are also available in MicroPython. The most significant difference
between Python and MicroPython is that MicroPython was designed to work under constrained
conditions.
Because of that, MicroPython does not come with the entire pack of standard libraries. It only
includes a small subset of the Python standard libraries, but it includes modules to easily control and
interact with the GPIOs, use Wi-Fi, and other communication protocols.
Thonny IDE:
Thonny is an open-source IDE which is used to write and upload MicroPython programs to different
development boards such as Raspberry Pi Pico, ESP32, and ESP8266. It is extremely interactive and
easy to learn IDE as much as it is known as the beginner-friendly IDE for new programmers. With
the help of Thonny, it becomes very easy to code in Micropython as it has a built-in debugger that
helps to find any error in the program by debugging the script line by line.
You can realize the popularity of Thonny IDE from this that it comes pre-installed in Raspian OS
which is an operating system for a Raspberry Pi. It is available to install on r Windows, Linux, and
Mac OS.
5. After completing the installation, open Thonny IDE. A window as shown in the following figure
should open.
CONNECTIONS:
PROGRAM
LED:
from machine import Pin
import time
LED = Pin(16, Pin.OUT)
while True:
LED.value(1)
time.sleep(1)
LED.value(0)
time.sleep(1)
CONNECTIONS:
RGB:
from machine import Pin
from time import sleep_ms,sleep
r=Pin(16,Pin.OUT)
y=Pin(17,Pin.OUT)
g=Pin(18,Pin.OUT)
while True:
r.value(1)
sleep_ms(1000)
r.value(0)
sleep_ms(1000)
y.value(1)
sleep(1)
y.value(0)
sleep(1)
g.value(1)
sleep(1)
g.value(0)
sleep(1)
CONNECTIONS:
Thus the different programs using python was studied and carried out.
EXP NO:
INTERFACING SENSORS WITH RASPBERRY PI
DATE
AIM:
To interface the IR sensor and Ultrasonic sensor with Raspberry Pi.
1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Jumper Wires few
4 Micro USB Cable 1
5 IR Sensor 1
6 Ultrasonic sensor 1
CONNECTIONS:
IR Sensor:
ULTRASONIC SENSOR:
def measure_distance():
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()
while True:
dist = measure_distance()
print(f"Distance : {dist} cm")
if dist <= 10:
buzzer.value(1)
utime.sleep(0.01)
else:
buzzer.value(0)
utime.sleep(0.01)
utime.sleep(0.5)
RESULT:
Thus the interfacing sensors with Raspberry Pi was tested and carried out.
EXP NO: COMMUNICATE BETWEEN ARDUINO AND
DATE RASPBERRY PI
AIM:
To write and execute the program to Communicate between Arduino and Raspberry Pi
using any wireless medium (Bluetooth).
1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Arduino Uno Development Board 1
4 Jumper Wires few
5 Micro USB Cable 1
6 Bluetooth Module 2
CONNECTIONS:
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:
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')
RESULT:
Thus the program to Communicate between Arduino and Raspberry Piusing any wireless medium
(Bluetooth) was written and executed.
EXP NO:
CLOUD PLATFORM TO LOG THE DATA
DATE
AIM:
To set up a cloud platform to log the data from IoT devices.
1 Blynk Platform 1
CLOUD PLATFORM-BLYNK:
Blynk is a smart platform that allows users to create their Internet of Things applications without the
need for coding or electronics knowledge. It is based on the idea of physical programming & provides
a platform to create and control devices where users can connect physical devices to the Internet and
control them using a mobile app.
Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign
in using the registered Email ID.
A new device will be created. You will find the Blynk Authentication Token Here. Copy it as it is
necessary for the code.
Step 5: Now go to the dashboard and select ‘Web Dashboard’.
From the widget box drag a switch and place it on the dashboard screen.
Step 6:
On the switch board click on Settings and here you need to set up the Switch. Give any title to it and
Create Datastream as Virtual Pin.
Configure the switch settings as per the image below and click on create.
Configure the final steps again.
With this Blynk dashboard set up, you can now proceed to program the Raspberry Pi Pico W board
to control the LED.
Step 7:
To control the LED with a mobile App or Mobile Dashboard, you also need to setup the Mobile
Phone Dashboard. The process is similarly explained above.
Install the Blynk app on your smartphone The Blynk app is available for iOS and Android. Download
and install the app on your smartphone. then need to set up both the Mobile App and the Mobile
Dashboard in order to control the LED with a mobile device. The process is explained above.
Thus the cloud platform to log the data from IoT devices was carried out.
EXP NO: LOG DATA USING RASPBERRY PI AND UPLOAD IT TO
DATE THE CLOUD PLATFORM
AIM:
To write and execute the program Log Data using Raspberry Pi and upload it to the cloud
platform.
CONNECTIONS:
adc = machine.ADC(4)
i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR=i2c.scan()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)
wlan = network.WLAN()
wlan.active(True)
wlan.connect("Wifi_Username","Wifi_Password")
BLYNK_AUTH = 'Your_Token'
"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
lcd.clear()
while True:
ADC_voltage = adc.read_u16() * (3.3 / (65536))
temperature_celcius = 27 - (ADC_voltage - 0.706)/0.001721
temp_fahrenheit=32+(1.8*temperature_celcius)
print("Temperature in C: {}".format(temperature_celcius))
print("Temperature in F: {}".format(temp_fahrenheit))
lcd.move_to(0,0)
lcd.putstr("Temp:")
lcd.putstr(str(round(temperature_celcius,2)))
lcd.putstr("C ")
lcd.move_to(0,1)
lcd.putstr("Temp:")
lcd.putstr(str(round(temp_fahrenheit,2)))
lcd.putstr("F")
time.sleep(5)
blynk.virtual_write(3, temperature_celcius)
blynk.virtual_write(4, temp_fahrenheit)
blynk.log_event(temperature_celcius)
blynk.run()
time.sleep(5)
RESULT:
Thus the program Log Data using Raspberry Pi and upload it to the cloud platform was written
and executed.
EXP NO:
DESIGN AN IOT-BASED SYSTEM
DATE
AIM:
To design a Smart Home Automation IOT-based system.
5 LED or Relay 1
CONNECTIONS:
import time
import network
import BlynkLib
from machine import Pin
led=Pin(16, Pin.OUT)
wlan = network.WLAN()
wlan.active(True)
wlan.connect("Wifi_Username","Wifi_Password")
BLYNK_AUTH = 'Your_Token'
"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
LCD DISPLAY:
while True:
lcd.move_to(3,0)
lcd.putstr("Ediylabs")
sleep(5)
lcd.clear()
Connection
pwm = PWM(Pin(1))
pwm.freq(50)
while True:
for position in range(1000,9000,50):
pwm.duty_u16(position)
sleep(0.01)
for position in range(9000,1000,-50):
pwm.duty_u16(position)
sleep(0.01)
Connection
IN1 = Pin(12,Pin.OUT)
IN2 = Pin(13,Pin.OUT)
IN3 = Pin(14,Pin.OUT)
IN4 = Pin(15,Pin.OUT)
sequence = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
while True:
for step in sequence:
for i in range(len(pins)):
pins[i].value(step[i])
sleep(0.001)
Connection: