I'm struggling here big time with a project I need to do for my college.
I've decided to do a little window automation with a simple DC motor and 2 door sensors.
So for the code, I'm trying to combine the Adafruit tutorials 9 and 12.
Here is the code:
- Code: Select all
import RPi.GPIO as io
dc1_pin = 4 #DC Motor Pin 1
dc2_pin = 17 #DC Motor Pin 2
sen1_pin = 23 #1st Door Sensor (Indicates closed window)
sen2_pin = 24 #2nd Door Sensor (Indicates opened window)
#Block for PWM
def set(property, value):
f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
print("Error writing the value of: " + property + " value: " + value)
cmd = raw_input("Do you wish to [o]pen or [c]lose?")
direction = cmd
if direction == "o":
print("The window is open!")
print("The window is close!")
At the block where are the instructions for the PWM module, I've added the line to set the speed to 0 because sometimes when running the program, the motor started running before choosing the proper action. I've also noted the same thing happening on the lesson 9 tutorial (I have no idea why but this extra line made the issue go away in both cases).
For the wiring, I'm also combining both tutorials and adding the second door sensor to GPIO 24. Both sensors and the DC motor are also connected into pin 6 (GROUND).
But here is the problem. When trying to trigger the sensors, nothing happens. I've tried the tutorial adding the second sensor and it runs just fine so there is no problem with a faulty sensor.
Could someone give me some advice? I'm not quite sure if the code is incorrect or perhaps I need to add a resistor perhaps into the circuit.
Also as per the tutorial, I'm using a L293D IC.
For the motor, a small DC motor with a 12VDC bench power supply.
Any help would be very appreciated! Thanks!