Doorlock by Max

Here’s our second project Max and I worked on during the last few months. The first one was Fish feeder. The next one will be a lemonade stand drink dispenser.

It’s a door lock to Max’s cabinet. It consists of:

  1. Keypad. Designed in Freecad and printed on Creality CR-10 3d printer. It houses 12 Grove buttons, a Grove buzzer and Grove RGB display.
  2. Door lock mechanism. Idea found on thingiverse, but rather than using someone’s STL files that didn’t print well, we ended up designing from scratch in Freecad. The gear is attached to a Futaba S3003 servo.
  3. Computer box with Raspberry Pi, two GrovePi’s (G3 and G5) and a pivotPi for the servo. Two separate DC power lines run back to AC/DC transformers.

Last but not least, here’s the Python code for it. I would really love to hear your feedback on how we handle pressed buttons. I’m sure there is a more efficient way to handle that:

import time
import grovepi3
import grovepi5
from pivotpi import *
from grove_rgb_lcd import *

setRGB(0,255,0)
setText("Hello Maksim! Enter 4 digit code.")

servo = PivotPi()
servo.angle(SERVO_1,0)

code = ""

grovepi5.pinMode(4,"OUTPUT")

def buzz(howlong):
	#grovepi5.digitalWrite(4,1)
	time.sleep(howlong)
	grovepi5.digitalWrite(4,0)

while True:
	if grovepi3.digitalRead(2):
		# button 1
		setRGB(255,0,0)
		code = code + "1"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(3):
		# button 2
		setRGB(255,148,0)
		code = code + "2"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(4):
		# button 3
		setRGB(250,255,0)
		code = code + "3"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(5):
		# button 4
		setRGB(0,255,0)
		code = code + "4"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(6):
		# button 5
		setRGB(0,0,255)
		code = code + "5"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(7):
		# button 6
		setRGB(199,0,255)
		code = code + "6"
		setText(code)
		buzz(0.2)
	if grovepi3.digitalRead(8):
		# button 7
		setRGB(255,0,0)
		code = code + "7"
		setText(code)
		buzz(0.2)
	if grovepi5.digitalRead(2):
		# button 8
		setRGB(255,114,0)
		code = code + "8"
		setText(code)
		buzz(0.2)
	if grovepi5.digitalRead(3):
		# button 9
		setRGB(238,255,0)
		code = code + "9"
		setText(code)
		buzz(0.2)
	if grovepi5.digitalRead(5):
		# button 0
		setRGB(0,0,255)
		code = code + "0"
		setText(code)
		buzz(0.2)
	if grovepi5.digitalRead(7):
		# button key
		setRGB(0,255,0)
		if code in ("7767", "141414"):
			setRGB(0,255,0)
			setText("Door is open!")
			code = ""
			servo.angle(SERVO_1,0)
			buzz(5)
		else:
			setRGB(255,0,0)
			setText("Wrong code! Try again!")
			code = ""
			buzz(5)
			time.sleep(1)
			buzz(5)
	if grovepi5.digitalRead(6):
		# button clear
		setRGB(255,0,0)
		code = ""
		buzz(2.9)
		setText("clear code \ close door.")
		servo.angle(SERVO_1,90)
1 Like

That’s sweet. So maaany Grove buttons! I haven’t see that many Grove buttons in my entire life LOL!

And you actually got me interested in FreeCAD. I didn’t know that thing existed. I think I’m gonna give it a try. So far I’ve only done things in SolidWorks.