Engineers Garage

  • Electronic Projects & 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

Rain Detector using 8051 Microcontroller

By Salman Khan April 21, 2008

 

Now we are going to learn how to make a rain detector with only a LCD and a microcontroller to control your hole circuit. This controller will give you the data that what is the speed of the rain. You can also make a circuit from this that to make water flowing from the pipe this will take the detail of the water flowing from the pipe and tell you the speed of the rain. You can fit it at very far places and the places where you go very less. You can place it in the office, in that office form where you cannot see outside you cannot tell or predict the speed of rain like if you are in a hall or in the mall. You can make a automatic system which can help you to work in the further process. So let’s begin.

Aim: To make rain detector with microcontroller 8051.
Principle: It works in the principle of water conducting electricity.
Material required: present, 8051 microcontroller (I used P89C52X2BN), LCD, connecting wire, hole pin, plastic pipe, battery.
Description:
This rain detector is working in very simple process of water conducting electricity. The wire which is connected to Vcc and the other four wires are made to be inside the pipe whose image is given below. It has different levels namely slow, moderate, high, and very high via BC547 transistor. Port P2 is connected to data pins of LCD and P1.0, P1.1, P1.2, are connected to RS, RW, and EN pins of LCD respectively.
When there is no rain it will show No Rain. As the rain starts the pipe gets filled slowly wire at different levels get some positive voltage, due to conducting nature of the water. Due to this voltage is sent to their respective pins on controller. When first drop fall in that pipe, LCD displays the message slow. When the speed of rain increases the water get touched the wire and show different message like slow, moderate, high, very high.
 
Overview of 8051 Microcontroller based Rain Detector
Fig. 1: Overview of 8051 Microcontroller based Rain Detector
How to make:
You only have to see the circuit and connect the wire.
For PCB users:
Do the etching process and whatever required making the circuit or buying readymade prototype PCB containing holes. This is your headache just make a PCB design and makes it.
Advantages:
      1.      It will tell you the detail of the rain.
      2.      Very less energy is required to give a good result.
      3.      You can make your own.
      4.      Work with a basic principle.
      5.      Very easy to make
      6.      Easy to handle.
      7.      Lots more
Disadvantages:
      1.      It could not store the data for further use but if you what you can make this out of it.
       2.      It has to on for 24 hour.
      3.      Alert will be start when rain is there, sometime it disturb human.
      4.      Cannot tell you from far has to be very close to it to find out that whether it is raining or what.
      5.      It has to be in few heights so that something could not enter it.

 

 

Project Source Code

###

// Program to make a Rain detector with Microcontroller 8051 from Salman
#include<REG52X2.H>
sbit rs=P1^0; //register select pin
sbit rw=P1^1; //read/write pin
sbit e=P1^2; //enable pin
sbit firs=P3^0; //pin connected to 1st level of pipe
sbit seco=P3^1; //pin connected to 2nd level of pipe
sbit thir_3=P3^2; //pin connected to 3rd level of pipe
sbit fort=P3^3; //pin connected to 4th level of pipe
sbit spkr_on=P3^4;  
sbit spkr_off=P3^5; // pin to off speaker

void delay(int k) //delay function
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<1275;j++);
}

void write(int j) //write function
{
rs=1; //selecting command register
rw=0; //selecting to write
P2=j; //putting value on the pins
e=1; //strobe the enable pin
delay(1);
e=0;
return;
}

void cmd(int j) //command function
{
P2=j; //put the value on pins
rs=0; //selecting command register
rw=0; //selecting to write
e=1; //strobe enable pin
delay(1);
e=0;
return;
}

void puts(char *a) //puts function to print a string
{
unsigned int p=0;
for(;a[p]!=0;p++)
write(a[p]);
}

void lcd_init(void) // function to initialise the LCD
{
cmd(0x38); //setting 8-bit interface, 2 lines, 5*7 Pixels
delay(1);
cmd(0x0e); //turning on underline visible cursor
delay(1);
cmd(0x01); //clearing screen
cmd(0x80); //moving cursor to the begining of line 1 of LCD
}

void main()
{
firs=seco=thir=fort=spkr_off=1; //configuring as input pins
firs=seco=thir=fort=spkr_off=0; //lowering input pins
spkr_on=1; // making speaker on pin high,as it works on negative logic
while(1)
{
while(firs==0&&seco==0&&thir==0&&fort==0&&spkr_off==0) //condition when pipe is empty
{
lcd_init(); // initialising LCD
puts("No Rain"); //printing No Rain on lcd
}
while(firs==1&&seco==0&&thir==0&&fort==0&&spkr_off==1) //condition when 1st level
{
lcd_init();
puts("Slow"); //printing Slow on lcd
}
while(firs==1&&seco==1&&thir==0&&fort==0&&spkr_off==1) //condition when 2nd level
{
lcd_init();
puts("Moderate"); //printing Moderate on lcd
}
while(firs==1&&seco==1&&thir==1&&fort==0&&spkr_off==1) //condition when 3rd level
{
lcd_init();
puts("High"); //printing High on lcd
}
while(firs==1&&seco==1&&thir==1&&fort==1&&spkr_off==1) //condition when 4th level
{
lcd_init();
puts("fort;Very High"); //printing Very High on lcd
spkr_on=0;// Enabling speaker
}
while(firs==1&&seco==1&&thir==1&&fort==1&&spkr_on==0&&spkr_off==1)//enabling high speaker_off pin
{
spkr_on=1;//disabling speaker
}
}
}

###

 


Circuit Diagrams

Circuit-Diagram-8051-Microcontroller-Based-Rain-Detector


Filed Under: Electronic Projects
Tagged With: 8051 microcontroller, rain detector
 

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: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

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

  • Identification of a 6 pin smd chip (sto-23-6) marked E2
  • Dynacord enter protect
  • IGBTs without negative gate drive
  • Need suggestions in task NI6363 retrigger (analog trigger)
  • Monte-Carlo simulation error on ADE-XL

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • using a RTC in SF basic
  • Does US electric code allow branching ?
  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault
  • Sump pit water alarm - Kicad 9

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

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

  • Electronic Projects & 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