Car window auto drop feature

If any of you have seen a newer mustang (2005+), when you open the door, the window drops about half an inch. and when you shut the door, it goes up into the seal.
I'm looking to do this in my 2004 mustang cobra.

For the input I have the door jamb switch, and the output would need to tap into the window down and the window up wires to the motor. Little bit vague I know, but I don't have a wiring diagram yet.

I've tried to prototype this on a breadboard already using a pushbutton (door jamb switch) and 2 LEDs to represent the signal to control the window motor.

2 problems so far:

1, I could either have the door opening signal turn on the Arduino board and turn off after the door shuts and the window rolls up, or the board could just be powered constantly therefore it would be in a loop constantly waiting for a door open signal. My worry is how well the board would do with being run constantly for a very long time, years in theory. Does it have a low power state?

Tried using "if/else" loops, but I don't know how to make the program work right.
It needs to run a motor (down) for about .5 seconds or less, then wait for the door to shut before rolling up the window. seems simple, but I can't make it work. I've been doing arduino for about 2 weeks, so I'm not very experienced yet, but I've been doing BasicStamp 2 and Propeller and small circuits for a while.

This is my code so far. Be nice, like I said I don't know much of what I'm doing, I fooled around with commands until it did what I want it to do.

The key issue is, when the door opens, I need it to lower the window once and wait for the door to close. I "accomplished" this with the "while" command by accident. then when the door closes, run the window up once and wait for the door to open again.

So how well would the board hold up to running this over and over again for eternity? Assuming this was attached to a car battery, how would this affect battery draining?

/*
The circuit:

  • Window up LED attached from pin 10 to ground
  • Window down LED attached from pin 9 to gnd
  • pushbutton representing door jamb switch attached to pin 11 from +5V
  • 10K resistor attached to pin 11 from ground
    */

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 11; //pushbutton pin representing the door jamb switch
const int upLed = 10; //represents the signal to raise the window
const int dnLed = 9; //represents the signal to lower the window

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LEDs pin as outputs:
pinMode(upLed, OUTPUT); //window up signal
pinMode(dnLed, OUTPUT); //window down signal
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) { //if the door is open
digitalWrite (dnLed, HIGH); //signal applied to lower the window
delay (7500); //time it should take to lower window half an inch
digitalWrite (dnLed, LOW); //stop the window
while (digitalRead(buttonPin) == LOW) { //not sure how to use this, but it works
}
}
else (buttonState == HIGH); { //if the door shuts
digitalWrite (upLed, HIGH); //signal to raise the window
delay (750); //time it should take to raise the window half an inch
digitalWrite (upLed, LOW); //stop the window
while (digitalRead(buttonPin) == HIGH) { //not sure how to use this either
}
}
}

orrinbare:
So how well would the board hold up to running this over and over again for eternity? Assuming this was attached to a car battery, how would this affect battery draining?

So long as the board is properly connected, and installed, it should have plenty of life and the power consumption would not be much worse than the radio memory, so just take slightly shorter holidays if you don't want to disconnect it.

But that window trick has been around for quite a while and it would surely be simpler to get the real switchgear for the job from your friendly Ford dealer, or wrecker.

What does the car do when you have the window down and you open and close the door? Your program should cope with that and other situations, like the program is started when the door is open.

When showing your code use the code tag. (See point 7 at http://forum.arduino.cc/index.php/topic,148850.0.html)

I am surprised it takes 7.5 seconds to lower the window half an inch and only 0.75 seconds to raise it.

You have redundant logic.

if ( test for button UP ) 
   do something
else if ( test for button DOWN ) 
  do morestuff

The point about if ( ) A else B is that if the test only can be one or the other, then you will only do the “B” if it failed the if. The reason for if then else if else if is if there is more than two possible states of what you are testing for (f.ex. a character read from Serial)

while (Test) Stuff ; works because you do not have “Stuff” to be done (perfectly legal) and your “Test” is re-tried and re-tried until it finally is true.

I would use edge detection on the door switch to detect the door opening and closing. I think you also need a 'window fully closed' switch on the lifter mechanism so that you can arm this device only when the window starts off fully closed. I would suggest you also monitor the lifter motors to detect when the window has been moved after the door was opened, and inhibit the auto-lift feature if it has. I'd also suggest putting a short delay between the 'door closed' event and starting the lift sequence since the door switch will probably operate before the door is fully closed.

Uh, why exactly does the window do this...? :~

I see this as a safety issue. What happens if you leave your fingers in the way on the newer mustangs?

Try it with a hot dog first. 8^)

