< Back to Blog

The Lunch Button

28 September 2018 Ross DeaneHardware , Lunch , Fun

One of the perks of working at DueDil is that lunch gets delivered to the office every Friday at about 12pm. Business information is hungry work, and as a result, the “#lunch” channel on Slack gets very busy, especially around this time.

Our desks are upstairs away from the lunchroom and it’s difficult for everyone to know when lunch has been delivered, and secure that all important place at the front of the queue. To this end, I wanted to make a physical button that could be placed in the kitchen and pressed when lunch was delivered, which would alert the lunch channel on Slack.

We have a few raspberry pis in the office, so although slightly overkill for this project, I used one of those as a starting point. Our infrastructure team have made a tool for provisioning  raspberry pis for use in the office, and after installing a raspian image, that got me quickly set up with the necessary config to connect to our office network.

There are many breakout boards for the raspi’s GPIO (general purpose input output) pins but most of them require soldering, and I wanted to make this a quick project without the need for filling the office with solder fumes. With this in mind, after a quick trip to Maplin (RIP) I came back with a few supplies.

I connected one side of a ribbon cable to the GPIO pins on the Pi, the inserted two of the jumper wires into the other end, one to one of the I/O pins (18) and the other to ground. I then connected the 2 jumper wires to the pins on the switch.

The Lunch Button

Next it was time to write the code that would listen for the button press and post to the slack channel. I used the RPi.GPIO python library to interface with the pins on the Pi like so:

import RPi.GPIO as GPIO
import time
import requests

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

url = 'slack.url'
data = {'payload' : 'Lunch is served.'}

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        requests.post(url, data=data)
        time.sleep(0.2)

All thats left is to ssh into the pi and run this script (you might need to install pip first), and push the button!

While this example uses slack, the code can be easily modified to post to any web service, for example, you could have a doorbell that emails you when someone presses it, turn on a hue light, or anything you can think of.

If you're hungry to tackle some interesting problems, come work with us! We're hiring.