Author Topic: PROJECT - Gate & garage controlled by Car Lights [PHOTOS]  (Read 15450 times)

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
PROJECT - Gate & garage controlled by Car Lights [PHOTOS]
« on: February 22, 2015, 08:09:30 PM »
I wanted to include the gate into my home automation project, so a Moteino was the obvious choice to remotely control it without those pesky remotes.
Now all I have to do is assemble a module to install in my car and with a flick of the passing light, the gate opens, and a double flick will open the garage.
Stay tuned for that project soon...

This project uses a couple of components:
1 rectifying bridge, 1 condenser, 2 transistors to control the relays, two relays and a LM2596 power regulator board (the blue thing) I got from ebay.

The rectifying bridge is necessary because there is only 24v AC available in the gate control box, so it must be converted into DC, filtered with the condenser and regulated to 5v.

Here is my gate, with the control box on the left:


Size fitting a perfoboard (top right):


Parts layout, without the moteino installed:


And now, with the moteino:


Board spaghetti:


All in its place, ready to use:


Some more detail:
« Last Edit: September 18, 2015, 07:21:00 AM by luisr320 »

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1682
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #1 on: February 22, 2015, 09:20:17 PM »
Looks like a perfect application!  Nice job!  I even recognize the power module you used for the car remote control!  Good choice.

Nice photos (nice digs too!).

An interesting mod would be to have the gate Mote polling the environment, so that, when you drive up to the gate, your vehicle mote gets the poll and then responds with an 'open, says me!'.  Now that would impress a passenger!

Tom

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #2 on: March 01, 2015, 03:45:16 PM »
The poll idea is actually a good way of detecting that the car is in the garage or out since I have the Car node hotwired to 12V. But to have it open the gate without asking for permission, might not be what I would always want. Sometimes I park the car on the curb and it would open the gates when I didn't want to.

So to continue with the remote project, the next step was to get the car Moteino remote connected to the passing lights of my car.
I found a couple of schematics on the net that would allow me to do exactly that. I decided to try to use Eagle Cad to create a small circuit board to be routed on my CNC machine.
My experience with Eagle is almost zero, beside some test experiments. So it was a challenge for me to get some useful results out of it.

This is the schematic of my Moteino car Remote I ended up with:


Initially I had pin 6 of the optocoupler connected to R2 and pin 5 of the opto connected to pin 7 of the Moteino, but couldn't get it to work so after some research, I went on a LOW detection circuit instead, and all worked well.

The car flashing lights 12V are connected to ""LUZES"" on the board, and fed into the optocoupler trough a resistor. D1 is a 23v zener to take care of some wild current that may show up.

The Moteino pins and footprint where taken out from the original Moteino Eagle file after all circuits were deleted.

Eagle autorouter did a terrible job so after a couple of tries I ended up with this:

The blue connection is a wired via that go on the top of the single side board.

I'm sure you will find a lot of those "never do this" errors in my design, but it all worked out fine.

All components are laid down under the Moteino board so the final footprint may be as small as a Moteino itself. The caps need to be bent to the side to allow for space.
The 12/5 v conversion is done by a 78L05 linear regulator. Since there is not much current involved, it is well within the specs of the regulator.



I used a script call PCBGcode on Eagle, that allowed me to produce the Gcode to route out the board tracks, as well as the Drill file with information for the CNC machine to drill the components holes.




And this is the final result. This is not the same board that is on the pic above, because this one still had the HIGH/ON logic that I changed to LOW/ON, as mentioned above.


