Saturday, June 1, 2013

Automatic Room light and fan control with visitor counting

This system will control the room light and fan by taking inputs as person count, room light intensity and room temperature.

Working:  When there is no person entered in to room then person count will become zero and then it will not check intensity and temperature, so that bulb and fan will be in OFF mode.  If a person enters into a room then the person count will be increased by '1' and if person exits a room then person count will decrease. If person count is greater than zero then it will check intensity and temperature. If the room intensity is less than the threshold then the bulb will glow otherwise will be in OFF mode only and if the room temperature exceeds the threshold temperature then the fan will start moving otherwise will be in OFF mode only.

Pictorial view of system arrangement 
  to download C-code
  to see its working video-1
to see working video-2

Here is the main flow chart


This flow chart is used to indicate person count, but in practical we dont need to implement this part

 Output Results:
case'1': when there is no person in the room
LEDs showing count value is '0'

case'2': when there are two persons in the room, room condition the intensity is less and temperature is greater than the threshold temperature


                       
NOTE:
1. Threshold values may be different in practical 
2. push buttons will be replaced by IR sensor network in practical 
3. person count LEDs are not needed in practical


Friday, May 31, 2013

Automatic Train Gate controlling / Metro Train Indication

This Embedded System is designed to control the  train junction Gates automatically when train passes across this junction. Here we arrange two IR sensors before the junction ( distance > 500mtrs from Gate junction) and also two IR sensors after the junction (distance  > 500mtrs from Gate junction). The IR sensors which are before the junction will indicate that the train is coming near to the junction and the IR sensors which are after the junction will indicate that the train has passed away the junction.
The pictorial arrangement of the system is shown here
                       

when train comes in between the 2 IR sensors the output of both the photodetectors will become logic - '1'. Then the system will send logic high to the Siren, Red light will glow , green light will turn off and the Gate will close. 
Here is the simple flow chart showing its operation

           
                               

Case'1': When train is coming near to the junction
 to see the video output
  to download the C-code                                                     Servo Motor
    
Case '2': When train passed away the junction
                       

NOTE: 
Here we  connected single servo motor b'coz it is a prototype. but in real time we will use two servo motors, and also here the Siren is replaced by Yellow color LED and IR sensors are replaced by optocouplers.

Thursday, May 30, 2013

Password based Door locking system

This is a  8051 based security project, we can lock and unlock the door electronically. Electronic door locking systems are used in Bank lockers, home lockers, main doors and prison  etc.,

Working: When we give correct UserID and Password then only we can UNLOCK and LOCK the door otherwise we can't operate it. If we entered correct userID and password it will show authenticated message on LCD screen otherwise Invalid userID or Access Denide. Then you can select one of the option LOCK DOOR and UNLOCK DOOR.
Here is the functional flow chart 


to download C-code
Here we are showing how door can be locked and unlocked mechanically and electrically with mechanical body of the door                                                                         Available Product
 Schematic Diagram:  
  to see the video output
case'1': when the door is locked

case'2':When the door is unlocked
NOTE: I haven't connected any motor driver here, but practically we can interconnect opto-coupler or motor driver H-bridge.

Sunday, May 19, 2013

Smart Energy Meter using 8051

This is just a prototype of original meter having some features.
conventional analog energy meters indicates the meter reading by scrolling down the mechanical number plates. It will not show daily power consumption and cost/unit to the consumer. This is a prototype of Smart Energy meter it indicates the meter reading and cost/unit and also it can send the same information to the power grid. This is developed using AT89c51 microcontroller.

Features:
> Security UserID and Password
> Read Units anytime and price/unit
> send no.of Units to grid
> we can change userID and Password 
> get back to previous menu

to download code

Here is the functional tree chart

high level Flow chart: it gives behavioral working model of the meter


 Results: to see the video how it works 
  to see working video
 When user selected read units : displaying no.of units and price/unit
 

when user selected send to grid : it sent ID and no.of units consumed by the user
                                
NOTE: meter readings are calculated by IR LED and PhotoDetector. In between the IR LED and PhotoDetector there will be a rotating magnetic coil of a conventional meter. But here we replaced it with one push button connected to the 555 timer(Monostable multivibrator), because we can't represent them here.

Saturday, May 18, 2013

