Arduino Ladder · Bozoma Innovation Hub

Band 4  ·  Night Guard

Swap  The rain alarm

Washing on the line, and a number that goes down when it gets wet. Calibration you cannot avoid doing.

Time
95 min
You need
Rain sensor board and plate, 2 LEDs, 2 resistors, passive buzzer, 11 jumper wires
At once
One per rain sensor
Before this
Finish Band 4 up to Part 9. This replaces the night guard in Part 10, and nothing earlier.

Sketches for this project

Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.

Why

The question you cannot dodge

Band 4's night guard makes you pick a number for “dark”, and it is possible to fudge it. Set the threshold anywhere near the middle and the lamp does something, and you can convince yourself that was the plan.

This build does not let you. What number counts as wet? A damp finger, three drops, a light shower and a soaking are four completely different readings, and until you have gone and measured them you cannot write a useful line of code.

So this is the same lesson as the night guard, with the escape route closed.

And it surprises everybody the first time

The number goes DOWN when it gets wet.

Dry, the two copper lines on the plate are not joined, so almost nothing flows and the reading sits high, often above 800. Water bridges them, current flows, and the reading falls. A well-soaked plate can read under 300.

In the night guard, dark was also a small number, for a completely unrelated reason. Do not carry either habit anywhere. The only way to know which way a sensor runs is to go and make it happen while watching the number.

Build

Wire it

30 min
+ − − + j i h g f e d c b a 1 5 10 15 20 25 30 35 40 45 USB ARDUINO UNO rain sensor board rain sensor board + + 220 220 + + 220 220 + + buzzer buzzer a1 a1 a25 a25 a26 a26 a27 a27 a28 a28 a3 a3 a4 a4 a40 a40 a42 a42 a5 a5 a7 a7 a8 a8 b1 b1 b25 b25 b26 b26 b27 b27 b3 b3 b4 b4 b40 b40 b42 b42 b5 b5 b7 b7 b8 b8 SCL SCL SDA SDA AREF AREF GND GND 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 IOR IOR RST RST 3V3 3V3 5V 5V GND GND GND GND VIN VIN A0 A0 A1 A1 A2 A2 A3 A3 A4 A4 A5 A5
Read the printing on your own sensor board. The three wires go by name, not by position, because the pin order differs between boards.
Before you startUSB unplugged. Take the light sensor and its resistor off the board, and take the knob off too. Its middle leg is wired to A0, which is the pin this build needs for the rain sensor. Two wires in one pin is forbidden here as everywhere, and the knob would win: your alarm would follow the knob and ignore the plate, with no error and nothing to tell you.
Which rails this page meansEverything on this page goes in rows a to e, so use the pair of rails along the bottom edge, the ones nearest row a. Band 4's own builds used the top pair, so move your two rail wires down: + rail to the Arduino's 5V pin, − rail to a GND pin, both on the bottom pair. On most boards the top rails and the bottom rails are not joined to each other, and mixing them means nothing works and nothing looks wrong.
The sensor is two pieces and only one of them may get wetThere is a small board with pins on it, and a flat plate with copper lines, joined by two wires.

Only the plate goes anywhere near water. The small board has a chip on it and must stay dry. People drown the wrong half of this sensor every year.
PartGoes toNote
The sensor board itselfPush its four pins into a25, a26, a27, a28. Its own pins fill those holes, so your wires go into row b of the same columns: b25, b26, b27, and nothing in b28, because DO stays empty. A hole takes one leg, and the five holes in a column are joined underneath.Read the printing on your board and match each wire to the column its pin is in. The pin order is not the same on every board, so do not count positions.
Sensor board VCCthe + rail
Sensor board GNDthe − rail
Sensor board AOpin A0The one that gives a number. This is the one you want.
Sensor board DOnothingLeave it empty. See the note below.
The platethe board's two screw terminals or pinsEither way round
Green lightlong b3, short b4; resistor a3 to a1; wire b1 to pin 7; a4 to − rail
Red lightlong b7, short b8; resistor a7 to a5; wire b5 to pin 8; a8 to − rail
Buzzerlong b40, short b42; wire a40 to pin 6; wire a42 to − railNo resistor. If the legs will not reach two holes apart, use b40 and b43 and move the − wire to a43.
Powerone wire, + rail to the Arduino 5V pinThe bottom pair of rails
Groundone wire, − rail to a GND pinThe bottom pair of rails
Check this twice before the USB goes in. The + rail wire must be in the pin marked 5V and the − rail wire in a pin marked GND. Swapped, the sensor board is powered backwards and is destroyed in seconds. If any part feels warm after you plug in, unplug at once and check those two wires before anything else.
Why DO stays empty, and why the little knob on the board is a trapThe board has a small screw on it and a pin marked DO. Together they give you a yes-or-no answer: wet or not wet, with the screw setting where the line is.

