Nick Pettefar
Published © GPL3+

Motor On!

How to drive a motor from C.H.I.P. (In this case, controlled by a button and confirmed by an LED.)

IntermediateProtip1 hour2,284
Motor On!

Things used in this project

Hardware components

C.H.I.P.
C.H.I.P.
×1
DC motor (generic)
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
LED (generic)
LED (generic)
×1
Power MOSFET N-Channel
Power MOSFET N-Channel
I used an IRF510
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
I used an 2N3904
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
Some wires...
×10

Story

Read more

Schematics

The Circuit Diagram

Wire it up carefully.
Circuit diagram.jpg

Code

MotorOnSw.py

Python
Press the button to switch the motor and LED on.

You need to install the AdaFruit C.H.I.P. GPIO library first of all. See here for instructions, usage guides and tips and other stuff: https://bbs.nextthing.co/t/adafruit-gpio-library-for-chip/2696
#!/usr/bin/python
#
# Nick Pettefar - 14th July 2016
#
import CHIP_IO.GPIO as GPIO
from time import sleep
#
delay=0.01
Motor = "XIO-P2"
LED = "XIO-P4"
Switch = "XIO-P0"
GPIO.setup(Motor, GPIO.OUT)
GPIO.setup(LED, GPIO.OUT)
GPIO.setup(Switch, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#
GPIO.output(Motor, GPIO.LOW)
GPIO.output(LED, GPIO.LOW)

try:
    while True:
        while GPIO.input(Switch)==1:
            sleep(delay)
        GPIO.output(Motor, GPIO.HIGH)
        GPIO.output(LED, GPIO.HIGH)
        sleep(delay)
        GPIO.output(Motor, GPIO.LOW)
        GPIO.output(LED, GPIO.LOW)

except KeyboardInterrupt:
    GPIO.output(Motor, GPIO.LOW)
    GPIO.output(LED, GPIO.LOW)

Credits

Nick Pettefar

Nick Pettefar

2 projects • 1 follower
Unix biker Radio Ham bad Ukulele player.
Contact

Comments

Add projectSign up / Login