Rain Sensor Interfacing with LPC2148

This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the Fire or Flame detection sensor with LPC2148 (ARM7). In this tutorial, we are going to see Rain Sensor Interfacing with LPC2148.

Prerequisites

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

Components Required

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

Introduction

Water is a basic need in everyone’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 rainwater harvesting or take out our clothes from outside, before its getting wet due to rain. You can also add the alarm circuit to this project.

Rainwater 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

A raindrop sensor is basically a board on which nickel is coated in the form of lines. It works on the principle 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.

Specifications

  • 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 of 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 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 raindrops 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 waterfalls 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, its output will be an analog voltage that needs to be converted to this digital one. So, the electronic circuit uses an 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 potentiometer that we can change to adjust this threshold, making the sensor more or less sensible to the raindrops.

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

Connection

IR Sensor

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

LCD

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

Rain Sensor Interfacing with LPC2148

Source Code – Rain Sensor Interfacing with LPC2148

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

/* Rain Sensor Interfacing with LPC2148
 * 
 * Done by EmbeTronicX
*/


#include<lpc214x.h>
#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;
    lcd_int();
    cmd(0x80);
    string("EMBETRONICX.COM ");
    while(1) {
            if(RAIN == 0) {
                    string("Rain Detected");
                    //You can also add alarm here
            }
            delay;delay;
            cmd(0x01);
        }
}
 
void lcd_int()
{
    cmd(0x38);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x01);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    IO0PIN&=0x00;
    IO0PIN|=(a<<0);
    IO0CLR|=bit(8);                //rs=0
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    delay;
    IO0CLR|=bit(10);               //en=0
}
 
void dat(unsigned char b)
{
    IO0PIN&=0x00;
    IO0PIN|=(b<<0);
    IO0SET|=bit(8);                //rs=1
    IO0CLR|=bit(9);                //rw=0
    IO0SET|=bit(10);               //en=1
    delay;
    IO0CLR|=bit(10);               //en=0
}
 
void string(unsigned char *p)
{
    while(*p!='\0') {
        dat(*p++);
    }
}

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 a 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 the A0 pin and ADC.

In our next tutorial, we will see how to interface the LPG gas sensor with LPC2148 (ARM7). If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader Tutorials
0 0 votes
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x