And the other side is like this (still missing the zener which I didn't had on my parts box)

The cap on the left was rotated on the final board design so that it doesn't have to bend sideways as in this pic.

Final assembly:


All boxed up, and nowhere to go:


And finally, assembled in the car, connected to 12V, ground and the Flash light 12v wire:


So now, when I want to open the outside Gate, I flash the lights 1 time and 2 times to close it. The garage door requires 3 flashes to open, 3 to stop and 3 to close. It may also stop automatically when fully open, of course and in that case it will only require 3 flashes to open and 3 to close.

(continues...)
« Last Edit: March 04, 2015, 10:47:17 AM by luisr320 »

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #3 on: March 01, 2015, 03:54:39 PM »
Code: [Select]
// **********************************************************************************************************
// Moteino Car Remote
// Ver. 4.2
// Changes:
// - Removed some useless Serialprint() code and Flash check routines
// - Change the click check routine to allow for a longclick to open both gates at the same time
// 2014-05-22 (C) luisr320@gmail.com
// Adapted from felix@lowpowerlab.com, http://www.LowPowerLab.com mote.ino
// Creative Commons Attrib Share-Alike License
// You are free to use/extend this code/library but please abide with the CCSA license:
// http://creativecommons.org/licenses/by-sa/3.0/
// **********************************************************************************************************

#include <RFM69.h>
#include <SPI.h>
#include <SPIFlash.h>
#include <avr/wdt.h>
#include <WirelessHEX69.h>
#include <ClickButton.h>

#define NODEID 6 //unique for each node on same network
#define GATEDOORID 5
#define GARADOORID 4
#define NETWORKID 100 //the same on all nodes that talk to each other
#define FREQUENCY RF69_433MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define ACK_TIME 100 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200
#define LIGHTPIN 7 //Defines the pin to which the car light wire is connected

//Initialize some variables
int doorId = 0;// This variable will hold the Destination Node number
long int code = 0;// This variable will hold the code that will be sent to a node

// Hardware Init
SPIFlash flash(8, 0xEF30); //Initiate the FLASH chip - EF40 for 16mbit windbond chip
RFM69 radio; // Initiate the radio
ClickButton lightFlashes(LIGHTPIN, LOW, CLICKBTN_PULLUP);//Initiate the button class

void setup()
{
//Setup the pins
pinMode(LED, OUTPUT);

// Setup button timers (all in milliseconds / ms)
// (These are default if not set, but changeable for convenience)
lightFlashes.debounceTime   = 20;   // Debounce timer in ms. Default 20
lightFlashes.multiclickTime = 500;  // Time limit for multi clicks. Default 200
lightFlashes.longClickTime  = 1000; // time until "held-down clicks" register. Default 1000

//Start the Serial port
Serial.begin(SERIAL_BAUD);

//Initialize the radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
radio.setHighPower();
radio.encrypt(ENCRYPTKEY);//Turn encryption ON
radio.promiscuous(false);//Turn off promiscuous mode to allow Wireless Programming
}


void loop()
{
//Check if some data came trough the radio
if (radio.receiveDone())//If some packet was received by the radio, wait for all its contents to come trough
{
//Check if data is wireless programming
CheckForWirelessHEX(radio, flash, true);// If the WP header is detected, start WP routine and restart the MCU at the end 
}
   
//Check if the light was flashed
lightFlashes.Update();//lightFlashes.Update will fill lightFlashes.clicks variable with the number of light flashes

if (lightFlashes.clicks != 0)
{
if (lightFlashes.clicks == 1)//One light flash
{
doorId = GATEDOORID;
code = 1;//Open the Gate
//Send code to doorId node via radio
if (radio.sendWithRetry(doorId, (const void*)&code, sizeof(code), 5, ACK_TIME))
{
Blink(LED,50);
}
  }
else if (lightFlashes.clicks == 2)//Two light flashes
{
doorId = GATEDOORID;
code = 2;//Close the gate
//Send code to doorId node via radio
if (radio.sendWithRetry(doorId, (const void*)&code, sizeof(code), 5, ACK_TIME))
{
Blink(LED,50);
}

}
else if (lightFlashes.clicks == 3)//Three light flashes
{
doorId = GARADOORID;
code = 1;//Open or Close the Garage Door
//Send code to doorId node via radio
if (radio.sendWithRetry(doorId, (const void*)&code, sizeof(code), 5, ACK_TIME))
{
Blink(LED,50);
}
}
else if (lightFlashes.clicks == -1)//Hold flash lights for more then 1 second
{
doorId = GATEDOORID;
code = 1;//Open the Gate
//Send code to doorId node via radio
if (radio.sendWithRetry(doorId, (const void*)&code, sizeof(code), 5, ACK_TIME))
{
Blink(LED,50);
}
doorId = GARADOORID;
code = 1;//Open or Close the Garage Door
//Send code to doorId node via radio
if (radio.sendWithRetry(doorId, (const void*)&code, sizeof(code), 5, ACK_TIME))
{
Blink(LED,50);
}
}

//reset variables
lightFlashes.clicks = 0;
doorId = 0;
code = 0;
}
}


void Blink(byte PIN, int DELAY_MS)//Local led blinking function
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}
« Last Edit: March 03, 2015, 06:47:03 AM by luisr320 »

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #4 on: March 01, 2015, 04:13:43 PM »
To check for the number of light flashes, I installed a library that does exactly that, ClickButton.h, that counts button clicks, where I can define the timings between clicks (or light flashes in this case) to still be considered a sequence of clicks, debounce timing, and if the button is ON when LOW or HIGH.
The library can be found here:
https://code.google.com/p/clickbutton/
All I had to do was insert
Code: [Select]
#include <ClickButton.h>

