← Home
D1 Mini + BME280 · Google Sheets log · leak alarm

Know when the garage freezes or the basement floods

Two small Wi-Fi sensors log temperature and humidity to a Google Sheet every 10 minutes and email you when something's wrong. The basement unit also watches the floor for water and hangs a float in the sump pit, so you hear about a failed pump before the water reaches the floor.

Time an afternoon for bothSkill soldering + copy-pasteCost about $25 in new parts
BME280temp · humidity Leak puck +sump floatbasement only D1 Minireads sensors Wi-Fi10 min Apps Scriptchecks your limits Google Sheetevery reading Email alertfreeze · water Also: a live page on your Wi-Fi at http://garage.local and http://basement.local
How it fits together. Your Mac is only needed for setup; after that, each unit runs on its own from a phone charger.

A Get the parts

You already have the D1 Minis, the ELEGOO kit and a printer. Everything else is cheap.

Order these

ItemForSearch for
2 × BME280 sensor moduleboth units“GY-BME280 5V” (the 2-pack you found is right)
2 × stainless steel screws, M3 × 8 mm, pan headbasement leak puck“A2 stainless M3 x 8 pan head screw” — must be stainless; plain zinc screws rust in water
About 2 m (6–7 ft) of 2-conductor wirebasement leak puck“22 AWG 2 conductor red black wire”, or any old speaker or phone wire
1 × cable float switch, normally open, 2–3 m cablebasement sump pit“cable float switch normally open” — a sealed float on a cable with a sliding counterweight. A 220 V rating is fine; here it only switches 3.3 V.
2 × USB wall charger + micro-USB data cableboth unitsany 5 V, 1 A phone charger; a 2–3 m cable for the garage helps
Double-sided foam mounting tapeboth units“3M foam mounting tape” (gray, about 1 mm thick)

From what you have

Tools

Do I need the 3.3 V version of the BME280? No. The “5V” module has its own regulator and works from 3.3 V too. You'll power it from the D1 Mini's 3V3 pin, which keeps its data lines at the 3.3 V the D1 Mini expects.

B Print the case and leak puck

Start the print first. It runs while you do Parts C and D.

1

Download the print files

I designed these for your D1 Mini and BME280. The sensor gets its own vented chamber below the D1 Mini, behind a solid wall. The D1 Mini runs a few degrees warm, and heat rises, so this layout keeps its warmth from skewing the temperature reading.

D1 MiniBME280USB cable slotscrew holetop vents: heat escapes upscrew holeD1 Mini chambersolid divider, wire notch at leftsensor chamber, ventedbottom cable slot (basement)46 mm wide · 56 mm tall · 16.5 mm deep with lid
Front view with the lid off, drawn to scale. The same base works for both units. On the garage unit, the cable slot in the bottom wall just stays empty.
2

Slice and print in Bambu Studio

  1. Open Bambu Studio and drag all five files onto one plate (2 bases, 2 lids, 1 puck). They're already in the right orientation: base lying on its back, lid outside-face down, puck upside down with its feet up. Don't rotate them.
  2. Filament: PETG (Bambu PETG HF or Basic). A summer garage can pass 120 °F in the sun and soften PLA. PLA is fine for the basement unit. Pick a light color so sunlight doesn't heat the case.
  3. Process: 0.20 mm Standard, wall loops 3, sparse infill 15%, supports off.
  4. Slice and print. Expect roughly 1½ hours for the plate.
  5. When it's done, press a lid onto a base to check the fit. It should snap on snugly and only fit one way, with the lid's vents over the lower (sensor) chamber.
Lid too tight? Sand the outside of the lid's inner rim lightly. Too loose? A small strip of tape on the rim fixes it.

C Set up the Google Sheet

This is where readings land and where alerts come from. Do it before the D1 Mini code, because the code needs the Sheet’s web address.

3

Create the Sheet

  1. On your Mac, open sheets.new. It makes a blank Google Sheet.
  2. Click the title “Untitled spreadsheet” and rename it Home Climate Log.
  3. You don't need to add any columns. The script creates the Readings and Latest tabs the first time data arrives.
4

Add the script

  1. In the Sheet, click Extensions → Apps Script. A code editor opens in a new tab.
  2. Delete everything in Code.gs, then paste in the script below (use Copy all).
  3. Edit the settings block at the top:
    • SECRET: make up a password of 15+ letters and numbers only, like Garage7Basement42Sensor. It stops strangers from writing to your Sheet. Write it down; the D1 Mini needs the same one.
    • ALERT_EMAIL: your email address.
    • ALERTS: the limits. The garage alerts below 35 °F or above 100 °F. The basement alerts below 45 °F or above 60% humidity (mold starts to grow above about 60%). Water alerts are always on for a unit with a leak puck.
  4. Click the Save (disk) icon.
Code.gs (Google Apps Script)Download
Show the code
Loading…
5

Turn on alerts (one time)

  1. In the toolbar's function dropdown (next to Debug), choose installTriggers, then click Run.
  2. Google asks for permission: click Review permissions and choose your account.
  3. You'll see “Google hasn't verified this app”. That's normal for your own scripts. Click Advanced → Go to Untitled project (unsafe) → Allow.
  4. Within a minute you get an email: “Climate sensors: alerts are set up.” That confirms email works.
6

Publish it as a web app

  1. Click Deploy → New deployment.
  2. Click the gear next to “Select type” and choose Web app.
  3. Set Execute as: Me and Who has access: Anyone. “Anyone” is required so the D1 Mini can reach it without signing in; the SECRET is what protects it.
  4. Click Deploy and copy the Web app URL. It looks like https://script.google.com/macros/s/AKfy…/exec. Save it with your SECRET.
If you edit the script later: Deploy → Manage deployments → pencil icon → Version: New version → Deploy. Saving alone doesn't update the live web app. The URL stays the same.
7

Test it from your browser

Paste this into a browser's address bar, with your URL and SECRET swapped in:

YOUR-WEB-APP-URL?secret=YOUR-SECRET&device=test&tempF=70&humidity=40&pressure=29.9
  • The page should just say ok, and the Sheet gets Readings and Latest tabs with one row each.
  • “bad secret” means the SECRET doesn't match. A Google sign-in page means access isn't set to Anyone.
  • Then delete the test rows from both tabs (right-click the row number → Delete row).

D Install the Arduino software

One-time setup on your Mac.

8

Install Arduino IDE

  1. Download Arduino IDE 2 for macOS from arduino.cc/en/software (pick “Apple Silicon” or “Intel” to match your Mac).
  2. Open the download and drag Arduino IDE into Applications. Open it, and allow any prompts to install USB drivers.
9

Add D1 Mini support

  1. Arduino IDE → Settings… Find Additional boards manager URLs and paste:
https://arduino.esp8266.com/stable/package_esp8266com_index.json
  1. Click OK.
  2. Click the Boards Manager icon in the left sidebar (it looks like a circuit board), search esp8266, and install esp8266 by ESP8266 Community. It's a large download; give it a few minutes.
10

Install the sensor library

  1. Click the Library Manager icon in the left sidebar (it looks like books).
  2. Search Adafruit BME280. Install Adafruit BME280 Library.
  3. When asked about dependencies, click Install All. That adds Adafruit Unified Sensor and BusIO.
11

Open the sensor program

  1. Download the sketch below (Download), or make a new sketch and paste it in with Copy all.
  2. Open ClimateSensor.ino in Arduino IDE. If it says the file must be inside a folder named ClimateSensor, click OK.
  3. Don't edit it yet; you'll fill in the settings in Part G.
ClimateSensor.ino (D1 Mini program)Download
Show the code
Loading…

I compiled this code for the D1 Mini, both with and without the water sensors, before publishing this page.

E Wire the sensor

Do this for both units. Solder the wires straight into the boards. Header pins would make the D1 Mini too tall for the case.

12

Cut and strip four wires

  1. Cut 4 jumper wires, one each of red, black, yellow and green, to 9 cm (3½ in). Cut off both plug ends.
  2. Strip 3 mm (⅛ in) from each end, twist the strands and tin them with a little solder.
13

Solder the wires to the BME280

  1. Set the 4-pin header strip that came with the sensor aside; you won't use it.
  2. Hold the sensor with the printed labels VIN GND SCL SDA facing you.
  3. Push each wire into its hole from the printed side, then solder on the back and trim: red → VIN, black → GND, yellow → SCL, green → SDA.
  4. Don't touch the tiny silver sensor (the square can with a pinhole) with the iron.
14

Solder the wires to the D1 Mini

Use a fresh D1 Mini with no header pins. Push each wire into its hole from the chip side and solder on the back. The back then stays flat for the foam tape in Part H.

WireBME280 pinD1 Mini pinWhere on the D1 Mini
redVIN3V3far edge, the corner next to the USB socket
blackGNDGnear edge, 2nd hole from the USB end
yellowSCLD1near edge, 6th hole
greenSDAD2near edge, 5th hole
ESP-12FD1 Minichips up · USB left3V35VD8GD7D4D6D3D5D2D0D1A0RXRSTTXBME280VINGNDSCLSDA
Garage unit. The yellow and green wires cross, which is expected: on the D1 Mini, D2 comes before D1. Go by the printed labels if your board looks different.
Don't use the 5V pin. And don't mix up the pin labeled D1 with the board's name, “D1 Mini”.

Check each joint: shiny, with no solder bridging two neighboring holes.

F Build the water sensors

Basement unit only: a floor puck for leaks and a float for the sump pit. Skip to Part G for the garage.

15

Put the screws into the puck

  1. On the puck's top (the side with the grooves), drive the two M3 × 8 mm stainless screws into the two small holes. The plastic cuts its own thread, so turn firmly.
  2. Stop when each head sits in its round seat.
  3. Set the puck on a table and slide a sheet of paper under the screw tips. The tips must not touch the table; there should be a gap of about 1.5 mm.
basement floor2-wire cable to the casehot glue over heads + wire joints1.5 mm gap3 mm feetWater deeper than 1.5 mm touches both screw tips and completes the circuit.M3 × 8stainless
Side view, cut through the screws. The three feet keep the tips just above a dry floor, so damp concrete doesn't set off a false alarm.
16

Attach the cable

  1. At one end of the 2-conductor wire, split the two conductors apart for 4 cm and strip 1 cm from each.
  2. Loosen each screw a turn. Wrap one conductor clockwise under each screw head, then tighten the screws back into their seats. Which conductor goes to which screw doesn't matter.
  3. Lay the cable in the groove to the puck's edge.
  4. Cover both screw heads, the bare wire and the groove with hot glue. Only the tips underneath should be bare metal.
17

Check the sump float

  1. A cable float switch has two wires, usually brown and blue (sometimes a third, black, wire on 3-wire versions; see below).
  2. Hold the float with its cable pointing up, the way it hangs: that's “low water”. Then turn it so the cable points down: that's “high water”. You may hear a ball or switch click inside.
  3. 3-wire floats: use the black (common) and brown wires. On most models those two are “normally open”. Tape off the blue wire.
This float is only for the alarm. Never connect it to the pump or to any mains wiring, and leave the pump's own float alone.
18

Connect both cables to the D1 Mini

First, push the free ends of both cables (leak puck and sump float) through the slot in the bottom of the case base, from outside to inside. You can't thread them once they're soldered.
  1. Strip 3 mm from each conductor at the case end.
  2. Trim the 1 kΩ resistor's legs to about 1 cm. Solder one leg into the D1 Mini's D5 hole (far edge, 5th from the USB end).
  3. Solder the red conductor to the resistor's other leg, then wrap that joint in tape or heat-shrink.
  4. Solder the leak cable's black conductor into the A0 hole (far edge, 7th from the USB end).
  5. Solder the sump float's two wires into D6 and D7 (far edge, 4th and 3rd from the USB end). Either wire can go in either hole.
