Introduction
A raindrop sensor, or raindrop detection sensor, is used to detect whether it is raining and also the rainfall. It is widely used in the automatic wiper system, smart lighting system and sunroof system of automobiles.
Components
– 1 * SunFounder Uno board
– 1 * USB data cable
– 1 * Raindrop Sensor
– 1 * Raindrop Sensor Analyser
– 1 * 4-Pin anti-reverse cable
– 1 * 2-Pin ribbon cable
Experimental Principle
In a raindrop/water wiper system, detect the rainfall with the raindrop sensor and convert the signals detected by a controller. Then the interval of the wiper scraping will be set automatically based on the signals, so as to control the motor of the wiper conveniently. In a smart lighting system, detect the driving environment and adjust the lighting mode automatically, to improve the driving safety in a severe environment. In a smart sunroof system, detect whether it is raining – to close the sunroof automatically if raindrops are detected.
In this experiment, we use the module and the LED attached to pin 13 of the SunFounder Uno board to build a circuit. Hook up A0 of the raindrop sensor module with A0 of the Uno board, D0 to pin 7. Drop some water onto the sensor. The more drops, the lower value at A0. When the quantity of the raindrops exceeds the threshold set, D0 will change from high to low and the corresponding LED will light up.
The schematic diagram is shown as below:
Experimental Procedures
Step 1: Build the circuit
Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)
Step 3: Compile
Step 4: Upload the sketch to SunFounder Uno board
Now drop some water onto the sensor, When the quantities of the raindrops exceeds the threshold, the LED on the raindrop sensor module and that hooked up with pin 13 of the SunFounder Uno board light up; otherwise, they stay turned off. You may adjust the sensitivity of the sensor by the potentiometer on it, which means to set the threshold for it.
Code
/****************************************************** name:Raindrop Detection function:drop some water onto the sensor, When the quantities of the raindrops exceeds the threshold, the LED on the raindrop sensor module and that hooked up with pin 13 of the SunFounder Uno board light up *******************************************************/const int analogPin=A0; //the AO of the module attach to A0 const int digitalPin=7; //D0 attach to pin7 const int ledPin=13; //pin 13 built-in led int Astate=0; //store the value of A0 boolean Dstate=0; //store the value of D0void setup() { pinMode(ledPin,OUTPUT); //set the ledPin as OUTPUT pinMode(digitalPin,INPUT); //set digitalPin as INPUT Serial.begin(9600); //initialize the serial monitor }void loop() { Astate=analogRead(analogPin); //read the value of A0 Serial.print(“A0: “); Serial.println(Astate); //print the value in the serial monitor Dstate=digitalRead(digitalPin); //read the value of D0 Serial.print(“D0: “); Serial.println(Dstate); if(Dstate==HIGH) { digitalWrite(ledPin,LOW); } else //if the value of D0 is LOW { digitalWrite(ledPin,HIGH); //turn on the led } } |