Change UserID and Password using 8051

Here is the one example showing how to change Predefined "UserID" and "Password" manually by user. If we want to change userID or password, it will take  inputs from the keypad two times for confirmation. If the two inputs are matched then one of them will be assigned to the predefined one , otherwise it will display "not matched" inputs and jumps to main menu. The following flow chart describes how it works

to see the output 
  to download the code
                It is showing initial user ID and Password when the power is ON.

It is showing new UserID and Password when the user changed successfully 

                                

Monday, May 13, 2013

Automatic Room light Controller with OpAmp:

Automatic Room light Controller with OpAmp: 

It is more important to save power. here the one way to save the power by automatic controlling of room lights. This is also an application of OpAmp based comparator. This is based on the light intensity in the room, here we use LDR(light dependent resistor) who's resistance decreases with increase in room light intensity. There is a choice that you can change the threshold level to your desired level so that it can operate at that intensity level. It does not require any microcontroller or any other programmable devices.

components procured:
>LDR  
>OpAmp 741
>resistor 10k
>BC547 transistor
>SPDT relay 12V
>1N4001 diode 
>battery and a bulb

 here i connected the LDR output to the inverting terminal and a threshold voltage of 1.5v is connected to the non-inverting terminal. so that whenever the light intensity increases the LDR output will decrease and if it is less than the threshold the output of the opamp will be +Vsat=+5v.This will trun on the BC547 so that relay will be connected as shown here, bulb will not glow
                                           VLDR >1.5v ; transistor ON; Light OFF;

  to see the output                                             A book on OPAMP circuits

 when the room light intensity decreases LDR resistance will decrease and voltage across the resistor goes high. when it is greater than the threshold opamp output goes to -Vsat=-5v. then the BC547 will goes to the cutoff region (OFF state). so the light will glow.
                                  VLDR < 1.5v ; transistor OFF; light ON;

Automatic room fan controller using OpAmp:


This is the another application of a comparator. This can save the power and we don't need to switch ON and OFF the ceiling FAN manually. here we can set the threshold voltage to our desired value. The ceiling fan will be switched ON when the temperature increases the threshold value. We are using LM35 sensor to sense the room temperature. The sensitivity of this LM35 sensor is 10mv/ 'C. I want that fan to be switched on when the temperature increases more than 27'C. so set my threshold voltage to
                                 Vthreshold = 27'C x 10mv = 270mv = 0.27V

                      here the room temperature is 26'c so the output voltage is < 0.27V ; Fan off
  to see the output 



 when the temperature increases to 27'c or more, the output voltage of LM35 will increases to more than 0.27V. so that opamp output will goes to +Vsat=+5v. This will switch ON the transistor and so relay connects. This will switch ON the ceiling fan.

    here the temperature is 28'c so the output voltage >0.27v; fan ON      LM35 sensor

4x4 matrix keypad interfacing to 8051(AT89c51)

//----- reading the char/number from the keyboard----//
#include<reg51.h>
#define ROW P1      // assigning  Port1 to ROW
#define COL P2       // assigning port2 to COL
void msdelay(unsigned int value);
void sertx(unsigned char );
unsigned char dat[4][4]
={'0','1','2','3',    // keypad read data
                          '4','5','6','7',
                           '8','9','A','B',
                           'C','D','E','F'};
