Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Mon Mar 04, 2019 3:50 am

Code: Select all

import RPi.GPIO as GPIO
import MySQLdb
import datetime
import time
import os
import smtplib
from ftplib import FTP
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from contextlib import closing
from twilio.rest import TwilioRestClient

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#                       VARIABLES
#           CHANGE THESE TO YOUR OWN SETTINGS!
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# Insert your own account's SID and auth_token from Twilio's account page
twilio_account_sid = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
twilio_auth_token = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
# The phone number you purchased from Twilio
sTwilioNumber = "+12145551212"
# Gmail information - for informing homeowner that garage activity happened
recipients = ['myemail@gmail.com', 'home_owner_email@gmail.com']
sGmailAddress = "myemail@gmail.com"
sGmailLogin = "GoogleUserName"
sGmailPassword = "GoogleEmailPassword"
sFTPUserName = "WebsiteFTPUsername"
sFTPPassword = "WebsiteFTPPassword"
sFTPHost = "MyWebsite.com"

iNumOpenings = 0
iStatusEnabled = 1
iAuthorizedUser_Count = 0
iSID_Count = 0

sLastCommand = "Startup sequence initiated at {0}.  No open requests, yet".format(time.strftime("%x %X"))
sAuthorized = ""
sSid = ""
sSMSSender = ""

GPIO_PIN = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PIN, GPIO.OUT)

# Unfortunately, you can't delete SMS messages from Twilio's list.  
# So we store previously processed SIDs into the database.
lstSids = list()
lstAuthorized = list() # authorized phone numbers, that can open the garage

# Connect to local MySQL database
con = MySQLdb.connect('localhost', 'garage', 'garagepassword', 'GarageDoor')
# Twilio client which will be fetching messages from their server
TwilioClient = TwilioRestClient(twilio_account_sid, twilio_auth_token)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#                       FUNCTIONS
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# This function sends an SMS message, wrapped in some error handling
def SendSMS(sMsg):
  try:
    sms = TwilioClient.sms.messages.create(body="{0}".format(sMsg),to="{0}".format(sSMSSender),from_="{0}".format(sTwilioNumber))
  except:
    print "Error inside function SendSMS"
    pass

# Once the garage door has begun opening, I want a video of who's coming in.  And then, upload the video to my website so I can see it remotely    
def TakeVideoAndUpload():
  try: 
    sVideoFile = "Vid.{0}.h264".format(time.strftime("%m-%d-%Y.%I.%M.%S"))
    # Give 10 seconds to garage to raise up
    time.sleep(10)
    # Now take 60 seconds of video, to see who's coming inside
    sVideoCommand = "raspivid -w 640 -h 480 -o /home/pi/movies/{0} -t 60000".format(sVideoFile)
    os.system(sVideoCommand)
    ftp = FTP(sFTPHost,sFTPUserName,sFTPPassword)    
    ftp.storbinary("stor {0}".format(sVideoFile), open("/home/pi/movies/{0}".format(sVideoFile),'rb'),blocksize=1024)
    # It uploaded ok, so delete the video file to avoid clogging up SD card space
    os.system("sudo rm /home/pi/movies/{0}".format(sVideoFile))
  except:
    print "Error inside function TakeVideoAndUpload"
    pass

# When doing a STATUS on the Garage SMS Butler, it will capture a screen shot of the garage, so I can see if it's open or closed, from anywhere in the world
def TakePictureAndUpload():
  try:
    os.system("raspistill -w 640 -h 480 -o /home/pi/pictures/garagepic.jpg")
    ftp = FTP(sFTPHost,sFTPUserName,sFTPPassword)
    ftp.storbinary("stor garagepic.jpg", open("/home/pi/pictures/garagepic.jpg",'rb'),blocksize=1024)
  except:
    print "Error inside function TakePictureAndUpload"
    pass

