Things used in this project

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
×1
13285 01
PIR Motion Sensor (generic)
×1
5v Stepper Motor Uln2003 Driver Board
×1
Adafruit industries ada1536 image
Buzzer
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
09590 01
LED (generic)
×1
08377 02 l
Resistor 330 ohm
×1

Schematics

ojGkh1cgyied4GJure2b.fzz
Stepper control
NzcXggMo28Hy3I0XZVRd.fzz

Code

BlinkPython
from gpiozero import LED
from time import sleep
led = LED(18)
while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)
Alternative BlinkPython
from gpiozero import LED
from signal import pause
red = LED(17)
red.blink()
pause()
ButtonPython
from gpiozero import Button
button = Button(2)
while True: 
    if button.is_pressed: 
        print("Button is pressed") 
    else:
        print("Button is not pressed")
Button commanding a LEDPython
from gpiozero import LED, Button
from signal import pause
led = LED(18)
button = Button(2)
button.when_pressed = led.on
button.when_released = led.off
pause()
AlarmPython
from gpiozero import MotionSensor, Buzzer, LED
import time
pir = MotionSensor(23)
bz = Buzzer(24)
led = LED(18)
print("Waiting for PIR to settle")
pir.wait_for_no_motion()
while True:
    led.off()
    print("Ready")
    pir.wait_for_motion()
    led.on()
    print("Motion detected!")
    bz.beep(0.5, 0.25, 8)
    time.sleep(3)
Stepper Motor ControlPython
import time
import sys
from gpiozero import OutputDevice as stepper
IN1 = stepper(12)
IN2 = stepper(16)
IN3 = stepper(20)
IN4 = stepper(21)
stepPins = [IN1,IN2,IN3,IN4] # Motor GPIO pins</p><p>
stepDir = -1        # Set to 1 for clockwise
                           # Set to -1 for anti-clockwise
mode = 1            # mode = 1: Low Speed ==> Higher Power
                           # mode = 0: High Speed ==> Lower Power
if mode:              # Low Speed ==> High Power
  seq = [[1,0,0,1], # Define step sequence as shown in manufacturers datasheet
             [1,0,0,0], 
             [1,1,0,0],
             [0,1,0,0],
             [0,1,1,0],
             [0,0,1,0],
             [0,0,1,1],
             [0,0,0,1]]
else:                    # High Speed ==> Low Power 
  seq = [[1,0,0,0], # Define step sequence as shown in manufacturers datasheet
             [0,1,0,0],
             [0,0,1,0],
             [0,0,0,1]]
stepCount = len(seq)
if len(sys.argv)>1: # Read wait time from command line
  waitTime = int(sys.argv[1])/float(1000)
else:
  waitTime = 0.004    # 2 miliseconds was the maximun speed got on my tests
stepCounter = 0

while True:                          # Start main loop
  for pin in range(0,4):
    xPin=stepPins[pin]          # Get GPIO
    if seq[stepCounter][pin]!=0:
      xPin.on()
    else:
      xPin.off()
  stepCounter += stepDir
  if (stepCounter >= stepCount):
    stepCounter = 0
  if (stepCounter < 0):
    stepCounter = stepCount+stepDir
  time.sleep(waitTime)     # Wait before moving on</p>

Credits

Mjrobot hiresicon 512 512 j57u7diljd
MJRoBot

Engineer, writer and forever student. Passionate to share knowledge of electronics with focus on IoT and robotics.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Mask with Blinking Eye
Easy
  • 57
  • 3

Protip

Makes a great mask more eye-catching when one eye is blinking. Has an on-off switch, is powered by a cell , and driven by an ATtiny85.

Test Your Internet Speed Using a Raspberry Pi + Ubidots
Easy
  • 269
  • 4

Protip

Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Chicken Coop Livestream
Easy
  • 2,422
  • 10

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

PHPoC - Detect Someone Taking Your Stuff
Easy
  • 581
  • 14

When your stuff is being taken away by a thief, PHPoC makes an alert and sends a notification to you via Gmail.

Safe City: A Device to Keep You Safe
Easy
  • 440
  • 5

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Scavenger Hunt Clues w/ Telephone Keypad
Easy
  • 877
  • 3

Full instructions

Type the correct code on the phone's keypad to hear the clue through the handset, then decode the message to finish before the other team.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog