// Door sign + Claude status light, one sketch, one Uno. VERSION FOR THE 16-PIN LCD (no I2C board). // Uses the LiquidCrystal library that ships with Arduino (nothing to install). // LCD pins -> Uno: 1 VSS GND | 2 VDD 5V | 3 V0 potentiometer middle pin | 4 RS D12 | 5 RW GND | 6 E D8 // 11 D4 D2 | 12 D5 D6 | 13 D6 D5 | 14 D7 D4 | 15 A 5V via 220 ohm | 16 K GND (pins 7-10 unused) // LEDs (same as claude_light_3led): red D9, yellow D10, blue D11, each through 220 ohm. // The Mac sends one line per message over USB (9600 baud): // IDLE / WORK / WAIT / DONE / FAIL -> status light (exactly as before). WAIT, DONE and FAIL // also put a short line on the LCD; IDLE and WORK bring the door message back. // "top text|bottom text" -> door message, 16 characters per row. // Desk senses: door sign + status light + PIR motion sensor, one sketch, one Uno. // = door_sign_16pin.ino (every word unchanged) + PIR OUT on D13 + DHT11 S on A0. // PIR: VCC -> 5V rail, GND -> GND rail, OUT -> D13 (D13 also lights the Uno's own little LED: handy). // The Mac gets one line each time the PIR changes: "MOVE" (something moved) or "STILL" (nothing for 2 s). // The PIR needs about 60 seconds after power-up to settle: ignore it until then. const int PIN_PIR = 13; int pirLast = -1; unsigned long pirChange = 0; void pirLoop() { int v = digitalRead(PIN_PIR); unsigned long now = millis(); if (v == HIGH && pirLast != HIGH) { pirLast = HIGH; Serial.println("MOVE"); } if (v == LOW && pirLast == HIGH) { if (now - pirChange > 0) { pirLast = LOW; Serial.println("STILL"); } } if (v != pirLast) pirChange = now; } // ---- DHT11 (blue grid module): S -> A0, + -> 5V rail, - -> GND rail. No library needed. ---- const int PIN_DHT = A0; unsigned long dhtLast = 0; unsigned int expectLevel(int level) { // microseconds the line stays at `level`; 0 = timeout unsigned long t = micros(); while (digitalRead(PIN_DHT) == level) { if (micros() - t > 150) return 0; } return (unsigned int)(micros() - t); } bool readDHT(int &t, int &h) { byte d[5] = {0, 0, 0, 0, 0}; pinMode(PIN_DHT, OUTPUT); digitalWrite(PIN_DHT, LOW); delay(20); digitalWrite(PIN_DHT, HIGH); delayMicroseconds(40); pinMode(PIN_DHT, INPUT_PULLUP); delayMicroseconds(10); if (expectLevel(HIGH) == 0 && digitalRead(PIN_DHT) == HIGH) return false; // wait for the sensor to pull low if (expectLevel(LOW) == 0) return false; if (expectLevel(HIGH) == 0) return false; for (int i = 0; i < 40; i++) { unsigned int lo = expectLevel(LOW); unsigned int hi = expectLevel(HIGH); if (lo == 0 || hi == 0) return false; d[i / 8] <<= 1; if (hi > lo) d[i / 8] |= 1; } if ((byte)(d[0] + d[1] + d[2] + d[3]) != d[4]) return false; h = d[0]; t = d[2]; return true; } void dhtLoop() { // every 10 s: "ROOM 23 45" = temperature C, humidity % if (millis() - dhtLast < 10000UL) return; dhtLast = millis(); int t, h; if (readDHT(t, h)) { Serial.print("ROOM "); Serial.print(t); Serial.print(" "); Serial.println(h); } else Serial.println("ROOM ?"); } #include LiquidCrystal lcd(12, 8, 2, 6, 5, 4); // RS, E, D4, D5, D6, D7 void showRow(uint8_t row, const String &s) { lcd.setCursor(0, row); for (uint8_t i = 0; i < 16; i++) lcd.write(i < s.length() ? s[i] : ' '); } void show(const String &top, const String &bottom) { showRow(0, top); showRow(1, bottom); } const int PIN_R = 9, PIN_Y = 10, PIN_B = 11; enum State { IDLE, WORK, WAIT, DONE, FAIL, STAND }; int state = IDLE; unsigned long stateSince = 0; String line = ""; String doorTop = "Hello Pep", doorBottom = "Door sign ready"; void setColor(int r, int y, int b) { analogWrite(PIN_R, r); analogWrite(PIN_Y, y); analogWrite(PIN_B, b); } int triangle(unsigned long t, unsigned long periodMs) { unsigned long p = t % periodMs, half = periodMs / 2; if (p < half) return (int)(p * 255UL / half); return (int)((periodMs - p) * 255UL / half); } void setState(int s) { state = s; stateSince = millis(); if (s == WAIT) show("Claude needs you", ""); else if (s == DONE) show("Claude: done", ""); else if (s == FAIL) show("Claude: error", ""); else if (s == STAND) show("Stand up!", "10 squats"); else show(doorTop, doorBottom); // IDLE or WORK: the door message } void handleLine(String cmd) { cmd.trim(); int bar = cmd.indexOf('|'); if (bar >= 0) { // door message doorTop = cmd.substring(0, bar); doorBottom = cmd.substring(bar + 1); if (state == IDLE || state == WORK) show(doorTop, doorBottom); Serial.println("OK DOOR"); return; } cmd.toUpperCase(); if (cmd == "IDLE") setState(IDLE); else if (cmd == "WORK") setState(WORK); else if (cmd == "WAIT") setState(WAIT); else if (cmd == "DONE") setState(DONE); else if (cmd == "FAIL") setState(FAIL); else if (cmd == "STAND") setState(STAND); else { Serial.println("?"); return; } Serial.print("OK "); Serial.println(cmd); } void setup() { pinMode(PIN_PIR, INPUT); pinMode(PIN_R, OUTPUT); pinMode(PIN_Y, OUTPUT); pinMode(PIN_B, OUTPUT); Serial.begin(9600); lcd.begin(16, 2); setColor(0, 0, 80); // power-up flash, like before show(doorTop, doorBottom); delay(300); setColor(0, 0, 0); } void loop() { while (Serial.available() > 0) { char c = (char)Serial.read(); if (c == '\n') { handleLine(line); line = ""; } else if (c != '\r' && line.length() < 36) line += c; } pirLoop(); dhtLoop(); unsigned long t = millis() - stateSince; switch (state) { case IDLE: setColor(0, 0, 0); break; case WORK: setColor(0, 0, 10 + triangle(t, 2400) / 2); break; case WAIT: if ((t / 300) % 2 == 0) setColor(0, 255, 0); else setColor(0, 0, 0); break; case DONE: if (t < 8000UL) setColor(0, 0, 255); else setState(IDLE); break; case FAIL: setColor(255, 0, 0); break; case STAND: setColor(255, 0, 255); break; // purple = red + blue LEDs together } }