ES & IoT Lab Manual R21 Final
ES & IoT Lab Manual R21 Final
LAB MANUAL
LABORATORY
YEAR / SEM : 03 / 06
REGULATION : 2021
COURSE COORDINATOR :
COURSE FACULTY :
ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY
LABORATORY MANUAL
PREPARED BY APPROVED BY
Assistant Professor
Department of Electronics and
Communication Engineering
COURSE OBJECTIVES :
COURSE OUTCOMES:
Aim :
To write an assembly language program to perform the Arithmetic and Logical Operations in
8051.
1. Personal Computer
2. Keilμ Vision5 software.
Theory:
In 8051 assembly language programming, arithmetic and logical operations are fundamental
for manipulating data and controlling program flow. Instructions like ADD, SUB, AND, OR,
XOR, and NOT are used to perform arithmetic and logical operations on data stored in
registers or memory locations. These operations are crucial for tasks such as arithmetic
calculations, bitwise manipulation, and decision making in embedded systems. Mastery of
these operations enables efficient programming for various applications in the 8051
microcontroller, enhancing its versatility and functionality.
Procedure :
Program :
Output :
Result :
Aim :
3. Personal Computer
4. Keilμ Vision5 software.
Theory:
Generating a square waveform with 8051 involves toggling an output pin at a certain
frequency, achieved by alternately setting and clearing the pin within a specified time
interval. This is typically accomplished by implementing a delay loop to control the on-off
timing of the pin, thus creating a square wave with equal high and low durations.
Procedure :
Program :
#include <REG51xD2.H>
/* delay routine */
for (;x>0;x--);
main ()
delay(100);
P0 = Off;
delay(100);
Output :
Result:
Aim :
To write an ALP to toggle the content of port 0 continuously using timer delay in between.
1. Personal Computer
2. Keilu Vision5 software.
Theory:
Procedure :
Program :
ORG 0000H
MOV A, #01H ; Load accumulator A with value 01H (binary 0000 0001)
DELAY:
MOV R2,#255 ; Load register R2 with value 255 for delay loop
LABEL:
DJNZ R2, LABEL ; Decrement R2, if not zero, jump to LABEL for loop
Output :
Result :
The program successfully interfaces with the On-Chip ports of the 8051 microcontroller,
controlling the logic levels of the pins as intended. The output is verified using a logic
analyzer, confirming the expected behavior of the hardware interfacing.
EX.NO: PROGRAMMING USING SERIAL PORTS IN
DATE : 8051
Aim :
To implement serial communication using 8051 microcontroller and facilitating data transfer
between the microcontroller and external devices through serial ports.
1. Personal Computer
2. Keilμ Vision5 software.
3. Proteus Software
Theory:
Serial communication in 8051 involves sending and receiving data one bit at a time over a
single wire. The microcontroller's UART (Universal Asynchronous Receiver/Transmitter)
module is commonly used for serial communication, with the TXD (Transmit Data) and RXD
(Receive Data) pins for transmitting and receiving data, respectively. The communication
parameters such as baud rate, data bits, stop bits, and parity must be configured to ensure
proper data transfer.
Procedure :
Program :
#include<reg51.h>
void main(void)
TH1 = 0xFD; // Set Timer 1 reload value for baud rate generation
SCON = 0x50; // Configure serial port for mode 1 (8-bit UART, variable baud
rate)
void send(char x)
SBUF = x; // Load character to be sent into the Serial Buffer Register (SBUF)
Output :
Result :
Successfully implement the 8051 microcontroller can transmit and receive data serially,
enabling communication with external devices such as Virtual terminal .
EX.NO: DESIGN OF A DIGITAL CLOCK USING
DATE : TIMERS/COUNTERS IN 8051
Aim :
To implement a digital clock using timers/counters in the 8051 microcontroller for accurate
timekeeping and display.
1. Personal Computer
2. Keilμ Vision5 software.
3. Proteus Software
Theory:
Digital clocks utilize timers/counters in the 8051 microcontroller to generate precise time
intervals. Timer 0 and Timer 1 are commonly used for timekeeping applications, with Timer
0 often used for generating accurate time base interrupts. By configuring timer modes and
setting appropriate timer values, the 8051 can maintain accurate timekeeping functionality.
Displaying the time typically involves interfacing with a 7-segment display or an LCD to
present the time in a human-readable format.
Procedure :
Program :
#include <reg51.h>
#define msec 1
unsigned int arr[10] = {0x40, 0xF9, 0x24, 0x30, 0x19, 0x12, 0x02, 0xF8, 0x00, 0x10};
sbit d4 = P1^0;
sbit d3 = P1^1;
sbit d2 = P1^2;
sbit d1 = P1^3;
sbit d0 = P1^4;
sbit d = P1^5;
unsigned int j, k;
void main() {
v1 = v2 = v3 = v4 = v0 = v5 = v6 = 0;
while (1) {
v0 = v0 + 1;
if (v0 == 130) {
v0 = 0;
v1 = v1 + 1;
P2 = 0xFF;
d = 1;
d3 = d2 = d4 = d0 = d1 = 0;
P2 = arr[v1];
delay(msec);
if (v1 == 10) {
v1 = 0;
v2 = v2 + 1;
P2 = 0xFF;
d0 = 1;
d4 = d3 = d1 = d = d2 = 0;
P2 = arr[v2];
delay(msec);
if (v2 == 6) {
v2 = 0;
v3 = v3 + 1;
P2 = 0xFF;
d1 = 1;
d2 = d4 = d3 = d = d0 = 0;
P2 = arr[v3];
delay(msec);
if (v3 == 10) {
v3 = 0;
v4 = v4 + 1;
P2 = 0xFF;
d2 = 1;
d3 = d4 = d1 = d = d0 = 0;
P2 = arr[v4];
delay(msec);
if (v4 == 6) {
v4 = 0;
v5 = v5 + 1;
P2 = 0xFF;
d3 = 1;
d0 = d2 = d1 = d = d4 = 0;
P2 = arr[v5];
delay(msec);
if (v5 == 10) {
v5 = 0;
v6 = v6 + 1;
P2 = 0xFF;
d4 = 1;
d3 = d2 = d1 = d = d0 = 0;
P2 = arr[v6];
delay(msec);
if (v6 == 1 && v5 == 2) {
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
}
delay(msec);
P2 = 0xFF;
Output :
Result :
The digital clock implemented using timers/counters in the 8051 microcontroller successfully
displayed accurate time, verified by observing the output signals using a logic analyzer. The
clock accurately updated its display at regular intervals, demonstrating the functionality of
the implemented design.
EXPERIMENTS
USING ARM
EX.NO: INTERFACING ADC & DAC
DATE :
Aim :
To develop a C-Language program for reading an on-chip ADC, convert into decimaland to
display it in PC and to generate a square wave depending on this ADC reading. The ADC
input is connected to any analog sensor/ on board potentiometer.
Theory :
The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic
clocking
for the A/D converters is provided by the VPB clock. A programmable divider is included in
each converter, to scale this clock to the 4.5 MHz (max) clock needed by the successive
approximation process. A fully accurate conversion requires 11 of these clocks. The ADC
cell
can measure the voltage on any of the ADC input signals.
ARM Board has one potentiometer for working with A/D Converter. Potentiometer outputs
are in the range of 0V to 3.3V. Switch select in right position for reading the Potentiometer
value by ADC.
Procedure :
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using FlashMagic.
Software.
ADC Program :
#include<lpc214x.h>
intk,z;
#define rs 30
#define en 29
void LCD(void);
void co(unsigned char );
void da(unsigned char );
void lcds(unsigned char* p);
intmain()
{
int in1; /*VARIABLE DECLARATION*/
LCD(); /*INITILIZES LCD*/
while(1){
PINSEL0|=1<<12|1<<13; /* SELECTING PINSEL FOR ADC1.0*/
AD1CR=0x01200401; /*SETTING VALUE ON ADC CONTROL
REGISTER*/
}
//--------------------------FUNCTION TO DISPLAY DATA ON LCD----------------------/
void da(unsigned char y)
{
IO0PIN=(IO0PIN&0xFFFFC3FF)|((y&0xF0)>>4)<<10;
IO0SET=1<<rs;
IO0SET=1<<en;
for(k=0;k<20000;k++);
IO0CLR=1<<en;
for(k=0;k<1000;k++);
IO0PIN=(IO0PIN&0xFFFFC3FF)|(y&0x0F)<<10;
IO0SET=1<<rs;
IO0SET=1<<en;
for(k=0;k<20000;k++);
IO0CLR=1<<en;
}
//----------------------------LCD INITIALIZATION------------------------/
void LCD(void)
{
unsigned char i[]={0x28,0x0f,0x01,0x06},j;
IO0DIR|=0x60003c00;
//for(k=0;k<1000;k++);
for(j=0;j<4;j++)
{
co(i[j]);
for(z=0;z<1000;z++);
}
}
/*----------------------------DISPLAY STRING ON LCD---------------------------*/
void lcds(unsigned char* p)
{
for(;*p!=0;p++)
{
da(*p); }
}
ARM DETAILS
P0.29 ADCO0.2
PO.10 RS LCD PIN
P1.11 CE LCD PIN
Output :
DAC Program :
Square Wave :
for(j=0;j<count;j++)
{
for(i=0;i<120;i++);
}
}
////////// MAIN /////////////////
int main (void)
{
Init_DAC();
while(1)
{
Write_DAC(00);
delay(100); // change this value to change Frequency
Write_DAC(1023); // change this value to change Amplitude
delay(80); // change this value to change Frequency
}
}
Sin Wave :
const unsigned int tab[256] = { 514 , 526 , 538 , 551 , 563 , 576 , 588 , 600 , 613 , 625 , 637
, 649 , 661 , 673 , 685 , 696 , 708 , 719 , 731 , 742 , 753 , 764 , 775 , 785 , 796 , 806 , 816 ,
826,836 , 845 , 855 , 864 , 873 , 881 , 890 , 898 , 906 , 914 , 922 , 929 , 936 , 943 , 949 , 956 ,
962, 967 , 973 , 978 , 983 , 987 , 992 , 996 , 1000 , 1003 , 1006 , 1009 ,1012 , 1014 , 1016 ,
1018 , 1019 , 1020 , 1021 , 1021 , 1021 , 1021 , 1021 , 1020 , 1019 , 1018 , 1016 , 1014 ,
1012, 1009, 1006 , 1003 , 1000 , 996 , 992 , 987 , 983 , 978 , 973 , 967 , 962 , 956 , 949 , 943
, 936 , 929 , 922 , 914 , 906 , 898 , 890 , 881 , 873 , 864 , 855 , 845 , 836 , 826 , 816 , 806 ,
796 , 785 , 775 , 764 , 753 , 742 , 731 , 719 , 708 , 696 , 685 , 673 , 661 , 649 , 637 , 625 , 613
, 600 , 588 , 576 , 563 , 551 , 538 , 526 , 514 , 501 , 489 , 476 , 464 , 451 , 439 , 427 , 414 ,
402 , 390 , 378, 366 , 354 , 342 , 331 , 319 , 308 , 296 , 285 , 274 , 263 , 252 , 242 , 231 , 221
, 211 , 201 , 191 , 182 , 172 , 163 , 154 , 146 , 137 , 129 , 121 , 113 , 105 , 98 , 91 , 84 , 78 ,
71 , 65 , 60 , 54 , 49 , 44 , 40 , 35 , 31 , 27 , 24 , 21 , 18 , 15 , 13 , 11 , 9 , 8 , 7 , 6 , 6 , 6 , 6 , 6
, 7 , 8 , 9 , 11 , 13 , 15 , 18 , 21 , 24 , 27 , 31 , 35 , 40 , 44 , 49 , 54 , 60 , 65 , 71 , 78 , 84 , 91 ,
98 , 105 , 113 , 121 , 129, 137 , 146 , 154 , 163 , 172 , 182 , 191 , 201 , 211 , 221 , 231 , 242 ,
252 , 263 , 274 , 285 , 296 , 308 , 319 , 331 , 342 , 354 , 366 , 378 , 390 , 402 , 414 , 427 , 439
, 451 , 464 , 476, 489 , 501 };
////////// InitDAC /////////////////
Init_DAC()
{
// Convert Port pin 0.25 to function as DAC
PINSEL1 = 0X00080000;
DACR = 0;
}
Init_DAC();
while(1)
{
for(i=0;i<255;i++)
Write_DAC(tab[i]);
}
}
TriangleWave :
Init_DAC();
while(1)
{
for(i=0;i<1024;i++)
Write_DAC(i);
for(i=1023;i>0;i--)
Write_DAC(i);
}
}
ARM DETAILS
Output :
Result:
The C-Language program for reading an on-chip ADC, convert into decimal and
to display it in PC was written & output is verified with the ADC input is
connected to on board potentiometer.
The DAC, convert digital data into analog signal& output is verified with the DAC
input and the square wave has been generated to display it in CRO.
EX.NO: BLINKING OF LEDS AND LCD
DATE :
Aim :
To develop a ‘C’ program to make the LED blink(including delay routine) and LCD module.
TheLCD display should come in the desired line and column and Upon change in LED delay
program the speed should vary.
Theory :
LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
electrons are able to recombine with holes and energy is released in the form of light. This
effect is called electroluminescence and the color of the light is determined by the energy gap
of the semiconductor.
The LCD display should come in the desired line and column to print the letters of the
program and verified the outputs.
Procedure :
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
#include <lpc214x.h>
/* -------------------MAIN FUNCTION--------------------------*/
intmain()
{
inti;
/*SETTING DIRECTION OF P1.16-P1.23 ,P0.15,P0.16 AS OUTPUT*/
IODIR1|=0x00FF0000;
IODIR0|=0x00018000;
/*----------INFINITE LOOP TO BLINK LED CONTINUOUSLY---------*/
while(1)
{
/*SETTING P1.16-P1.23 ,P0.15,P0.16 AS HIGH TO POWER ON LED*/
IOSET1 = 0x00FF0000;
IOSET0 = 0x00018000;
ARM DETAILS
PI.16 S&L ENABLE PIN
PI.17 S&L ENABLE PIN
PI.18 S&L ENABLE PIN
PI.19 S&L ENABLE PIN
P1.20 S&L ENABLE PIN
P1.21 S&L ENABLE PIN
PI.22 S&L ENABLE PIN
P1.23 S&L ENABLE PIN
PI.24 S&L ENABLE PIN
P1.25 S&L ENABLE PIN
P1.26 S&L ENABLE PIN
P1.27 S&L ENABLE PIN
P1.28 S&L ENABLE PIN
P1.29 S&L ENABLE PIN
PI.30 S&L ENABLE PIN
PI.31 S&L ENABLE PIN
Output :
#include<lpc214x.h>
#define rs 30
#define en 29
int k;
void co (unsigned char);
void da (unsigned char);
void LCD (void);
void lcds (unsigned char*);
intmain()
{
LCD();
co(0x80);
lcds(" ROHINI COLLEGE ");
while(1);
}
//-----------------------------COMMAND---------------------------------/
void co(unsigned char x)
{
IO0PIN=(IO0PIN&0xFFFFC3FF)|((x&0xF0)>>4)<<10;
IO0CLR=1<<rs;
IO0SET=1<<en;
for(k=0;k<100000;k++);
IO0CLR=1<<en;
IO0PIN=(IO0PIN&0xFFFFC3FF)|(x&0x0F)<<10;
IO0CLR=1<<rs;
IO0SET=1<<en;
for(k=0;k<100000;k++);
IO0CLR=1<<en;
}
//-------------------------------DATA----------------------------------/
void da(unsigned char y)
{
IO0PIN=(IO0PIN&0xFFFFC3FF)|((y&0xF0)>>4)<<10;
IO0SET=1<<rs;
IO0SET=1<<en;
for(k=0;k<100000;k++);
IO0CLR=1<<en;
IO0PIN=(IO0PIN&0xFFFFC3FF)|(y&0x0F)<<10;
IO0SET=1<<rs;
IO0SET=1<<en;
for(k=0;k<100000;k++);
IO0CLR=1<<en;
}
//----------------------------LCD INITIALIZATION------------------------/
void LCD(void)
{
unsigned char i[]={0x28,0x0f,0x01,0x06},j;
IO0DIR|=0x60003c00;
for(k=0;k<1000;k++);
for(j=0;j<4;j++)
{
co(i[j]);
for(k=0;k<200000;k++);
}
}
//-------------------------------LCDSTRING------------------------------/
void lcds(unsigned char* p)
{
for(;*p!=0;p++)
{
da(*p);
for(k=0;k<200000;k++);
}
}
ARM DETAILS
PO.IO RS LCD PIN
PI.11 CE LCD PIN
Output :
Result :
The C-Language program to make the LED blink was developed and output was verified and LCD
module and the output was verified on the LCD on the desires line and column/address successfully.
EX.NO: INTERFACING KEYBOARD AND STEPPER
DATE : MOTOR
Aim :
To develop a C-Language program for Interfacing the Key pressed in the Keypad in the terminal and
interfacing the running stepper motor either in clock- wise or counter-clock- wise and the direction of
the rotation .
Theory :
KEYBOARD
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to
connect only one key or switch with an I/O line. If the number of keys in the system exceeds
the more I/O lines are required. To reduce the number of I/O lines the keys are connected in
the matrix circuit. Keyboards use a matrix with the rows and columns made up of wires. Each
key acts like a switch. When a key is pressed a column wire makes contact with row wire and
completes a circuit. For example 16 keys arranged in a matrix circuit uses only 8 I/O lines.
STEPPER MOTOR
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central
metal gear. To make the motor shaft turn, first one electromagnet is given power, which
makes the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's
teeth are thus aligned to the first electromagnet, they are slightly offset from the next
electromagnet.
So when the next electromagnet is turned on and the first willtum off, the gear rotates slightly
to align with the next one and from there the process is repeated. Each of those slight
rotations is called a "step." In that way, the motor can be turned to a precised angle. There are
two basic arrangements for the electromagnetic coils: bipolar and unipolar.
Procedure :
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
KEYBOARD PROGRAM :
#include<lpc214x.h>
/*--------PROTOTYPE DEFINITION----------------*/
void serini(void);
void tr(unsigned char);
unsigned char key_wa(void);
unsigned char keypad(void);
void delay(void);
/*-------------MAIN FUNCTION-------------*/
intmain()
{
inti,k;
unsigned char a[]="PRESS ANY KEY";
serini();
while(1)
{
/*----------ROUTINE TO DISPLAY PRESS ANY KEY STRING ON SERIAL----
-------------*/
tr(0x0d);
tr(0x0A);
for(i=0;a[i]!=0;i++)
tr(a[i]);
tr(0x0d);
tr(0x0A);
/*--------------SENDING PRESSED KEY ON SERIAL--------------------------
-----------*/
tr(key_wa());
IO0DIR|=0x0F00<<8;
{
switch(IO0PIN & 0xF000<<8) //check which one of the key is pressed
{
case 0x0007000<<8 : delay();return '9' ;
case 0x000B000<<8 : delay();return '0' ;
case 0x000D000<<8 : delay();return 'a' ;
case 0x000E000<<8 : delay();return 'b' ;
}
}
IO0PIN =(IO0PIN&0xFFF0FFFF)|0x0B00<<8; //Move 3rd scan data to port
line
if(( IO0PIN & 0xF000<<8 )!= 0xF000<<8)//Scan any key is pressed in 2nd row
{
switch(IO0PIN & 0xF000<<8) //Check which one of the key is
//pressed in 2nd row
{
case 0x0007000<<8 : delay();return '5' ;
case 0x000B000<<8 : delay();return '6' ;
case 0x000D000<<8 : delay();return '7' ;
case 0x000E000<<8 : delay();return '8' ;
}
}
IO0PIN =(IO0PIN&0xFFF0FFFF)|0x0700<<8; //Move 4th scan data to port line
if(( IO0PIN & 0xF000<<8 )!= 0xF000<<8) //Check any key is pressed in 1st
// row
{
switch(IO0PIN & 0xF000<<8) //Check which one of the key is
//pressed in 1st row
{
case 0x0007000<<8 : delay();return '1' ;
case 0x000B000<<8 : delay();return '2' ;
case 0x000D000<<8 : delay();return '3' ;
case 0x000E000<<8 : delay();return '4' ;
}
}
return 0xFF;
}
/*---------------------------------KEYPAD WAIT FUNCTION----------------------------------*/
OUTPUT :
counter clockwise
#include<lpc214x.h>
/*-----------------MAIN FUNCTION-------------------*/
int main(void)
{
inti;
IO1DIR|=0x3c<<24;
while(1)
{
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x1<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x3<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x2<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x6<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x4<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0xC<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x8<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x9<<26;
for(i=0;i<25000;i++);
}}
Anti clockwise
#include<lpc214x.h>
/*-----------------MAIN FUNCTION-------------------*/
int main(void)
{
inti;
IO1DIR|=0x3c<<24;
while(1)
{
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x1<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x3<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x2<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x6<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x4<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0xC<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x8<<26;
for(i=0;i<25000;i++);
IO1PIN=(IO1PIN&0xc3FFFFFF)|0x9<<26;
for(i=0;i<25000;i++);
}
}
OUTPUT :
Result :
The C-Language program for running stepper motor either in clock-wise or counter-clock-
wise direction.
MINIPROJECTS
FOR IOT
EX.NO: GARBAGE SEGREGATOR AND BIN LEVEL
DATE : INDICATOR
Aim :
To design the simulation and circuit for a Garbage Segregator and Bin Level Indicator system
and verify the output.
1. PC
2. Wokwi Online Simulation Platform
Procedure :
1. Open the Google Chrome and Open the https://wokwi.com/ Online Simulation
platform.
2. To select the Components to start the designs per circuit diagram.
3. To write and upload the coding from the simulation platform .
4. Finally Verified the output of the simulation.
Theory :
The Garbage Segregator and Bin Level Indicator system aims to efficiently manage waste
disposal by automatically segregating different types of garbage and providing real-time
information about the level of waste in the bins. This system utilizes various sensors and
actuators along with microcontroller-based control to achieve its functionality.
Circuit Diagram :
Pin Details:
VCC 5V
GND GND
SDA A4
SCL A5
VCC 5V
GND GND
TRIG 6
ECHO 7
VCC 5V
GND GND
TRIG 3
ECHO 4
SERVO PIN
VCC 5V
GND GND
PWM 5
Program :
LiquidCrystal_I2C lcd(0x27,16,2);
Servo servo;
int trigPin = 3;
int echoPin = 4;
int servoPin = 5;
int trigPin2 = 6;
int echoPin2 = 7;
int active = 0;
long duration, dist, average;
long aver[3]; //array for average
long duration2, dist2, average2;
long aver2[3];
int percent;
byte gauge_left[8]
= { B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111}; // left
part of empty gauge [
byte gauge_center[8] =
{ B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; // center
part of empty gauge _
byte gauge_right[8]
= { B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111}; // right
part of empty gauge ]
byte gauge_fill[8]
= { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111}; // filled
gauge
char buffer[10];
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the 16x2 lcd module
lcd.createChar(0, gauge_left); // create special character on position 0, gauge left [
lcd.createChar(1, gauge_center); // create special character on position 1, gauge center _
lcd.createChar(2, gauge_right); // create special character on position 2, gauge right ]
lcd.createChar(3, gauge_fill); // create special character on position 3, gauge fill █
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin2, OUTPUT);
servo.write(0); //close cap on power on
lcd.backlight(); // enable backlight for the LCD module
lcd.setCursor(0,0);
lcd.print("INITIALIZATION");
delay(100);
servo.detach();
}
void measure() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(30);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration / 2) / 29.1; //obtain distance
}
void measure2() {
digitalWrite(trigPin2, LOW);
delayMicroseconds(5);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(30);
digitalWrite(trigPin2, LOW);
pinMode(echoPin2, INPUT);
duration2 = pulseIn(echoPin2, HIGH);
dist2 = (duration2 / 2) / 29.1; //obtain distance
}
void loop() {
for (int i = 0; i <= 2; i++) { //average distance
measure();
aver[i] = dist;
delay(10); //delay between measurements
}
dist = (aver[0] + aver[1] + aver[2]) / 3;
if(active == 0){
for (int i = 0; i <= 2; i++) { //average distance
measure2();
aver2[i] = dist2;
delay(10); //delay between measurements
}
dist2 = (aver2[0] + aver2[1] + aver2[2]) / 3;
percent = ((float)dist2/50.0) * 100.0;
if (percent > 100)
{
percent = 100;
}
Serial.print(percent);
Serial.print("Distance: ");
Serial.println(dist2);
Output :
Result :
The simulation and circuit design of the Garbage Segregator and Bin Level Indicator system
were successfully implemented using Wokwi Online Platform.
EX.NO: IMAGE PROCESSING BASED FIRE
DATE : DETECTION
Aim:
The aim of the experiment is to develop a Python program using OpenCV that detects the of
fire in an image.
1. PC
2. Python software
Procedure :
Theory :
Fire detection is a crucial aspect of safety and security systems in various environments such
as buildings, forests, and industrial sites. Image processing offers a non-intrusive method for
detecting fires in visual data. In this experiment, we utilize OpenCV, a powerful library for
computer vision tasks in Python, to analyze video or image frames for signs of fire. The
system identifies the characteristic features of flames, such as color, shape, and motion, to
distinguish them from the background. By implementing algorithms for fire detection, we
aim to create a reliable and efficient solution for early fire detection and alerting.
Program :
import cv2
import numpy as np
import tkinter as tk
lower = np.array([0, 50, 50]) # Lower bound for red color in HSV
upper = np.array([10, 255, 255]) # Upper bound for red color in HSV
no_red = cv2.countNonZero(mask)
return True
else:
return False
def upload_image():
root = tk.Tk()
return file_path
def main():
image_path = upload_image() # Obtain the image path from the file dialog
frame = cv2.imread(image_path)
cv2.imshow("Original", frame)
fire_detected = detect_fire(frame)
if fire_detected:
print("Fire detected!")
# You can add further actions here such as sounding an alarm or sending
notifications.
else:
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
else:
if __name__ == "__main__":
main()
Output :
Result :
The developed fire detection system demonstrates promising results in identifying fire
occurrences in images and videos. The system successfully detects flames based on their
characteristic features and distinguishes them from non-fire elements in various
environments.
EX.NO:
VEHICLE NUMBER PLATE DETECTION
DATE :
Aim:
The aim of this experiment is to develop a system for detecting vehicle number plates using
OpenCV and Python.
1. PC
2. Python software
Procedure :
Theory :
Vehicle number plate detection is a crucial task in various applications such as traffic
monitoring, automatic toll collection, and law enforcement. In this experiment, we utilize
OpenCV, an open-source computer vision library, along with Python programming
language to implement a number plate detection system. The process involves several steps
including image preprocessing, edge detection, contour detection, and character recognition.
By leveraging these techniques, we aim to accurately locate and extract number plates from
input images or video streams.
Program :
import cv2
import numpy as np
import tkinter as tk
plat_detector = cv2.CascadeClassifier(cv2.data.haarcascades +
"haarcascade_russian_plate_number.xml")
root = tk.Tk()
file_path = filedialog.askopenfilename()
exit()
img = cv2.imread(file_path)
exit()
cv2.imshow('Plates', resized_img)
cv2.destroyAllWindows()
Output :
Result :
The vehicle number plate detection system successfully detects and recognizes number
plates from the input images, demonstrating the effectiveness of the implemented approach
in real-world scenarios.
EX.NO:
SMART LOCK SYSTEM
DATE :
Aim:
The aim of this experiment is to design and simulate a Smart Lock System and verify its
output.
• PC
• Wokwi Online Simulation Platform
Theory :
The Smart Lock System is an advanced security mechanism that allows access to a door or a
lock using electronic means rather than traditional physical keys. It employs various
technologies such as RFID (Radio Frequency Identification), Bluetooth, or biometric
recognition to authenticate and authorize users. The system typically consists of a controller
unit, a locking mechanism, and sensors. When a user attempts to access the locked area, the
system verifies their identity based on the provided credentials. If the authentication is
successful, the locking mechanism is triggered to unlock the door, granting access to the
authorized user.
Circuit Diagram :
Pin Details:
VCC 3.3V
GND GND
SDA SDA
SCL A4
SERVO PIN
VCC Vin
GND GND
PWM 10
KEYBOARD PIN
R1 7
R2 6
R3 5
R4 4
C1 3
C2 2
C3 1
C4 0
Procedure :
1. Open the Google Chrome and Open the https://wokwi.com/ Online Simulation
platform.
2. To select the Components to start the designs per circuit diagram.
3. To write and upload the coding from the simulation platform .
4. Finally Verified the output of the simulation.
Program :
#define Password_Length 5 // the length of the password, if the password is 4 digits long set
this to 5
int Position = 0; // position of the servo
char Particular[Password_Length]; // the password length
char Specific[Password_Length] = "1234"; // the password which is called specific in the
code, change this to anything you want with the numbers 0-9 and the letters A-D
byte Particular_Count = 0, Specific_Count = 0; // counts the amount of digits and and checks
to see if the password is correct
char Key;
const byte ROWS = 4; // the amount of rows on the keypad
const byte COLS = 4; // the amount of columns on the keypad
char keys[ROWS][COLS] = { // sets the rowns and columns
// sets the keypad digits
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
bool SmartDoor = true; // the servo
// the pins to plug the keypad into
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {3, 2, 1, 0};
Keypad myKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); // gets the data
from the keypad
// locked charcater
byte Locked[8] = {
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11011,
B11111
};
// open character
byte Opened[8] = {
B01110,
B00001,
B00001,
B11111,
B11011,
B11011,
B11011,
B11111
};
void setup()
{
servo.attach(10); // attaches the servo to pin 10
ServoClose(); // closes the servo when you say this function
lcd.init(); // initializes the lcd
lcd.backlight(); // turns on the backlight
lcd.setCursor(0,0); // sets the cursor on the lcd
lcd.print("Vector X"); // prints the text/charater
lcd.setCursor(0,1); // sets the cursor on the lcd
lcd.print("Arduino Lock!!!"); // prints text
delay(4000); // waits 4 seconds
lcd.clear(); // clears the lcd diplay
void loop()
{
if (SmartDoor == 0) // opens the smart door
{
Key = myKeypad.getKey(); // the word key = myKeypad which gets the value
{
lcd.clear( ); // clears the lcd diplay
ServoClose( ); // closes the servo motor
lcd.setCursor(2,0); // sets the cursor on the lcd
lcd.print("Door Closed"); // prints the text to the lcd
lcd.createChar(0, Locked); // prints the locked character
lcd.setCursor(14,0); // sets the cursor on the lcd
lcd.write(0); // prints the first character when you are on the door closed page
delay(3000); // waits 3 seconds
SmartDoor = 1; // closes the door
}
}
Key = myKeypad.getKey(); // gets the keys you press from the keypad
if (Key)
{
Particular[Particular_Count] = Key;
lcd.setCursor(Particular_Count, 1); // sets the cursor on the lcd
lcd.print("*"); // prints '*' instead of the password
Particular_Count++; // counts the length of the password
}
Output :
Result :
The simulation of the Smart Lock System demonstrates its ability to authenticate users and
grant access accordingly. The system successfully unlocks the door when presented with
valid credentials, thus verifying its functionality and effectiveness as a security mechanism.