That sounds easier and it is worse for you. It moves the decision into a screw you cannot see, cannot write down, and cannot explain. AO gives you the number and makes you own the threshold, which is the entire subject of Band 4. Use AO. Ignore the screw.
This build wants the passive buzzerThe sketch uses tone, which needs the kind with a small green circuit board underneath. If yours is the active kind, the solid black one Band 3 asked for, it still works: it beeps at its own single note instead of the rising one. If you would rather it were exact, replace each tone(buzzerPin, ...) with digitalWrite(buzzerPin, HIGH) and each noTone(buzzerPin) with digitalWrite(buzzerPin, LOW), and put a 220 ohm resistor in its pin leg as Band 3 does. Run id_01_which_buzzer.ino if you are not sure which you have.

Upload b4_06_rain_alarm.ino and open the serial monitor at 9600, with the plate completely dry.

You should seeA steady stream of numbers, high, probably somewhere between 700 and 1023, and the word dry. The green light is on and nothing is beeping.
If it reads near 0 with a dry plateThe two plate wires are touching each other, or the plate has something conductive on it. Wipe it and separate the wires.
If the reading is only ever near 0 or near 1023, with nothing in betweenYour wire is on DO rather than AO. DO has already made the decision for you and only ever says yes or no, so analogRead sees either nothing or the full five volts and never a middle. Move the wire one pin. This is the most common fault on this build, and the little screw on the board is what decides where DO flips, which is exactly the decision you are supposed to be making yourself.
If it reads 0 all the time and never moves at allNothing is powering the sensor board. Check that VCC reaches the + rail and the + rail reaches 5V, then that the − rail really reaches a GND pin.
If the number drifts and jumps about with no pattern, wet or dryThe AO wire is loose or has come out, so A0 is floating. You met floating pins in Band 3. A floating pin does not read 0; it reads whatever it feels like, and the drifting is the giveaway.
Measure

Find your two numbers

30 min

This is the part that matters. Do it properly and write everything down.

Guess first. Before you wet anything, write a guessed reading in the middle column for all six rows. You will be wrong, and being wrong on paper is the point: it is the only way to find out which of your ideas about this sensor were made up. Band 4 asked the same of you in Part 1.

Then fill the table in for real, reading the serial monitor for each state and waiting a few seconds for the number to settle. Keep both sets of numbers.

State of the plateReadingShould this set off the alarm?
Bone dry
Breathed on, then wiped
One drop of water on it
Five or six drops spread out
Properly wet, water running off
Wet, then dried with a cloth
You should seeA wide spread, and at least one row where you genuinely are not sure of the answer in the third column. That row is the interesting one and it is why this is a judgement rather than a calculation.

Now choose wetLevel. Pick a number that sits between the last reading you would ignore and the first reading you would act on.

Then choose dryLevel, and make it noticeably higher. Not one higher. Fifty or a hundred higher.

Why two numbers instead of oneTry one first, if you want to see it: set dryLevel equal to wetLevel and put a single drop right on the boundary. The alarm will start and stop several times a second, because the reading wobbles across the line.

With 500 to alarm and 700 to clear, the plate has to genuinely dry out before it goes quiet, and no amount of wobble in between changes anything. You met this in Band 4 with the light threshold and you will meet it again in Band 6 as the deadband. Three bands, one idea.

Put your two numbers in the sketch, upload, and test all six states from your table again.

You should seeIt agreeing with the third column of your own table, every time. If it disagrees anywhere, your numbers are wrong and your table is right.
The honest note about leaving it outside

These plates corrode. Current passing through water eats the copper, slowly, the whole time the board is powered and the plate is wet. A plate left in the rain for a week is a measurably different plate by the end of it, and its readings will have drifted.

That is not a fault. It is what they are, and it is why real rain sensors are built differently and cost more. If you build something permanent from this, plan to re-measure your two numbers every few weeks, and write in your log what you found.

Change it

Make it yours

35 min
Bronze
Add a button that silences the buzzer without disarming the alarm, so the red light stays on. Then say why somebody would want that, in one sentence, thinking about who has to live with the device.
Silver
Make it report how wet rather than wet or not: three levels, with a different beep rate for each. Your table already contains the numbers you need.
Gold
Make it only power the sensor when it is about to read, by running the sensor's VCC from a spare Arduino pin instead of from 5V, and switching that pin on for a moment before each reading. Then explain in your log why this makes the plate last much longer.
Why Gold worksCorrosion happens while current flows. If the plate is only powered for a few thousandths of a second every few seconds, almost no current flows, and the plate lasts many times longer. Real outdoor sensors do exactly this, and it costs you one pin and about four lines.
Done

You still owe Band 4 the same evidence

This Swap replaces the night guard. To claim Band 4 you still need:

  • A video of it working, including the moment it decides
  • Your six-row measurement table, which is this band's real deliverable, and your two chosen numbers with a sentence on why
  • Your guessed readings for all six states, written down before you measured, next to what you actually found
  • Your build log
  • Both analogRead and analogWrite in your glossary, with their different ranges
  • Five or six correct answers in Part 14, the Check yourself questions, including question 6

Ship it

One video under sixty seconds, and one post of five lines. You built something different from the person next to you, so your video is the one nobody else in the room can post. Say in the post which build you chose and why — that choice is itself worth a line.

The four shots: three seconds of the thing still, fifteen of you doing something to it, fifteen of it responding all the way to the end, and ten of your measurement or the thing that went wrong first.

Show your work has the template and the three checks to make before anything goes public. Tag it #BozomaBuilds.