loading

Idea

I was thinking in some daily problems i have and onde of them is that i have always forgotten my window open and when starts to rain outside all of my stuff gets wet. So, I decided to use a rain sensor which closes my window when it gets wet. This is a part of the whole project because i couldn't manage time to construct the device which will actually closes the window, but to demonstrate the system i used the code and materials bellow to make one led turn on when the sensor activate.

Materials:

- Protoboard x1

http://produto.mercadolivre.com.br/MLB-716294209-p...

-Arduino UNO3 x1

http://www.institutodigital.com.br/pd-363bf9-ardui...

-Rain sensor x1

http://produto.mercadolivre.com.br/MLB-719086015-m...

- Jumpers x6

http://produto.mercadolivre.com.br/MLB-841642978-c...

-USB Cable x1

-LED X1

http://www.institutodigital.com.br/pd-154a7c-kit-2...




Code:



/* Flame Sensor analog example.
Code by Reichenstein7 (thejamerson.com)

For use with a Rain Sensor with an analog out!

To test view the output, point a serial monitor such as Putty at your Arduino.
- If the Sensor Board is completely soaked; "case 0" will be activated and " Flood " will be sent to the serial monitor. - If the Sensor Board has water droplets on it; "case 1" will be activated and " Rain Warning " will be sent to the serial monitor. - If the Sensor Board is dry; "case 2" will be activated and " Not Raining " will be sent to the serial monitor.

*/

// lowest and highest sensor readings:
const int sensorMin = 0; // sensor minimum

const int sensorMax = 1024; // sensor maximum

int led = 4;

void setup() {

//initialize serial communication @ 9600 baud:

Serial.begin (9600);

pinMode (led, OUTPUT);

}

void loop() {

// read the sensor on analog A0:

int sensorReading = analogRead(A0);

// map the sensor range (four options):

// ex: 'long int map(long int, long int, long int, long int, long int)'

int range = map(sensorReading, sensorMin, sensorMax, 0, 4);

// range value:

switch (range) {

case 0: // Sensor gettin wet

Serial.println("Chuva");

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltade level)

delay(50);

digitalWrite(led, LOW); // turn the LED off by making the voltade LOW

delay()50;

break;

// wait for a second

case 1: // Sensor getting wet

Serial.println("Umido");

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(500); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(500);

break;

case 2: // Sensor dry - To shut this up delete the " Serial.println("Not Raining"); " below.

Serial.println("Seco");

break;

}

delay(1); //delay between reads

}

<p>This would be great where we used to live in Okinawa :) It rains often.</p>

About This Instructable

102views

2favorites

More by GuilhermeO17:No More Wet Room 
Add instructable to: