Door contact to ProbeHarbor
A reed switch on a door. Posts open or shut once a minute and right away when it changes.
ESP32
3V3
GND
EN
23
VP
22
VN
TX
34
RX
35
21
32
GND
33
19
25
18
26
5
27
17
14
16
12
4
GND
0
13
2
D2
15
D3
D1
CMD
D0
5V
CLK
Wiring
| From | To board | Note |
|---|---|---|
| Reed switch, wire A | GPIO 4 | Internal pull-up. Low means the door is shut |
| Reed switch, wire B | GND |
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32 Dev Module
/**
* Door reed/button → ProbeHarbor push ingest (ESP32).
*
* Libraries: WiFi, HTTPClient (ESP32 Arduino).
* CONTACT_PIN to GND when closed (reed closed = door shut → door1 false).
* Set WIFI_SSID, WIFI_PASS, INGEST_URL.
*/
#if defined(ESP32) || defined(ESP8266)
#include <WiFi.h>
#include <HTTPClient.h>
#else
#error "door_contact_ingest targets ESP32 / ESP8266."
#endif
#ifndef WIFI_SSID
#define WIFI_SSID "your-wifi"
#endif
#ifndef WIFI_PASS
#define WIFI_PASS "your-password"
#endif
#ifndef INGEST_URL
#define INGEST_URL "https://probeharbor.dev/api/ingest/YOUR_DEVICE_KEY"
#endif
#ifndef CONTACT_PIN
#define CONTACT_PIN 4
#endif
const unsigned long INTERVAL_MS = 60UL * 1000UL;
unsigned long lastPost = 0;
int lastSent = -1;
void setup() {
Serial.begin(115200);
pinMode(CONTACT_PIN, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(400);
Serial.print(".");
}
Serial.println(" ok");
}
bool postDoor(bool open) {
if (WiFi.status() != WL_CONNECTED) return false;
HTTPClient http;
http.begin(INGEST_URL);
http.addHeader("Content-Type", "application/json");
char body[64];
snprintf(body, sizeof(body), "{\"door1\":%s}", open ? "true" : "false");
int code = http.POST(body);
Serial.printf("POST %d %s\n", code, body);
http.end();
return code >= 200 && code < 300;
}
void loop() {
/* INPUT_PULLUP: LOW = contact closed = door shut */
bool open = digitalRead(CONTACT_PIN) == HIGH;
unsigned long now = millis();
bool due = (now - lastPost >= INTERVAL_MS);
bool changed = (int)open != lastSent;
if (!due && !changed) return;
lastPost = now;
if (postDoor(open)) lastSent = (int)open;
}
Parts
| Quantity | Part | Where to buy |
|---|---|---|
| 1× | ESP32 dev board | Buy at Amazon |
| 1× | Magnetic reed switch | Buy at Adafruit |
Amazon buy links may include an Associates tag, and this site may earn a commission from qualifying Amazon purchases at no extra cost to you. Adafruit links are direct.
Libraries
None beyond the ESP32 Arduino core.
Load it
- In the Arduino IDE, install the esp32 board package and pick the board named above the sketch.
- Paste the sketch, choose the board's port and upload. Hold BOOT if the upload stalls at Connecting.
- Close the IDE's serial monitor, then open the bench here to watch the output.
Field notes
- Set WIFI_SSID, WIFI_PASS and INGEST_URL at the top of the sketch. The ingest URL comes from a push device under Dashboard, Devices at probeharbor.dev.