0
791views
A 230 V AC bulb is connected through a relay at P2.2. A light sensor is connected at P3.4. A light sensor produces logic high in dark condition,

Write a ‘C’ program to switch ‘ON’ the bulb in ‘DARK’ condition and switch it OFF in ‘LIGHT’ condition.


1 Answer
0
9views

The program

# include< reg51.h>

sbit relay = P2^2;

sbit sensor = P3^4;

void main (void)

{

    sensor=1; $\hspace{1.5cm}$ //P3.4 as input line

    relay = 0; $\hspace{1.5cm}$ // Intially OFF

    while (1)

    {

        while ( sensor == 0); $\hspace{1.5cm}$ // check sensor if no dark wait//

        relay = 1; $\hspace{1.5cm}$ // dark ON bulb//

        while ( sensor == 1); $\hspace{1.5cm}$ // wait till dark//

    }

}

$\hspace{4.5cm}$**OR**

# include< reg51.h>

sbit relay = P2^2;

sbit sensor = P3^4;

void main (void)

{

    sensor=1;$\hspace{1.5cm}$ //P3.4 as input line

    relay = 0; $\hspace{1.5cm}$// Intially OFF


    while (1)

    {

        if ( sensor == 1) $\hspace{1.5cm}$ // check sensor if dark //

            relay = 1; $\hspace{1.5cm}$ // ON bulb//

        else

        relay=0;

    }

}
Please log in to add an answer.