ESP-12FD1 Minichips up · USB left3V35VD8GD7D4D6D3D5D2D0D1A0RXRSTTXBME280VINGNDSCLSDA1 kΩto sumpfloatto leakpuck2-wire cable, about 2 m
Basement unit: the four sensor wires, the leak cable on D5 (through the 1 kΩ resistor) and A0, and the sump float on D6 and D7. The program holds D7 at 0 V, so it acts as the float's ground.

G Load the program and test

Do this for each unit, on your desk, before closing the case.

19

Fill in your settings

At the top of ClimateSensor.ino, change only the lines between the YOUR SETTINGS markers:

SettingGarageBasement
WIFI_SSID / WIFI_PASSyour Wi-Fi name and password (2.4 GHz network)
SCRIPT_URLthe Web app URL from step 6
SECRETthe same secret you put in the Apps Script
DEVICE_NAME"garage""basement"
HAS_LEAK_SENSORfalsetrue
HAS_SUMP_FLOATfalsetrue

Keep the quote marks and the semicolons at the ends of the lines.

20

Upload it

  1. Plug the D1 Mini into your Mac with the micro-USB data cable.
  2. Tools → Board → esp8266 → LOLIN(WEMOS) D1 R2 & mini.
  3. Tools → Port: choose the one with usbserial or wchusbserial in its name.
  4. Click the Upload button (the right-arrow at the top left). The first build takes a minute; it ends with “Hard resetting via RTS pin…”.
21

Watch it work

  1. Open Tools → Serial Monitor and set the speed (bottom right) to 115200 baud. Press the D1 Mini's tiny reset button to see it start up.
  2. You should see something like this:
Climate sensor "garage" starting
BME280 found at 0x76
68.4 F  41.2 %RH  29.31 inHg
Connecting to Wi-Fi.....
Connected. Open http://192.168.1.83  or  http://garage.local
Sent -> 200 ok
  • Sent -> 200 ok means a new row is in your Sheet. The blue LED blinks once on each successful upload, and three times on a failed one.
  • Breathe on the sensor. A reading or two later (every 30 seconds), the humidity jumps. That proves it's a real BME280.
  • On your phone (on the same Wi-Fi), open http://garage.local, or the number shown, to see the live page.
22

Test the water alarms basement

Floor puck:

  1. Pour a few millimeters of tap water onto a plate and set the puck in it.
  2. Within about 10 seconds the Serial Monitor shows LEAK SENSOR: WET (A0 = 900) or similar, and an email titled “WATER DETECTED…” arrives within a minute.
  3. Lift the puck out and dry the tips. You get a “dry again” email.
Dry readings should sit near 0–10, and wet readings in the hundreds. If wet only reaches 50–80, lower LEAK_THRESHOLD to 40 and upload again.

Sump float:

  1. Hold the float upside down (cable pointing down) for about 20 seconds.
  2. The Serial Monitor shows SUMP FLOAT: HIGH WATER and an email titled “SUMP PIT WATER IS HIGH…” arrives.
  3. Let it hang normally again. You get a “back to normal” email.
Alarm stuck on with the float hanging normally? Your float is the “normally closed” type. Set FLOAT_IS_NORMALLY_OPEN = false; and upload again.

H Assemble and mount

Close it up and put it where it belongs.

23

Put everything in the case

  1. Stick a small square of foam tape on the back of the BME280. Press it into the lower chamber, labels facing you, to the right of the screw hole.
  2. Lead its four wires up through the notch in the divider.
  3. Stick foam tape to the back of the D1 Mini. Press it into the upper chamber, chips facing you, with the USB socket pushed against the slot on the left side.
  4. Basement: pull the leak and float cables' slack back out through the bottom slot.
  5. Plug the USB cable in through the slot, then press the lid on, with its vents over the lower chamber.

The drawing in step 1 shows where each part goes.

24

