Shop OBEX P1 Docs P2 Docs Learn Events
Testing 12V Switch Open/Closed — Parallax Forums

Testing 12V Switch Open/Closed

MooooolsMoooools Posts: 7
edited 2010-10-03 10:08 in General Discussion
I have tried looking this up but it is hard to know exactly what to search.

Essentially what I am trying to do is replace the switch in my garage door opener with a transistor and control it via a micro controller from a switch on my motorbike.

The idea is that if I flash my headlights twice it will trigger the garage door opener.

How to I create a circuit for the micro controller to test whether the 12V switch is open or closed, ie if the lights are on or not?
I just can't work it out.

Any help would be much appreciated.

Cheers
Max

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-10-02 02:21
    You may not have to test anything, just get your switch logic correct.

    The first question would be what type of switch do you have?

    A lot, if not most, garage door openers use a momentary or push button switch, like a door bell button.

    If that is true, another push button equivalent (like a relay) can be used in parallel. Using a relay isolates the garage door opener electrically from the micro-controller. That is a wise choice when working with 110/220VAC devices - even if the control is something like 12VDC.

    There is a second situation though. IF you have a switch that closes and stays closed, a different form of logic has to be used. That would be using two 'single pole - double throw' switches to create a situation where either one can change the status of the device that is supposed to be on or off. This is most commonly seen in house wiring where you have a hall light that has two switches (one at each end of the hall) that share control of one light.

    In the second context, you can still use a relay. But the installation may be a bit more complex.
  • bill190bill190 Posts: 769
    edited 2010-10-02 08:28
    As said, a garage door opener works by momentarily pressing a switch.

    And without schematic wiring diagrams of the garage door opener, you would have no idea of what electricity goes to the garage door opener switch. It most likely is low voltage, however it could be alternating current or direct current.

    Bottom line is you are best to use a relay and the contacts from that to operate the garage door opener.

    Here is a relay (Thanks Erco from another thread)...
    http://www.radioshack.com/product/index.jsp?productId=2062478

    Then you need a backwards or "flyback" diode on the coil of that so it does not zap your microcontroller...
    http://www.physics.unlv.edu/~bill/PHYS483/relay.pdf

    Then you would need to program the microcontroller to momentarily activate the relay (close the switch) and then release it. A momentary on/off just like pressing the garage door button.

    And you might want to get that working first with a microcontroller like the Basic Stamp.

    Then for the headlight light sensor part. Here is a photo transistor...
    http://www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/SortField/0/Level/a/ProductID/604/Default.aspx

    Then in the Basic Stamp "What's a Microcontroller Book" at the following link, there is all sorts of information on using a phototransistor. See chapter 7 measuring light on page 195. Here is that book...
    http://www.parallax.com/Portals/0/Downloads/docs/prod/edu/28123-WAM-v3.0.pdf

    With that information, you should be able to get the microcontroller to activate the relay with two flashes of light (and along with many hours of trial and error and experimenting of course!)...

    BUT.... Note that light flashes in a city are common. A car may turn the corner and flash lights on your house. Or someone may turn around. Or a city street light may be malfunctioning and flashing on/off. Or as the sun sets it may go behind a tree branch, then start shining again. That is two flashes of light!

    The sun rising and setting. Then the next day rising and setting is also two flashes of light!

    SO... You would want to put a time limit on the flashes of light in your microcontroller program. Make it so the two flashes of light need to be within a certain time.

    And you might be best to make it so the flashes would not be like any accidental flashes. Maybe on for 2 to 4 full seconds, then off for 3 to 5 full seconds, then on for 5 to 7 seconds, then off. (A bit of leeway there.)

    If you make it on for one second, the microcontroller will do exactly that! If your light is not exactly on for one precise second, then it will not work!

    These things do what you tell them exactly.

    Also you might want to make it so if the correct sequence of light flashes does not happen, it "resets" and begins looking for the correct flashes of light after a certain delay.
  • ercoerco Posts: 20,260
    edited 2010-10-02 09:11
    Not much security in 2 headlight flashes. Anybody can get in.

    Where do live? Exactly?
    Anything good in your garage, besides a motorcycle?
    When aren't you home?

    :)
  • bill190bill190 Posts: 769
    edited 2010-10-02 09:31
    P.S. You can eliminate other sources of light and might possibly make this also work during the day by placing the phototransistor at the end of a long tube like a paper towel roller. Then aiming that in a downward direction toward where your headlight will be.

    Then light from the street or street lights would not hit the phototransistor.

    Advanced would be that the light would need to be a certain brightness of light. That daylight would not trigger it.

    i.e. Looking through the tube, a headlight would be brighter than daylight.

    If the tube was looking at a black backdrop, that would reduce the amount of daylight.
  • MooooolsMoooools Posts: 7
    edited 2010-10-02 12:59
    Thanks for the input, but most of it went over my head, and you were trying to solve the wrong problem. That is not your fault though as I was unclear.

    The garage door isn't going to be light activated, the light switch on the motorbike will simply be an easy one to use as a trigger. I could use any switch on the bike such as the horn or starter motor, but the light switch (while still operating the lights as well) is the least intrusive.

    So when I click the light switch twice in quick succession it will trigger the transmitter on the motorbike, which will trigger the garage door to open.

    The question is, what circuit do I use to test for the switch open/closed (whether current is flowing in the circuit or not I guess.

    Anyway here is a crude picture of the simple circuit. A switch and a light. How do I check whether the switch is closed/current is flowing.
    177 x 241 - 2K
  • bill190bill190 Posts: 769
    edited 2010-10-03 09:06
    Do you have a microcontroller you want to program to use for this? Like the Parallax Basic Stamp...
    http://www.parallax.com/Store/Microcontrollers/BASICStampProgrammingKits/tabid/136/CategoryID/11/List/0/SortField/0/Level/a/ProductID/327/Default.aspx


    Or are you just wanting to use your regular garage door opener remote and wire this into your motorcycle headlight circuit?

    As to detecting the motorcycle light switch being on, you could use a continuous duty rated relay wired in parallel to the headlight. Then use the contacts from that to go from there.

    A continuous duty rated relay would be like is used in a car for headlights. It is designed to be on for a long time. Other relays, like those used for a horn, might only be designed for brief use.
  • FranklinFranklin Posts: 4,747
    edited 2010-10-03 09:22
    You could also use an opto isolator by driving the led side from the power for the light through appropriate resistors.
  • ercoerco Posts: 20,260
    edited 2010-10-03 09:29
    Easy as cake. Add 3 silicon power diodes in the circuit per sketch below. Arrow output from top of the diodes goes into a stamp pin; also connect stamp ground to your 12v ground. Pin low= no current. Pin high = current flowing.

    Simple, just be very careful when hooking it up. There is no isolation; one mistake and you will fry your stamp pin. Your motor voltage will drop a tad, hope that's OK... If you wanna make an omelette, you gotta break a few eggs...
    250 x 400 - 7K
  • bill190bill190 Posts: 769
    edited 2010-10-03 10:08
    erco wrote: »
    Easy as cake. Add 3 silicon power diodes in the circuit per sketch below...

    Very clever! Taking advantage of the voltage drop of multiple diodes.:idea:
Sign In or Register to comment.