Initiate an instance of Clickbutton
Code: [Select]
// Hardware Init
SPIFlash flash(8, 0xEF30); //Initiate the FLASH chip - EF40 for 16mbit windbond chip
RFM69 radio; // Initiate the radio
ClickButton button1(LIGHTPIN, LOW, CLICKBTN_PULLUP);//Initiate the button class

And define the timings in the setup()
Code: [Select]
button1.debounceTime   = 20;   // Debounce timer in ms
button1.multiclickTime = 500;  // Time limit for multi clicks
button1.longClickTime  = 1000; // time until "held-down clicks" register

Then, on the loop() I run the button state by running
Code: [Select]
button1.Update();

This will return a variable (button1.clicks) filled with the number of clicks that was counted and then process that into the radio.sendWithRetry to command the respective Gate node.

Initially I wanted the Car node to connect directly to the Gateway and the Gateway would then dispatch the commands to the Gate nodes. This way I could monitor when the gates were commanded to be opened or closed. But since the Car node is deep inside the metal framework, the connection to the gateway wasn't very reliable, so I decided  to directly control the gate nodes avoiding having to deal with an intermediary.

As the car is always in close proximity with the gate control boxes where the nodes are installed, this works very well and now I get 100% reliability on the process.

The Car node is hotwired to the car 12v so that I may open or close the doors without having the ignition ON. As the whole thing only consumes 23ma, there isn't much drain on the battery. However, I will change the design in a near future to have the board sleeping just to wake-up when the lights are flashed on a interupt pin. That will drop the current into the micro amps range.

Keep tuned... :)
« Last Edit: March 02, 2015, 06:26:31 PM by luisr320 »

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1682
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #5 on: March 01, 2015, 06:02:33 PM »
Um, you're probably going to blowout your Moteino and radio running it from 5V driven into its 3.3V OUTPUT.   The 5V power should be driven into the PWR pin of the Moteino.  And the pullup from the opto isolator driven from the 3.3V OUTPUT of the Moteino. 

The 5V regulator isn't really necessary either, you can power the Moteino directly from the car supply (nominally 12V but will reach above 14V when charging).  The Moteino regulator can handle up to 16V, but this usually makes Felix cringe (which we like to do on occasion)   :D

Tom

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #6 on: March 02, 2015, 01:49:30 AM »
Thank you TomWS for your comments and for noticing that error which I did on the first run.

If you check the lower part of the circuit board, the one with the messy soldering, you can see that I did change the connection from the 3.3v OUTPUT of the Moteino to the 5v POWER, the pin next to the GND.
I will make the changes on the schematic and board layout today and replace the ones posted here.

As for the 5V regulator, I already had one blown on my first Moteino so I always prefer to have a cheap voltage regulator to ease on the Moteino's regulator. Not that the Moteino regulator is weak for the job, but the poor thing can't handle all the bad thing I did to it like reverse polarity and other terrible things. :-/

I'm also considering using a temperature sensor to compensate for the engine high temp to avoid frequency drift and build a PCB for the Outer Gate Moteino Node to replace the perfoboard.

As the car box is very accessible I'll keep on upgrading it as soon as I have more available time from my busy work.

I'll make a video showing how it all works soon.


TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1682
    • View Profile
Re: PROJECT - Gate control [PHOTOS][FINISHED]
« Reply #7 on: March 02, 2015, 08:43:21 AM »
Thank you TomWS for your comments and for noticing that error which I did on the first run.

If you check the lower part of the circuit board, the one with the messy soldering, you can see that I did change the connection from the 3.3v OUTPUT of the Moteino to the 5v POWER, the pin next to the GND.
I will make the changes on the schematic and board layout today and replace the ones posted here.
<snip...>
I see that you moved that leg (on the PCB) to the PWR pin, which will save your radio, however, this still leaves R2 pulled up to 5V, rather than 3.3V as it should be.  Fortunately, you've changed R2 to a 10K resistor so that will reduce the amount of potentially damaging current into pin 7.

