Making Office Life Better One Bathroom at a Time
Christina, our head of the Ministry of Culture, had a complaint at lunchtime one day: nearing the end of her second trimester of pregnancy, she was getting more and more frustrated having to walk across the office only to find out that the bathroom was already occupied. Several of the engineers present discussed ways of solving this problem using or misusing technology. There are several ways to do this, most of which involve switches and some kind of remote monitoring software.
I decided that this task would be best done with an Arduino with an Ethernet Shield. Essentially, the Arduino would be acting as a web server for the door state. I priced it out and sent Christina a parts list for the prototype: the Arduino boards from EIO and a magnetic switch from All Electronics. I magnanimously donated a 10K resistor and other implements of destruction. I set aside a few hours on a Friday afternoon and knocked this together:
The code running on the Arduino is this:
void loop()
{
buttonState = digitalRead(buttonPin);
// listen for incoming clients
Client client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head></head><body>AtalaToidy<br>BathroomDoor:");
if (buttonState == HIGH)
client.print("Open");
else
client.print("Closed");
client.println("<br></body></html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
Once the bench prototype was working, I mounted it into a project box and with the help of Jay, installed it in our server room.
Total cost: about $100, not including my time. It’s already paid off in terms of laughter and people trying the door and mashing on F5 to see if it works as advertised, which it does:
I love my job.