# Send a signal to the relay
def OpenGarageDoor():
  try:
    GPIO.output(GPIO_PIN, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(GPIO_PIN, GPIO.LOW)
  except:
    print "Error inside function OpenGarageDoor"
    pass

# Email the home owner with any status updates
def SendGmailToHomeOwner(sMsg):
  try:
    connect = server = smtplib.SMTP('smtp.gmail.com:587')
    starttls = server.starttls()
    login = server.login(sGmailLogin,sGmailPassword)
    msg = MIMEMultipart()
    msg['Subject'] = "GARAGE: {0}".format(sMsg)
    msg['From'] = sGmailAddress
    msg['To'] = ", ".join(recipients)
    sendit = server.sendmail(sGmailAddress, recipients, msg.as_string())
    server.quit()
  except:
    print "Error inside function SendGmailToHomeOwner"
    pass


try:
  # Store authorized phone numbers in a List, so we don't waste SQL resources repeatedly querying tables
  with closing(con.cursor()) as authorized_cursor:
    authorized_users = authorized_cursor.execute("select sPhone from Authorized")   
    auth_rows = authorized_cursor.fetchall()
    for auth_row in auth_rows:
      for auth_col in auth_row:
        iAuthorizedUser_Count = iAuthorizedUser_Count + 1
        lstAuthorized.append(auth_col)

  # Store previous Twilio SMS SID ID's in a List, again, so we don't waste SQL resources repeatedly querying tables
  with closing(con.cursor()) as sid_cursor:
    sid_rows = sid_cursor.execute("select sSid from Door")   
    sid_rows = sid_cursor.fetchall()
    for sid_row in sid_rows:
      for sid_col in sid_row:
        iSID_Count = iSID_Count + 1
        lstSids.append(sid_col)
        
  print "{0} Service loaded, found {1} authorized users, {2} previous SMS messages".format(time.strftime("%x %X"),iAuthorizedUser_Count,iSID_Count)
  SendGmailToHomeOwner("{0} Service loaded, found {1} authorized users, {2} previous SMS messages".format(time.strftime("%x %X"),iAuthorizedUser_Count,iSID_Count))
except:
  print "{0} Error while loading service, bailing!".format(time.strftime("%x %X"))
  if con: con.close() # Not critical since we're bailing, but let's be nice to MySQL
  exit(2)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#                       MAIN GARAGE LOOP
#
#         Continuously scan Twilio's incoming SMS list
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

while (True):
  
  # The TRY block is critical.  If we cannot connect to the database, then we could possibly open the garage dozens of times.
  # If we can't contact Twilio, again, we could open the garage excessively.  Ideally, if any error at all occurs, we need
  # to completely bail, and ideally contact the home owner that this application stopped working.
  try:

    # Only process messages from today (Twilio uses UTC)
    messages = TwilioClient.messages.list(date_sent=datetime.datetime.utcnow())

    for p in messages:
      sSMSSender = p.from_

      # Only processed fully received messages, otherwise we get duplicates
      if p.status == "received":
        if p.sid not in lstSids: # Is it a unique SMS SID ID from Twilio's list?
          # Insert this new SID ID into database and List, to avoid double processing
          lstSids.append(p.sid)
          try:
            with closing(con.cursor()) as insert_sid_cursor:
              insert_sid_cursor = insert_sid_cursor.execute("insert into Door(sSid) values('{0}')".format(p.sid))
              con.commit()
          except:
            print "Error while inserting SID record to database"
            pass
            
          if p.from_ in lstAuthorized: # Is this phone number authorized to open garage door?
            if p.body.lower() == "kill":
              print "{0} Received KILL command from phone number {1} - bailing now!".format(time.strftime("%x %X"), sSMSSender)
              SendSMS("Received KILL command from you.  Bailing to terminal now!")
              SendGmailToHomeOwner("Received KILL command from phone number {0}.  Exiting application!".format(sSMSSender))
              exit(3)

            if p.body.lower() == "disable":
              iStatusEnabled = 0
              print "{0} Received STOP command from phone number {1}, now disabled.  Send START to restart".format(time.strftime("%x %X"), sSMSSender)
              SendSMS("Received STOP command from you.  Send START to restart")
              SendGmailToHomeOwner("Received STOP command from phone number {0}.  Send START to restart".format(sSMSSender))

            if p.body.lower() == "enable":
              iStatusEnabled = 1
              print "{0} Received START command from phone number {1}.  Service is now enabled".format(time.strftime("%x %X"), sSMSSender)
              SendSMS("Received START command from you.  Service is now enabled")
              SendGmailToHomeOwner("Received START command from phone number {0}.  Service is now enabled".format(sSMSSender))

            if p.body.lower() == "status":
              if iStatusEnabled == 1:
                TakePictureAndUpload()
                print "{0} Status requested from {1}, replied".format(time.strftime("%x %X"), sSMSSender)
                SendSMS("ENABLED.  Status reply: {0}".format(sLastCommand))
              else:
                print "{0} SERVICE DISABLED!  Status requested from {1}, replied".format(time.strftime("%x %X"), sSMSSender)
                SendSMS("SERVICE DISABLED!  Status reply: {0}".format(sLastCommand))
              
            if p.body.lower() in ("open","close"):
              if iStatusEnabled == 1:
                iNumOpenings = iNumOpenings + 1
                sLastCommand = "Garage door last opened by {0} on {1}".format(p.from_, time.strftime("%x %X"))
                print "{0} Now opening garage for phone number {1}".format(time.strftime("%x %X"), sSMSSender)

                # OPEN GARAGE DOOR HERE
                SendSMS("Command received, and sent to garage door")
                print "{0} SMS response sent to authorized user {1}".format(time.strftime("%x %X"), sSMSSender)
                OpenGarageDoor()
                TakeVideoAndUpload()
                SendGmailToHomeOwner("Garage opened from phone {0}".format(sSMSSender))
                print "{0} Email sent to home owner".format(time.strftime("%x %X"))
              else:
                print "{0} Open request received from {1} but SERVICE IS DISABLED!".format(time.strftime("%x %X"), sSMSSender)
                
          else: # This phone number is not authorized.  Report possible intrusion to home owner
            print "{0} Unauthorized user tried to access system: {1}".format(time.strftime("%x %X"), sSMSSender)
            SendGmailToHomeOwner("Unauthorized phone tried opening garage: {0}".format(sSMSSender))
            print "{0} Email sent to home owner".format(time.strftime("%x %X"))

  except KeyboardInterrupt:  
    SendGmailToHomeOwner("Application closed via keyboard interrupt (somebody closed the app)")
    GPIO.cleanup() # clean up GPIO on CTRL+C exit  
    exit(4)
  
  except:
    print "Error occurred, bailing to terminal"
    SendGmailToHomeOwner("Error occurred, bailing to terminal")
    GPIO.cleanup()  
    exit(1)
    
GPIO.cleanup()

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Mon Mar 04, 2019 10:52 am

What have you tried so far? How is your linear actuator connected to the Pi?

You'll need to modify this function

Code: Select all

# Send a signal to the relay
def OpenGarageDoor():
  try:
    GPIO.output(GPIO_PIN, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(GPIO_PIN, GPIO.LOW)
  except:
    print "Error inside function OpenGarageDoor"
    pass
Odds are that you'll add a few more GPIO.output commands to move the linear actuator for a few seconds before the commands that control GPIO_PIN.

If you expect a more detailed explaination, you'll need to provide us with more information about your setup.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Mon Mar 04, 2019 12:47 pm

I have the raspberry pi connected to a gpio board and a 4 channel relay. I have not set any ideal gpio pins for the actuator function.

Here is a link to all the parts in using
6" linear actuator - https://rover.ebay.com/rover/0/0/0?mpre ... 2887896341

Gpio expansion board - https://rover.ebay.com/rover/0/0/0?mpre ... 2155136088

12v 4 channel relay - https://rover.ebay.com/rover/0/0/0?mpre ... 3179029520

And a 12v 5a power supply.

I have the power supply connected into the relay and the linear actuator wired into the com on the relay. Inputs from that same relay are wired into gpio06 and gpio 13 on the expansion board which has the ribbon connected to the raspberry pi. Having those set up completely I am stuck on how to make the linear actuator go from open to closed based on command. To achieve the closed state the actuator would only need to move 3".
Last edited by Djw23 on Fri Mar 08, 2019 6:44 pm, edited 1 time in total.

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Mon Mar 04, 2019 11:05 pm

scotty101 wrote:
Mon Mar 04, 2019 10:52 am
What have you tried so far? How is your linear actuator connected to the Pi?

You'll need to modify this function

Code: Select all

# Send a signal to the relay
def OpenGarageDoor():
  try:
    GPIO.output(GPIO_PIN, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(GPIO_PIN, GPIO.LOW)
  except:
    print "Error inside function OpenGarageDoor"
    pass
Odds are that you'll add a few more GPIO.output commands to move the linear actuator for a few seconds before the commands that control GPIO_PIN.

If you expect a more detailed explaination, you'll need to provide us with more information about your setup.
I have the raspberry pi connected to a gpio board and a 4 channel relay. I have not set any ideal gpio pins for the actuator function.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Tue Mar 05, 2019 8:42 am

If you have the pi connected to a relay board then you must know which gpio you intend to use to drive the relays, we would need to know much more about the operation of the actuator before we could help with the code.

for example

does the actuator just drive when power is applied
does the actuator have its own internal limit switches
how far does it need to travel to do what you want.

and so on.

As we can't see or test your actuator or relay setup you would have to provide every detail of how each component works and is connected before we could attempt to write code for it , it would be simpler for you to do it yourself, just break it down in to smaller jobs,

Start with getting the relay board working with the pi gpio, then test your actuator by connecting power to it so you know how it works ,
then connect it up so the relays can drive it.

The code will develop as you get the relays working and attach each part to the next, once you have the code to drive the actuator then you can integrate it in to your existing code.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 3:58 pm

pcmanbob wrote:
Tue Mar 05, 2019 8:42 am
If you have the pi connected to a relay board then you must know which gpio you intend to use to drive the relays, we would need to know much more about the operation of the actuator before we could help with the code.

for example

does the actuator just drive when power is applied
does the actuator have its own internal limit switches
how far does it need to travel to do what you want.

and so on.

As we can't see or test your actuator or relay setup you would have to provide every detail of how each component works and is connected before we could attempt to write code for it , it would be simpler for you to do it yourself, just break it down in to smaller jobs,

Start with getting the relay board working with the pi gpio, then test your actuator by connecting power to it so you know how it works ,
then connect it up so the relays can drive it.

The code will develop as you get the relays working and attach each part to the next, once you have the code to drive the actuator then you can integrate it in to your existing code.
This is the link that i bought the actuator - https://www.ebay.com/itm/2-18-Inch-Stro ... 2749.l2649

I only need the actuator to extend about 3 inches to go into the (locked) phase.

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 4:19 pm

Djw23 wrote:
Fri Mar 08, 2019 3:58 pm
This is the link that i bought the actuator - https://www.ebay.com/itm/2-18-Inch-Stro ... 2749.l2649

I only need the actuator to extend about 3 inches to go into the (locked) phase.
Okay, and what version did you buy. And what is the other hardware that you are using?

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 4:20 pm

Brandon92 wrote:
Fri Mar 08, 2019 4:19 pm
Djw23 wrote:
Fri Mar 08, 2019 3:58 pm
This is the link that i bought the actuator - https://www.ebay.com/itm/2-18-Inch-Stro ... 2749.l2649

I only need the actuator to extend about 3 inches to go into the (locked) phase.
Okay, and what version did you buy. And what is the other hardware that you are using?


Look for other posts by the same user. There is another thread that contains the shopping list. But no details of how anything is connected. Edit: duplicate thread has since been deleted by moderator.
Last edited by B.Goode on Fri Mar 08, 2019 6:41 pm, edited 1 time in total.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 4:22 pm

Also has same question asked here viewtopic.php?f=32&t=235354&p=1439298#p1439298
with a little more but not all of the information.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 5:07 pm

A okay, that is not very handy of the OP to open more than one topics with the same question.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 5:12 pm

{ Reply overtaken by events and obsoleted. }
Last edited by B.Goode on Fri Mar 08, 2019 6:39 pm, edited 1 time in total.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 6:30 pm

B.Goode wrote:
Fri Mar 08, 2019 5:12 pm
Brandon92 wrote:
Fri Mar 08, 2019 5:07 pm
A okay, that is not very handy of the OP to open more than one topics with the same question.

Quote so. It has been flagged for attention by a moderator.
Duplicate thread has been deleted, duplicates are not allowed here.

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 6:45 pm

Brandon92 wrote:
Fri Mar 08, 2019 5:07 pm
A okay, that is not very handy of the OP to open more than one topics with the same question.
I apologize for opening a new thread it was meant to be added to this one.. I'm trying to update this thread on my phone so it's difficult.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 6:46 pm

mahjongg wrote:
Fri Mar 08, 2019 6:30 pm
B.Goode wrote:
Fri Mar 08, 2019 5:12 pm
Brandon92 wrote:
Fri Mar 08, 2019 5:07 pm
A okay, that is not very handy of the OP to open more than one topics with the same question.

Quote so. It has been flagged for attention by a moderator.
Duplicate thread has been deleted, duplicates are not allowed here.
Hi mahjongg.

Would it have not been better to merge the 2 threads or at lease just lock the older one.

all the information about the hardware in use has now been lost and the work put in by forum members to try and help the OP has also been lost.

forum members come here and give there time to help people and support the pi but if their work can just be deleted through no fault of there own will you not just alienate those who are trying to help and in the end hurt the forum.

yes I know duplicate threads are frowned upon but once there are helpful replies surly there must be a better solution than just deleting them.

This is just my personal option as a member that has suffered my posts in reply to questions being deleted just because its a duplicate post and in not an attack on your or the forum.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 7:51 pm

pcmanbob wrote:
Fri Mar 08, 2019 6:46 pm
mahjongg wrote:
Fri Mar 08, 2019 6:30 pm
B.Goode wrote:
Fri Mar 08, 2019 5:12 pm



Quote so. It has been flagged for attention by a moderator.
Duplicate thread has been deleted, duplicates are not allowed here.
Hi mahjongg.

Would it have not been better to merge the 2 threads or at lease just lock the older one.

all the information about the hardware in use has now been lost and the work put in by forum members to try and help the OP has also been lost.

forum members come here and give there time to help people and support the pi but if their work can just be deleted through no fault of there own will you not just alienate those who are trying to help and in the end hurt the forum.

yes I know duplicate threads are frowned upon but once there are helpful replies surly there must be a better solution than just deleting them.

This is just my personal option as a member that has suffered my posts in reply to questions being deleted just because its a duplicate post and in not an attack on your or the forum.
Im really sorry for all this unnecessary hassle I caused. I'm just really struggling at the moment to get a working code together.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 7:59 pm

Ok as I said in my reply to your other post.

assuming you have the relays set up in an H bridge configuration to be able to drive your actuator motor in both directions .

the code is simple

you only have to switch on a relay to make the motor drive the actuator , then you switch that relay off and switch the other relay on to drive the actuator in the reverse direction.

So your code simply needs to switch a gpio output to make the relay turn on and then wait for a set amount of time to allow the actuator to move.

So if I remember correctly you said you had the wiring of the relays, actuator and psu completed, so have you wired the relays as an H bridge ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 8:53 pm

No problem.
The reason why I was asking what type of actuator you purchased. Is that you might need a couple of sensors that detect if the linear actuator has reach the limit/ setpoint. Otherwise the linear actuator can push further than you want and damage where he is mounted to it. And there are strong, in you case he can push 150kg and he will not stop until it reach his moving limits. So, I would use limit switch within his moving range. That are connected directly to the control relay and overrule the state of the Rpi.

And a other, possible important, part is the safety. What will happend when the Rpi crashed and you can not open the garage door? Are you able to open the door manual in case of an emergency?

So, if you can post a picture of you setup and wiring would be very useful.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 9:06 pm

Brandon92

Djw23 did post details of the actuator in the other thread and it did say it had built in limit switches if I remember correctly.

Djw23 may be you could post the links again along with a diagram of how you have the relay,actuator,psu wired or as Brandon92 suggested some photos if they will show the wiring clearly.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 9:32 pm

pcmanbob wrote:
Fri Mar 08, 2019 9:06 pm
Brandon92

Djw23 did post details of the actuator in the other thread and it did say it had built in limit switches if I remember correctly.
A okay, the actuator has indeed build in limit switches. However the actuator has a range of 6 inch and he only need a range of 3 inch. So one limit switch in the actuator will never be used, hopefully. Because the actuator will never reach his limit. It is smart to make sure it will stop at 3 inch and not make the full 6 inch stroke by adding a additional limit switch.

*https://www.ebay.com/itm/2-18-Inch-Stro ... 2887896341?

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 10:00 pm

I would be inclined to mount the actuator so that at full 6" travel its in the locked position, then you can use a timed unlock ,
but if things go wrong you have a limit switch as a back up and you will always use the limit switch for the locked position, so you have a known starting point and you can have a longer time activation for the locking cycle to make sure its actually locked.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Fri Mar 08, 2019 10:32 pm

That is also a option indeed. And if the lock has a spring you only need to close it for real. And to open it doesn't really matter how far the actuator goes back. As long it is more than 3 inch.

Personally I would use a sensor to detect if it is locked or not. And not really on a time based system. This is because the time could change if the parts are getting older and more dirty. But I would use a timer as a back up to report a error. So, if it takes a x amount of time to open -> close the lock. And the sensors didn't detect this movement in the given timespand, there is something wrong.

However this discussion about this could be very long, and I don't mind that by the way. But let's wait for a bit more information about what the setup is of the OP and go from there :)

Edit, added additional information

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Sat Mar 09, 2019 12:30 am

Image This is my current circuit build. Also it might be best for my actuator to extend completely, the original idea was to fasten a bolt into the hole at the end of the actuator but would honestly be pointless.

Djw23
Posts: 9
Joined: Mon Mar 04, 2019 3:43 am

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Sat Mar 09, 2019 12:32 am

Brandon92 wrote:
Fri Mar 08, 2019 10:32 pm
That is also a option indeed. And if the lock has a spring you only need to close it for real. And to open it doesn't really matter how far the actuator goes back. As long it is more than 3 inch.

Personally I would use a sensor to detect if it is locked or not. And not really on a time based system. This is because the time could change if the parts are getting older and more dirty. But I would use a timer as a back up to report a error. So, if it takes a x amount of time to open -> close the lock. And the sensors didn't detect this movement in the given timespand, there is something wrong.

However this discussion about this could be very long, and I don't mind that by the way. But let's wait for a bit more information about what the setup is of the OP and go from there :)

Edit, added additional information
i do have a magnetic sensor that can be placed into the circuit to tell when the door is opened or closed but didn't know if that was needed to get my wanted results.

pcmanbob
Posts: 9611
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Sat Mar 09, 2019 12:14 pm

Well first I would do some testing to make sure you actuator does as you expect, now I can't remember which gpio you were going to use to drive the relays to you will have to add them to this little test program were indicated.

Code: Select all

import RPi.GPIO as GPIO

import time

fwr = ?  # you need to enter the gpio number for the relay you want to operate the un-lock function
bwr = ? # you need to enter the gpio number for the relay you want to operate the lock function
GPIO.setmode(GPIO.BCM)
GPIO.setup(fwr, GPIO.OUT)
GPIO.setup(bwr, GPIO.OUT)

# switch relays off
GPIO.output(fwr, GPIO.HIGH)
GPIO.output(bwr, GPIO.HIGH)

print ("unlocking  for 10 seconds")

GPIO.output(bwr, GPIO.LOW)
time.sleep(10)
GPIO.output(bwr, GPIO.HIGH)

print ("completed")
time sleep (3)
print ("locking  for 10 seconds")

GPIO.output(fwr, GPIO.LOW)
time.sleep(10)
GPIO.output(fwr, GPIO.HIGH)

print ("completed")
now this is untested so there may be error, but if it works it should drive your actuator for 10 seconds in each direction based on how you have it wired.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How could I adjust this code to open a 12 volt linear actuator before opening the garage door?

Sat Mar 09, 2019 1:25 pm

pcmanbob wrote:
Fri Mar 08, 2019 6:46 pm
mahjongg wrote:
Fri Mar 08, 2019 6:30 pm
B.Goode wrote:
Fri Mar 08, 2019 5:12 pm



Quote so. It has been flagged for attention by a moderator.
Duplicate thread has been deleted, duplicates are not allowed here.
Hi mahjongg.

Would it have not been better to merge the 2 threads or at lease just lock the older one.
Sorry, can't do that, (merging) and really it is the OP's mistake for creating two identical posts. :oops:

I try to delete the one that contains the least useful information, but with two long threads it's hard to decide which one to delete, and I don't have much time to make the decision during the work, this isn't my day job, it is what I do during coffee breaks.

Locking the thread doesn't make the clutter go away, but perhaps I will consider it next time..

in any case I can see the deleted QA were quickly rewritten here.

Return to “Python”