Mount it in the right spot

  • Height: on an inside wall about 1.5 m (5 ft) up.
  • Away from the furnace, water heater, freezer exhaust, direct sun, the garage door, and where the car's hot engine parks.
  • Fastening: two #4 flat-head screws (with anchors in drywall) through the countersunk holes, with the lid off. Or a strip of foam tape on the back.
  • Leak puck: on the floor at the lowest spot near the water heater, washer or wherever water would show up first. Run the cable along the wall and tack it with cable clips.
  • Plug in the charger. Within a minute or two the Sheet's Latest tab shows the unit.
25

Hang the float in the sump pit basement

  1. Take the pit cover off and watch the pump run once. Note the water level where it turns on.
  2. Slide the float's counterweight so the float hangs 8–10 cm (3–4 in.) below the weight.
  3. Lower the float into the pit until it hangs about 5–8 cm (2–3 in.) above the turn-on level, on the side away from the pump and its own float.
  4. Zip-tie the cable to the discharge pipe at that height, so it can't slide down.
  5. Check it hangs freely and can't touch the pump's float when the water rises.
  6. Route the cable out under the pit cover's edge or through its cable hole, and along the wall to the basement unit.
basement floorpumpdischarge pipepump's own floatpump turns on herealarm level2–3 in. highercounterweightyour floatzip-tie the cable to the pipeto the basement unit
Normally the pump keeps the water below the alarm level, and the float hangs down. If the pump fails or can't keep up, the water lifts the float and you get an email within about 30 seconds.
26

Fine-tune the temperature

  1. Leave a trusted thermometer next to the unit for an hour, so both settle.
  2. Compare the readings. If the sensor reads 1.8 °F high, set TEMP_OFFSET_F = -1.8; in the sketch and upload again.

Pressure is your actual (station) pressure, which is a little lower than the sea-level number on weather apps. That's normal.

27

See your data

  • Latest tab: one row per unit with its newest reading.
  • Readings tab: every reading, every 10 minutes (about 50,000 rows a year for two units, well within Sheets' limits).
  • Chart: on Readings, click Data → Create a filter and filter Device to garage. Select columns A and C, then Insert → Chart and pick Line chart. Charts follow the filter.

? Troubleshooting

What you seeLikely cause and fix
No port in Tools → Port, or upload failsThe cable is charge-only; try another. Close the Serial Monitor during upload. Check the board is “LOLIN(WEMOS) D1 R2 & mini”.
BME280 NOT foundCheck the four solder joints. Yellow must go to D1 and green to D2; if they're swapped, swap them back. Red must go to 3V3.
is a BMP280 … NO humidityThe seller sent a BMP280 labeled as a BME280, which is common. Return it; this project needs the humidity reading.
Stuck on Connecting to Wi-Fi.....Check the name and password (they're case-sensitive). The D1 Mini only joins 2.4 GHz networks.
Sent -> 200 bad secretThe SECRET in the sketch and the Apps Script don't match exactly.
Sent -> 200 <!DOCTYPE html… or 401/403/404The URL must end in /exec. The deployment must be Execute as: Me, Anyone. After editing the script, deploy a New version.
Sent -> -1 or connection errorsWeak Wi-Fi: check the dBm on the live page. Above −80 is fine; below that, move the unit or add an extender.
Temperature reads a few degrees highThe sensor must be in the lower chamber with the vents clear. Use TEMP_OFFSET_F (see “Fine-tune the temperature”) for the rest.
Sump alarm always on, or never tripsNormally open vs. normally closed float: flip FLOAT_IS_NORMALLY_OPEN. On a 3-wire float, try a different pair of wires.
Sump alarm flips on and offThe float is hanging too close to the pump's turn-on level, so normal cycling reaches it. Raise it 2–3 cm.
Leak false alarmsThe tips are touching a damp floor: check the 1.5 mm gap. Or raise LEAK_THRESHOLD to 150.
No alert emailsCheck your spam folder and ALERT_EMAIL. Run installTriggers again.
garage.local won't openSome Android phones don't support .local names. Use the IP number from the Serial Monitor.