Tom

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #8 on: March 02, 2015, 12:48:43 PM »
I'm in the process of changing the input pin to pin 3 to use the interrupt function and connect it to 3.3v.
Should I switch R2 back to 4.7k?

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1682
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #9 on: March 02, 2015, 03:34:45 PM »
I'm in the process of changing the input pin to pin 3 to use the interrupt function and connect it to 3.3v.
Should I switch R2 back to 4.7k?
It depends on the code you use to sense a change on the pin.  Opto-isolators, especially open collector ones, are notoriously slow rise time (the transistor takes a long time to turn off).  The higher the current into the collector, the faster it will turn off (to a point, of course).  4.7K pulled to 3.3V will give you just a bit faster rise time than 10K pulled up to 5V, conversely, keeping it at 10K it will be almost twice as long a rise time.

Tom

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #10 on: March 02, 2015, 06:20:23 PM »
I have updated the Car RC schematic, presently on version 2.1, in order to get the input on pin 7 coming from a 3.3V pullup, from a 4,7K resistor.
I'm not going to try the interrupt feature of pin 3 yet, so for now it is still connected to pin 7.
I have also changed the circuit board, accordingly, to version 2.1.

Tomorrow I'm going on a trip, but on Friday I will be able to create a new PCB and test this changes. So consider this project as Beta for now.

Thank you, TomWS, for your inputs.

I'm also posting a link to the Eagle Cad files, just in case someone might want to have a go on a similar project.

Eagle Cad files - Ver. 2.1

« Last Edit: March 12, 2015, 08:56:43 PM by luisr320 »

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #11 on: March 08, 2015, 01:16:44 PM »
I decided to replace the prototype perfoboard on the gate with a PCB milled on my CNC machine.

This is the PCB layout:


I decided to replace the power regulator by a linear 7805 regulator.
I have also inserted a DS18B20 temperature sensor under the Moteino radio so that I may include some frequency temperature compensation routine on the sketch.
I have no idea on how to do that yet, but I found a couple of post here in the forum pointing in that direction.

I decided to not include the DS18B20 in this project.

I have also change the big rectifying bridge for a smaller one and switched the relays for a couple of 3.3v ones.

This is the new schematic of the Gate Door Node:



I'm milling the board now and I'll post a couple of photos when its ready.

These are the Eagle files:
Moteino Gate Door V3.0.zip
« Last Edit: March 12, 2015, 08:52:08 PM by luisr320 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5130
  • Country: us
    • View Profile
    • LowPowerLab
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #12 on: March 08, 2015, 04:40:35 PM »
Very nice, any chance to post a video of milling the PCB? :D
I'd like to one day get into milling PCBs at home also .. just not enough time in this life :(

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1682
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #13 on: March 08, 2015, 05:21:28 PM »
I decided to replace the prototype perfoboard on the gate with a PCB milled on my CNC machine.

<snip...>
Interesting.  I've looked at using my CNC router for this but haven't pursued it.  I use the router for V Grooving panelized boards, but haven't done any other PCB routing.

Three questions:
What software did you use (ie to go from schematic to GCODE)?
What router bit do you use?
How deep do you route below the surface?

Tom

luisr320

  • Full Member
  • ***
  • Posts: 213
  • Country: pt
    • View Profile
Re: PROJECT - Gate controled by Car Lights [PHOTOS][FINISHED]
« Reply #14 on: March 08, 2015, 10:19:03 PM »
Almost finished.
I milled the PCB on my CNC machine and this is the result (the relays are just place holders for the 3.3V i'm getting tomorrow):



Regarding your questions:
Quote
What software did you use (ie to go from schematic to GCODE)?
I use Eagle Cadsoft to draw the board and then I run a ULP script called "pcb-gcode" that is available free here:
http://pcbgcode.org/read.php?12,941
I then load the G_Code directly in MACH3, set the machine up and press RUN

Quote
What router bit do you use?
I use a carbide 60 V tool. I bought it from a local store.

Quote
How deep do you route below the surface?
The script is programed to the dept of 0.127mm, with a etching tool size of 0.1788mm

I haven't perfected the method yet but it's good enough for a quick job.
There are other scripts that you can run that will perform a auto-leveling of the PCB and for optimizing the bit travel but I don't use them. I just use double sided tape and stick the PCB to the machine table and fire away.

I'm preparing a 1 minute video of the board milling and will post it on Youtube to get a link.

This is the result (red trace is a error I did on the design):


« Last Edit: March 08, 2015, 11:20:47 PM by luisr320 »