void main()
{
 unsigned char colloc,rowloc; // initializing column and row locations
 TMOD=0x20;               // timer -2 mode-2
 TH1=0xFD;                 // preset FD
 SCON=0x50;              // serial control reg. 9600 baudrate
 TR1=1;                      // timer-1 start
 COL=0xFF;               // make column pins input
 while(1)
 {
   do
   {
    ROW=0x00;      // write "00000000" to ROW  
       colloc=COL;  // read column input
    colloc&=0x0F;  // hide higher nibble
    }while(colloc!=0x0f); //check whether any change in column pins
    do
    {
     do
     {
      msdelay(20);
      colloc=COL;
      colloc&=0x0F;
      }while(colloc==0x0F);
      msdelay(20);                  // check column after 20ms
      colloc=COL;                  // it is for accuracy if there is any random spike it can ignore
      colloc&=0x0F;
      }while(colloc==0x0F);
    while(1)
    {
     ROW=0xFE;         // write "1111_1110" on to ROW
     colloc=COL;
     colloc&=0x0F;
     if(colloc!=0x0F// if there is a change in column/button pressed
     { 
      rowloc=0;          
       break;
      }
      ROW=0xFD;  // writing "1111_1101" onto the ROW
      colloc=COL;
      colloc&=0x0F;
      if(colloc!=0x0F // if there is a change in column/button pressed
       {
        rowloc=1;
        break;
        }
      ROW=0xFB;   // writing "1111_1011" onto the ROW
      colloc=COL;
      colloc&=0x0F;
      if(colloc!=0x0F // if button pressed / change in column
       {
        rowloc=2;
        break;
        }
      ROW=0xF7;     // writing "1111_0111" onto ROW
      colloc=COL;
      colloc&=0x0F;
      if(colloc!=0x0F// if button pressed/change in column
      {
       rowloc=3;
       break;
       }
       }
   if(colloc==0x0E)
   sertx( dat[rowloc][0]);
   if(colloc==0x0D)
   sertx(dat[rowloc][1]);
   if(colloc==0x0B)
   sertx(dat[rowloc][2]);
   if(colloc==0x07)
    sertx(dat[rowloc][3]);
    }
  }
void sertx(unsigned char x)
{
 SBUF=x;
 while(TI==0);
 TI=0;
 }
void msdelay(unsigned int value)
{
 unsigned int i,j;
 for(j=0;j<value;j++)
 for(i=0;i<100;i++) ;
  }

Result:   to see output

Dc motor interfacing to 8051(AT89c51)

Controlling  2 motors in both forward, reverse and one forward one reverse operation according to the 4 input pins. When input is 1110=both in forward;1101=both in reverse;1011=left one forward right one stop; 0111=left one stop and right one forward.

MicroCode:

#include<reg51.h>
sfr sw=0x90;
sbit EN1=P2^0;
sbit EN2=P3^0;
sbit MTR1_0=P2^1;
sbit MTR1_1=P2^2;
sbit MTR2_0=P3^1;
sbit MTR2_1=P3^2;
void main( )
{
EN1=0;
MTR1_0=0;
MTR1_1=0;
EN2=0;
MTR2_0=0;
MTR2_1=0;
while(1)
{
EN1=1;
EN2=1;
if(sw==0xFE)
{
MTR1_0=0;
MTR1_1=1;
MTR2_0=0;
MTR2_1=1;
}
else if(sw==0xFD)
{
MTR1_0=1;
MTR1_1=0;
MTR2_0=1;
MTR2_1=0;
}
else if(sw==0xFB)
{
MTR1_0=0;
MTR1_1=1;
MTR2_0=0;
MTR2_1=0;
}
else if(sw==0xF7)
{
MTR1_0=0;
MTR1_1=0;
MTR2_0=0;
MTR2_1=1;
}
else
{
MTR1_0=0;
MTR1_1=0;
MTR2_0=0;
MTR2_1=0;
 }
}
}

Result:   to see output

Display messages on 16x16 LCD using 8051(AT89c51)

#include<reg51.h>
sfr ldata=0x90;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit sw1=P3^0;
sbit sw2=P3^1;
sbit sw3=P3^2;
void Tdelay(unsigned int );
void lcdcmd(unsigned char );
void lcd_data(unsigned char );
void lcd_init(void);
void lcd_display(unsigned char *c );

int main( )
{
while(1){
lcd_init( );
if (sw1==0)
lcd_display("Embedded Systems");
if (sw2==0)
lcd_display("Electronics");
if(sw3==0)
lcd_display("Embedded programming");
}
}
void Tdelay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<1275;j++);
}
void lcd_init( void)
{
lcdcmd(0x38);
Tdelay(25);
lcdcmd(0x0F);      //display on , cursor blinking
Tdelay(25);
lcdcmd(0x06);       //  cursor increment
Tdelay(25);
lcdcmd(0x80);        // start at row-1
Tdelay(25);
lcdcmd(0x01);        // clear screen
Tdelay(10);

}
void lcdcmd(unsigned char cvalue )   // lcd in command mode
{
ldata=cvalue;
rs=0;
rw=0;
en=1;
Tdelay(1);
en=0;
}
void lcd_display(unsigned char *dvalue)
{
unsigned int x;
for(x=0;dvalue[x]!=0;x++)
{
lcd_data(dvalue[x]);
Tdelay(10);
}
}
void lcd_data(unsigned char dvalue)       // lcd in data mode
{
ldata=dvalue;
rs=1;
rw=0;
en=1;
Tdelay(1);
en=0;
}

Result: to see output

16x2 LCD interfacing to 8051(AT89c51)

Displaying “Embedded Systems” in 16x2 LCD display  
#include<reg51.h>
sfr ldata=0x90;
sbit rs=P2^0;   // LCD reset
sbit rw=P2^1;  // read/write control
sbit en=P2^2;  // LCD r/w enable
void Tdelay(unsigned int );     // functions initializaion
void lcdcmd(unsigned char );
void lcd_data(unsigned char );
void lcd_init(void);
void lcd_display(unsigned char *c );

int main( )
{
while(1){
lcd_init( );
 lcd_display("Embedded Systems");
}
}
void Tdelay(unsigned int ms)  // providing some delay
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<1275;j++);
}
void lcd_init( void)
{
lcdcmd(0x38);
Tdelay(25);
lcdcmd(0x0F);      //display on , cursor blinking
Tdelay(25);
lcdcmd(0x06);       //  cursor increment
Tdelay(25);
lcdcmd(0x80);      // start at row-1
Tdelay(25);
lcdcmd(0x01);      // clear screen
Tdelay(10);
}
void lcdcmd(unsigned char cvalue ) // LCD in command mode opearaion
{
ldata=cvalue;
rs=0;
rw=0;
en=1;
Tdelay(1);
en=0;
}
void lcd_display(unsigned char *dvalue)
{
unsigned int x;
for(x=0;dvalue[x]!=0;x++)
{
lcd_data(dvalue[x]);
Tdelay(10);
}
}
void lcd_data(unsigned char dvalue) // LCD in data mode operation
{
ldata=dvalue;
rs=1;
rw=0;
en=1;
Tdelay(1);
en=0;
}
  

