Rain Sensor Interfacing with LPC2148

In this tutorial we are going to see Rain Sensor Interfacing with LPC2148.


Before start this tutorial we should know below topics. If you know already, please go further.

Components Required

  • LPC2148 Development Board
  • Rain Drop Sensor
  • LCD Module (To print the Sensor output)


Water is a basic need in every one’s life. Saving water and proper usage of water is very important. Here is an easy project which will display the rain status, so that we can make some actions for rain water harvesting or take out our cloths from outside, before its getting wet due to rain. You can also add the alarm circuit to this project.

Rain water detector will detect the rain and make an alert; rain water detector is used in the irrigation field, home automation, communication, automobiles etc. It may, however, be tinkered for a number of other applications.

Rain Drop Sensor

Raindrop sensor is basically a board on which nickel is coated in the form of lines. It works on the principal of resistance.

Rain Sensor module allows to measure moisture via analog output pins and it provides a digital output when a threshold of moisture exceeds. The module is based on the LM393 op amp.


  • Adopts high quality of RF-04 double sided material.
  • Area: 5cm x 4cm nickel plate on side,
  • Anti-oxidation, anti-conductivity, with long use time;
  • Comparator output signal clean waveform is good, driving ability, over 15mA;
  • Potentiometer adjust the sensitivity;
  • Working voltage 5V;
  • Output format: Digital switching output (0 and 1) and analog voltage output AO;
  • With bolt holes for easy installation;
  • Small board PCB size: 3.2cm x 1.4cm;
  • Uses a wide voltage LM393 comparator

Working Principle of Rain Drop Sensor

The rain sensor used is composed by two parts. The first one is the effective sensor, which is a plaque that is exposed to the rain. This plaque has two strips of conductive material, very close to each other, but without touching.

So, if we apply a voltage between the the two strips, it will be an open circuit. Nevertheless, when we expose this surface to the rain, the water that falls closes the circuit between the strips and a different voltage can be measured.

Keep in mind that when the rain drops the two strips will not be short circuited because water is not a perfect conductor. So, this sensor will act as a variable resistor, which will be lower when more water falls on the surface, connecting the stripes in more points. I’ve tested the resistance of the sensor with a multimeter after applying some water drops and it was about 65 kΩ.

The second part is the electronic circuit board responsible to process the signal from the plaque and expose it as two signals, one digital and another analog.

So, we have a digital output pin, which operates as active-low, indicating that rain is being detected or not. Since this pin is active-low, it will have a value of GND when rain is detected, and VCC when rain is not detected.

Since, as stated, the rain sensor will act as a variable resistor, it’s output will be an analog voltage that needs to be converted to this digital one. So, the electronic circuit uses a LM393 comparator to compare this analog voltage to a certain threshold and output GND or VCC accordingly.

The PCB of this electronic circuit has a potenciometer that we can change to adjust this threshold, making the sensor more or less sensible to the rain drops.

Additionally, the  sensor has an analog output with a variable voltage that depends on the resistance of the sensor and thus, on the amount of water on it.

This module can work with voltage supplies of both 3.3 V and 5 V. Just keep in mind that there can be different versions from different manufacturers.

Rain Sensor Interfacing with LPC2148


IR Sensor

  • Vcc – 5v
  • Gnd – Ground
  • D0 – P1.24


  • RS – P0.8
  • RW – P0.9
  • EN – P0.10
  • Data Lines – P0.0 – P0.7

Rain Sensor Interfacing with LPC2148

Source Code

If it is detecting rain, LCD will display “Rain Detected”. You can also add buzzer for indication.

/* Rain Sensor Interfacing with LPC2148
 * Done by EmbeTronicX

#define bit(x) (1<<x)
#define delay for(i=0;i<7000;i++);
#define RAIN (IO1PIN & (1<<24))
unsigned int i;
void lcd_int();
void dat(unsigned char);
void cmd(unsigned char);
void string(unsigned char *);
void main()
    IO0DIR =0XFFF;
    IO1DIR = 0x0;
    string("EMBETRONICX.COM ");
    while(1) {
            if(RAIN == 0) {
                    string("Rain Detected");
                    //You can also add alarm here
void lcd_int()
void cmd(unsigned char a)
    IO0CLR|=bit(8);                //rs=0
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    IO0CLR|=bit(10);               //en=0
void dat(unsigned char b)
    IO0SET|=bit(8);                //rs=1
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    IO0CLR|=bit(10);               //en=0
void string(unsigned char *p)
    while(*p!='\0') {

Troubleshooting Rain Sensor

Although this is a relatively simple sensor to interface with, some problems may arise when using it.

The first one is related to the sensitivity of the module. The configuration of the potentiometer that comes when we buy it may not be the best, so the output of the digital pin of the module is always at GND or VCC, independently if there is water or not on the sensor. So, we may have to play around with the resistor a little bit until we find a nice equilibrium.

Also, some people experience problems with the salinity of the water, which may not be conducting well enough. You can change the type of water used or add a little bit of salt to check if it solves the problem. You can also use a resistor between the two strips of the sensor to try to simulate the connectivity caused by the water drops, and check if the module works properly.

If the module doesn’t work at all, it may be a unit with defect. From my personal experience, I once bought one of these modules with a defect that was putting the digital LED with a value of GND no matter if there were raindrops or not. The problem persisted even if I changed the sensitivity of the potentiometer, and so it was really a defective unit.

NOTE: If you want to find the amount of rain, then you have to use A0 pin and ADC.

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Ads Blocker Image Powered by Code Help Pro
Ad Blocker Detected!!!

Dear User,

Thanks for visiting the site. Unfortunately, we have noticed that you are using an Ad Blocker extension in your browser.

We charge advertisers instead of the audience. We depend on Ad revenue to keep creating quality content for you. We guarantee clean ads. 


Click the AdBlock icon on your browser and click Enabled on this site to Disable AdBlock in embetronicx.com or whitelist our website.

If you still want to hide the ads, please become a Premium member. If you are a premium member already, then please log in.

Thank you for understanding.

If you are seeing this even after disabling all the ad blockers, Please report us the False Positive to [email protected]