Beagle Board - beagleboard.org
Mala Dies
Published

Lock it to Keep It Safe!

Did you ever want to lock your door from your computer or via WiFi?

BeginnerProtip1 hour101
Lock it to Keep It Safe!

Things used in this project

Hardware components

BeagleBone Black Wireless
BeagleBoard.org BeagleBone Black Wireless
×1
12vdc battery
×1
USB to barrel jack cable
×1
MotorCape
×1
Wires
×4
Power Bank w/ USB Port
×1
Solenoid w/ Latch/Lock
×1

Software apps and online services

Python3
Adafruit_BBIO

Hand tools and fabrication machines

screw driver

Story

Read more

Schematics

Look for the MotorCape

BBBW

Code

Latch.py

Python
For Motor4 instead of Motor1, i.e. in case you wanted to try that one too!
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
import time

class Motor:
    def __init__(self, dir_pin, pwm_pin, pwm_freq):
        self.dir_pin = dir_pin
        self.pwm_pin = pwm_pin
        self.value = 0

        PWM.start(pwm_pin, 0, pwm_freq)
        GPIO.setup(dir_pin, GPIO.OUT)

    def set(self, value):
        assert -100 <= value <= 100
        if (value < 0) != (self.value < 0):
            # changing direction
            PWM.set_duty_cycle(self.pwm_pin, 0)
            GPIO.output(self.dir_pin, value < 0)
        PWM.set_duty_cycle(self.pwm_pin, abs(value))
        self.value = value

motor4 = Motor(dir_pin="P8_26", pwm_pin="P8_19", pwm_freq=2000)

def updates():
    state = int(input("Please enter a 0 or 1 for action: "))
    for state in range(0, 10):
        if state == 1:
            motor4.set(100)
            time.sleep(2)
            motor4.set(0)
            time.sleep(2)

        elif state == 0:
            motor4.set(0)

        else:
            motor4.set(0)

updates()

Credits

Mala Dies

Mala Dies

25 projects • 6 followers
Stay there and someone will find you...

Comments

Add projectSign up / Login