Result: to see output

Serial data transmission using 8051(AT89c51)

  Transmit the following strings when the corresponding switch is pressed
     “EMBEDDED SYSTEMS” ; “ EMBEDDED PROGRAMMING” ; “ASSEMBLY PROGRAMMING”;   

#include<reg51.h>
sbit sw1=P2^0;  // switchs connecting port-2 lower pins 0,1,2
sbit sw2=P2^1;
sbit sw3=P2^2;
void Transmit(unsigned char ); // function initialization
void main()
{
unsigned char x;
unsigned char name1[ ]="Embedded systems";
unsigned char name2[ ]="Embedded programming";
unsigned char name3[ ]="Assembly programming";
TMOD=0x20;  // timer-1 mode-2
TH1=0xFD;      // preset value FD
SCON=0x50;  //Serial control 9600 baud rate selection
TR1=1;            // run timer-1
while(1)
{
if(sw1==0)      // check if switch 1 is pressed
{
for(x=0;x<=16;x++ // transmitting 17 characters to serial port
{
Transmit(name1[x]);
}
}
if(sw2==0)       // check if switch 2 is pressed
{
for(x=0;x<=20;x++)   // transmitting 21 characters to the serial port
{
Transmit(name2[x]);
}
}
if(sw3==0)    // check if switch 3 is pressed
{
for(x=0;x<=20;x++// transmitting 21 characters to the serial port
{
Transmit(name3[x]);
}
}
}
}

// serial port declaration
void Transmit(unsigned char i)
{
SBUF=i;
while(TI==0); // wait until serial Transmit interrupt flag  overflow
TI=0;
}




Result: to see output                                                         serial cable
 

Pulse Width Modulation(PWM) using 8051

PWM has many applications in real world , for example:  to control the speed of a DC motor we use PWM signal. Here we are generating a PWM signal having  250ms , 125ms and 50ms pulse widths.


#include<reg51.h>
void T0delay(void);
sbit Mybit=P1^0;
// output PWM port
void main(void)
{
unsigned char x;
while(1)
{
Mybit=1;
for(x=0;x<10;x++) 
// generating 250ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<10;x++) 
// generating 250ms delay for OFF time
{
T0delay();
}
Mybit=1;
for(x=0;x<5;x++) 
// generating 125ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<5;x++) 
// generating 125ms delay for OFF time
{
T0delay();
}
Mybit=1;
for(x=0;x<2;x++) 
// generating 50ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<2;x++) 
// generating 50ms delay for OFF time
{
T0delay();
}
}
}

// 25ms delay function
void T0delay(void)
{
TMOD=0X01;
// timer-0 mode-1
TL0=0xFE;
TH0=0xA5;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}




Result: to see output

Pulse Generator using 8051


Providing Delay using internal timers of AT89c51. We are generating a pulse wave having 250ms ON time and 250ms OFF time. microcontroller clock time is 1.085us.
                                             25ms / 1.085us = 23041 = A5FE in hex
                                             25ms x 10 = 250ms                                             

#include<reg51.h>
void T0delay(void);
// delay function
sbit Mybit=P2^0;
// output port
void main(void)
{
unsigned char x;
while(1)
{
Mybit= ~Mybit;
// inverter
for(x=0;x<10;x++)
T0delay();
}
}
void T0delay(void)
{
TMOD=0x01;
// selecting timer-0 mode-1
TL0=0xFE;  
// count starts at A5FE
TH0=0xA5;
TR0=1;       
// timer-0 run
while(TF0==0);
//wait until timer-0 flag overflow
TR0=0;
// then stop timer-0
TF0=0;
// reset the overflow flag
}





  


Result:     to see output

Serial LEDs using 8051


connecting LEDS to P2 pins and SWITCHES to P1 pins.

#include<reg51.h>
sfr leds=0xA0;
sfr SW=0x90;
unsigned int x;
int main ()
{

while(1)
{
if(SW==0xFE)
{
      leds=
0x08 ;                       //"1000"
    for( x=0;x<20000;x++);      
// providing some random delay    
    leds=0x04;                          //"0100"
    for( x=0;x<20000;x++);
    leds=0x02;                          //"0010"
    for( x=0;x<20000;x++);
    leds=0x01;                          //"0001"
    for( x=0;x<20000;x++);
}
else if(SW==0xFD)
{   
    leds=0x01;                          //"0001"

    for( x=0;x<20000;x++);
    leds=0x02;                          //"0010"
    for( x=0;x<20000;x++);
    leds=0x04;                          //"0100"
    for( x=0;x<20000;x++);
    leds=0x08;                          //"1000"
    for( x=0;x<20000;x++);
 }
else if(SW==0xFB)
{   
    leds=0x09;                        //"1001"

    for( x=0;x<20000;x++);
    leds=0x06;                       //"0110"
    for( x=0;x<20000;x++);
  }
else if(SW==0xF7)
{
    leds=0x06;                      //"
0110"
    for( x=0;x<20000;x++);
    leds=0x09;                     //"1001"
    for( x=0;x<20000;x++);
}
else
    leds=0x00;
}
}

 
  to see output
  

Sunday, May 12, 2013

Wednesday, April 3, 2013

Automatic Room light Controller using OpAmp:

It is more important to save power. here is the one way to save the power by automatic controlling of room lights. This is also an application of OpAmp based comparator. This is based on the light intensity in the room, here we use LDR(light dependent resistor) who's resistance decreases with increase in room light intensity. There is a choice that you can change the threshold level to your desired level so that it can operate at that intensity level. It does not require any microcontroller or any other programmable devices.

components procured:
>LDR  
>OpAmp 741
>resistor 10k
>BC547 transistor
>SPDT relay 12V
>1N4001 diode 
>battery and a bulb

 here i connected the LDR output to the inverting terminal and a threshold voltage of 1.5v is connected to the non-inverting terminal. so that whenever the light intensity increases the LDR output will decrease and if it is less than the threshold the output of the opamp will be +Vsat=+5v.This will trun on the BC547 so that relay will be connected as shown here, bulb will not glow
 VLDR >1.5v ; transistor ON; Light OFF;       LDR sensor         
 when the room light intensity decreases LDR resistance will decrease and voltage across the resistor goes high. when it is greater than the threshold opamp output goes to -Vsat=-5v. then the BC547 will goes to the cutoff region (OFF state). so the light will glow.
                                  VLDR < 1.5v ; transistor OFF; light ON;               SPDT Relay