How will you duplicate that behaviour?

rethink is needed
if doorhandle is operated the window moves down whhen closed.
after window the door is released to open
if door is closed and window was closed (befroe opening) close window until closed.

KeithRB:
What happens if you leave your fingers in the way on the newer mustangs?

That is a problem of any electric car window. "Newer" electric car windows which operate automatically have supposedly an overload trip so it might hurt but wont cut off your finger.

That is a problem of any electric car window

Yeah, but it is one thing to catch your fingers in the car window when you are operating the window, it is another thing entirely when the car decides to do it.

SirNickity:
Uh, why exactly does the window do this...? :~

(Just in case OP has gone away..) The seal he refers to is in the frame under the convertible top which then wraps over the windows thereby requiring them to drop a little when you open the door. I'm a bit surprised the 2004 Mustang hasn't got this and I was wondering under the shower last night that perhaps it does, but it isn't working.

Nick_Pyner:

SirNickity:
Uh, why exactly does the window do this...? :~

(Just in case OP has gone away..) The seal he refers to is in the frame under the convertible top which then wraps over the windows thereby requiring them to drop a little when you open the door. I'm a bit surprised the 2004 Mustang hasn't got this and I was wondering under the shower last night that perhaps it does, but it isn't working.

Not just convertibles. My buddy has a 2011 GT500 hard top and does that window down/up as you open and close the doors too.

You really need a window sensor to get this working correctly. When you open and close the door it should only move the window up and down if the glass is up in that almost completely closed position.

As for the finger getting stuck. It can't in this setup. The window barely moves ahh 1/8th of an inch or so. It's just enough to tuck under the rubber seal and get out of it. You'd have to shut your fingers in the door to get that to happen. In which case your fingers are hosed anyways. We've opened the door and disconnected the battery and then shut the door and you can't get your fingers in. At least not on his car.

Ah, that's interesting. I just assumed it was a convertible but I now see the OP doesn't actually say that. I have never owned a pillarless hardtop, but I guess the same principle would apply.

Egch. That just seems like an overly complicated engineering decision that would be plagued with problems from day one. Nevertheless…

If I were designing the electronics, I would want:

A sensor of some sort to detect window position. Under the 1/8th mark? Leave it alone. Over? Drop to 1/8th. Could be done with a gear and linear pot from the drive motor or window travel rails (or whatever mechanism).

Fault detection to protect against stuck windows, fingers, other obstructions. This may be built in to the motor, especially if it can receive up/down commands and do the rest on its own. Otherwise, current draw detection on the motor would probably be a good place to start.

Switch input from the door handle or latch mechanism. I wouldn’t wait until the door moves. I imagine the pull down has to happen fast in case the user exits the car in a hurry and makes the whole effort moot. Store the “door is ajar” status (only if the window is < 1/8th inch from top) in volatile RAM.

Switch input from the door close sensor. Check for door closed and door is ajar status and move window up if both are true. This avoids door open, battery removed, things happen, door is closed, battery is reconnected type of events. If there’s no continuity between door-open and door-closed, let the owner deal with the window position. (Potential flaw: Battery is connected while door is open, but window is not down enough to miss the seal on close. Could check at startup for door open condition and window position to resolve this.)

What about something along the lines of a small magnet glued to the glass inside the door (out of sight) and a magnetic reed switch to pick up glass location. Something more accurate would be ideal. Paint marks on the glass and some sort of optical sensor? That way if window is down more than 1/8 or 1/4 inch the Arduino will know and take no action on door open or close. It also solves things like the battery getting disconnected or reconnected when the doors are open/closed etc. Basically avoid unknown situations.

It would also solve issues like you open the door and the arduino drops the window 1/8" and then the user hits the window switch and moves the window down 2" and then shuts the door. On door shut the Arduino needs to take no action.