Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Automatic Room Lighting

By Gurmeet Singh April 21, 2008

 

Image of IR Sensor used in 8051 Microcontroller based Automatic Room Lights

Fig. 1: Image of IR Sensor used in 8051 Microcontroller based Automatic Room Lights

Prototype of 8051 Microcontroller based Automatic Room Lights

Fig. 2: Prototype of 8051 Microcontroller based Automatic Room Lights

Requirements:

·         2 x IR sensor module                                     

·         AT89S52 (8051 microcontroller by ATMEL corp.)

·         7805 voltage regulator

·         Crystal (11.0592 MHz)

·         LED (or a relay controlled room lighting system)

 

Pre-requisite:

About IR sensor module:

IR (Infrared Rays) sensors work on infrared waves, the module comprises of one IR led (transmitter) and one photodiode (receiver). Module consists of 3 pins namely GND, VCC (+5V) and SIG. SIG pin provides the TTL value based on the reference voltage set. It also consists of a potentiometer which can be adjusted to vary the reference voltage hence varying its range and accuracy.

This module provides a HIGH (+5V) signal when a voltage greater than reference voltage is generated and a LOW (0V) signal when it is lower than reference voltage.

These modules also have an onboard LED which glows off when an object is detected. 

Description

Description:

When an object moves into the room it passes through IR sensor 1 first and then IR sensor 2, this makes the microcontroller understand that something has moved into the room. In this situation it makes the LED to glow.

On the other hand when the last object moves out of the room it has to pass through IR sensor 2 first and then IR sensor 1, this situation helps the microcontroller to understand that no one is present in the room now, thus it glows off the LED.

In the coding part, I have used a variable “count” to count the number of objects present in the room. Count increments itself by one for every entry and decrements by one for every exit.

So when “count==0” i.e. no one is present in the room, the LED glows OFF

.

There should be a gap of minimum 1 second between every consecutive entry/exit. This is needed to ensure the accuracy of the system.

DELAY.H (user defined header file) has been used here to provide time delay in order of milliseconds according to the TIMERS in AT89S52.

IR sensors 1 and 2 are connected to PIN P1.1 and P1.2 respectively.

The LED is connected to PIN P2.0.

A reset button is connected to PIN 9 which shall be pressed in case anything goes wrong.

The IC 7805 voltage regulator provides a step down from 9V to 5V (ideal voltage for AT89S52)

The Crystal provides the desired 11.0592 MHz frequency for the microcontroller to work upon.

 

 Applications:

This system can be used to automatically control the lightings of a room to conserve electricity.

To practically implement this idea, just connect a relay to the pin where led is connected right now, this relay will further control the AC operated devices like tub lights, fans, etc.

 

Add-ons:

To make it a more user friendly system connect a 16×2 LCD with microcontroller and display the number of objects present in the room by simply feeding the “count” value to the LCD.

 

 

Project Source Code

###

 

// Coding (MAIN):


#include<reg51.h>

#include<delay.h>


sbit in=P1^1;

sbit out=P1^2;

sbit LED=P2^0;


void main()                                           

{

  int count=0;

    in=out=1;          //////   declaring ‘in’ and ‘out’ as input

 LED=0;

while(1)

 {

  if(in==1)

  {

   while(!out){}

   count++;

   LED=1;

   delay_msec(1000);

  }


  if(out==1 && count)

  {

    while(!in){}

   count--;

   delay_msec(1000);

   if(!count)

     LED=0;

  

  }

 }

}




// Coding (delay.h):


void delay_msec(int time)

{

int i=0;

while(i<time)

{

TMOD=0x10;

TH1=0xfc;

TL1=0x66;

TR1=1;

while(TF1==0);

TR1=0;

TF1=0;

i++;

}

}

###

 


Circuit Diagrams

Circuit-Diagram-8051-Microcontroller-Based-Automatic-Room-Lights


Filed Under: Electronic Projects
Tagged With: 8051, at89s52, room light
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • How to get started with RTL design?
  • CU824
  • RFsoc4x2 fpga diagram request
  • Switching Frequency For Transformer Design in QR Flyback converter?
  • 12VAC to 12VDC 5A on 250ft 12AWG

RSS Electro-Tech-Online.com Discussions

  • An Update On Tarrifs
  • Trying to use a L9110s motor driver chip
  • I want to make a CRT with some modifications But i have no Idea where to start
  • Funny Images Thread!
  • Need Help Figuring Out the Schematics Of Circuit Board

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe