1 analog in, 2 digital out

Good morning. I am trying make a timer to open and close my car widows a bit upon entry and exit (to save the door seals). I want to use the door jamb switch as the input (open or closed) to trigger a relay to drop the window for 500ms when the door opens (switch closes) and then lifts the window for 1 sec when the door closes (switch opens). I am trying to figure out how to modify and implement the built in state change program to no avail.

do you know how to control the windows and detect the opening and closing of the door ?

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction

The code could look like this (typed here, fully untested)

const byte doorPin = 2; // the switch detecting the door opening

const unsigned long durationGoingDown = 500ul; // ms
const unsigned long durationGoingUp = 1000ul;  // ms
unsigned long startTime;
enum {IDLE, WINDOW_GOING_DOWN, WINDOW_DOWN, WINDOW_GOING_UP} state = IDLE;

void openWindow() {
  Serial.println("activating window's motor down");
}

void stopWindow() {
  Serial.println("stopping the window's motor");
}

void closeWindow() {
  Serial.println("activating window's motor up");
}

void setup() {
  pinMode(doorPin, INPUT_PULLUP);
  Serial.begin(115200);
}

void loop() {
  switch (state) {
    case IDLE:
      if (digitalRead(doorPin) == LOW) { // door just opened
        startTime = millis();
        openWindow();
        state = WINDOW_GOING_DOWN;
      }
      break;

    case WINDOW_GOING_DOWN:
      if (millis() - startTime >= durationGoingDown) {
        stopWindow();
        state = WINDOW_DOWN;
      }
      break;

    case WINDOW_DOWN:
      if (digitalRead(doorPin) == HIGH) { // door just closed
        startTime = millis();
        closeWindow();
        state = WINDOW_GOING_UP;
      }
      break;

    case WINDOW_GOING_UP:
      if (millis() - startTime >= durationGoingUp) {
        stopWindow();
        state = IDLE;
      }
      break;
  }
}

Sir - thanks for the response. Let me look at this and try to understand it first. assuming there will be a state change on the analog input pins to detect the door opening and closing. Controlling the windows should just be a timed output.

Where does the analog input play a part in the project?

1 Like

Interesting, how it saves the seals?

I don't see any "analog in" here....

Before asking questions:


If your sketch was generated with AI like ChatGPT or by someone else tell us at the beginning of your post.

  • We often ask questions before offering solutions.

Please respond with the appropriate information requested.


  • Questioners know what their hardware and software looks like but the volunteers here do not. You need to fully explain what’s not working, and how it is supposed to work.
  • Before asking your questions, please read all the posting guidelines, follow these guidelines when you post your questions.

Hardware

  • Schematic diagrams are the universal language of electronics.
  • We use schematics to communicate hardware design. All components and connections are illustrated.
  • As always, show us a good schematic of your proposed circuit. Hand drawn schematics are acceptable.
  • Show us several good image views of your actual wiring.
  • Give WEB links to your major components.

Software

  • For readability, place { and } on separate lines by themselves, place each line of code on a separate line.
  • In the Arduino IDE, use Ctrl T or CMD T to format your code, then copy the complete sketch.
  • Use the < CODE / > icon from the ‘posting menu’ to attach your copied sketch
  • Examining a variable for HIGH/LOW or true/false makes your code very difficult to follow.
  • Avoid magic numbers in your sketches.
  • Something like this documents your code for you and tells others what is happening:

#define ENABLED true

#define DISABLED false

//

#define CW 0xB847FF00

#define CCW 0xB847FFA3

//

#define LEDon HIGH

#define LEDoff LOW

//

#define PRESSED HIGH

#define RELEASED LOW



  • When you follow the posting guidelines, volunteers can be more effective.
  • When we have a schematic we can speak the schematic language in helping you.
  • More volunteers will help when you properly post your questions.

Due to safety concerns—mainly regarding the risk of children getting caught in power windows—and other potential legal ramifications, I suggest you review the following resources:

Please ensure that any solution you implement prioritizes safety. I will not be able to answer further questions on this topic.

1 Like

kmin and PaulRB - good morning. The analog is the input signal from the door jamb switch. I guess it could be considered digital but, in my novice opinion, it is analog.

By dropping the windows a bit when opening and closing the car door, the additional pressure is not created when closing the door and same goes with the negative pressure when opening the door. This feature is common on the majority of newer cars and I would like to add it to my older cars, especially my 1959 Impala that does not have door trim on top of the glass. This feature will also help ensure the glass and rubber seal align correctly to provide a better environmental seal.

Thanks for your interest.

@gilschultz - thanks for your safety concerns. However, if you look at the majority of modern cars, they all have this feature. I would like to add this to my older vehicles.

One way you turn an analog signal into a digital signal is with one of the comparison operators.

For example:

aboveThresholdState = analogRead(doorJambPin) > 300;

Then you can use the aboveThresholdState value in place of the buttonState.

Your system is certainly different than this snippet but it might give you ideas to work with.

DaveX - thanks for the suggestion. Do I need to convert the signal from analog to digital? Given the input is 0 or 12v, I would assume the state change will be obvious.

As per @J-M-L @PaulRB and @LarryD intimations, a schematic would be helpful.

Yes, you need to do some conditioning to make the 0/12V signal into something compatible with an Arduino. Perhaps a voltage divider constructed from two resistors would be adequate.

If the signal is 0V or 12VDC, it is already digital, but just not compatible with the arduino.

I would say It’s analog (it’s a voltage) but it’s binary (two possible values).

You need to bring it down to 0/5V or 0/3.3V depending on your arduino so that digital pins could be used to detect the state

1 Like

seal saver schematic v1.pdf (52.1 KB)

I have attached a .pdf schematic. So instead of 0 /12v the input will be open or ground (infinite or 0) as the signal will be coming from the door switch (which passes ground to the dome light).
Looking at @J-M-L's suggested code, it appears that maybe I am over thinking this and just need a digital input pin to determine one of two states and a timer loop with an output pin for each state.

I appreciate everyone's thoughts, time and input.

If your signal output can be either at GND or at a high-impedance state (effectively disconnected or with infinite resistance), then it can work well with an input pull-up on an Arduino pin.

When the signal is in the high-impedance state, the pull-up resistor on the input pin will pull the pin to a HIGH level. When the signal is actively driven to GND, the pin will be at a LOW level.

YES!
So I will do some testing on my Nano when I get home (currently overseas for work). I plan on using pin 15 for input and pins 7 and 10 for the 5v output to the relays. Now to find some 5v relays that are rated for 20A contacts. Power windows typically draw 10A but the fuses are generally 20-30A. Don't need to smoke the relays! :slight_smile:

I've never played with Power windows but it would make sense that when the power window motors start, they draw a higher initial current than their typical operating current. The higher fuse rating would help accommodate this momentary increase without blowing the fuse.

May be MOSFETs would be more appropriate than the typical relays that you find for Arduino.

Remember that the standard voltage in a car's electrical system is typically 12 volts but it can range from about 12 to 14.5 volts depending if the engine is off and the battery is discharging or when the engine is running due to the alternator charging the battery.

Also some vehicles, especially hybrids or electric vehicles, may have higher voltage systems — often around 24 volts or more... So double check what it is.

image
So where is the dome light:

You'll need to take this into account, and translate the 12V (14.4V with alternator running) down to a level safe for your Arduino.

image
Your Arduino cannot power a relay coil directly from any of its pins. You'll need to use a transistor (e.g. a MOSFET). Or just use a ready-made relay module instead of a bare relay.

image
If you're going to feed the Arduino with 12V AND you're going to use 5V relays, you will most likely overheat the onboard regulator on a regular Arduino NANO (or clone) when the relays are powered. It may or may not survive this. It's not good practice to rely on it.

Should work as long as the window motors and the mechanism overall are in good condition. How will your system deal with increased friction as stuff gets dirty and the windows drop and/or rise more slowly?

As to overall stability of your Arduino circuit: an automotive environment is pretty 'dirty' electrically speaking. You may have to take some precautions against stability problems and damage to the Arduino. In particular the power supply is a concern (see also remark above) as well as the door switch input.

@rsmls The dome light is a continuation of the door jamb switch. I plan to piggy back off the switch to get my input state. If that does not work, then I will install an additional door jamb switch for this purpose.

Regarding VCC: the Nano has an onboard voltage regulator and can handle 7-12vdc input. The rest of the circuit will be 5v or less. However, I hear what you are saying and will see how everything tests out with the potential of having to add a voltage regulator on the power input.

Output relay(s): are to be driven by the 5v output from the Nano. The 5v will activate the relay and close the NO circuit that will be attached to the power window switch. The relays can handle 30A @ 30v so there should not be any issues. There are plenty of 5v relays available that allege to handle 10A across the contacts, but no reason to test them. Also, I am not sure a MOSFET could handle a 10A current, even if it was for a second or two. But I am not very knowledgeable on MOSFETs.

Again, this contraption is for my 1959 Impala and maybe for my 1958 Truck. So no need to worry about EV or PHEV.

Sure, vehicles are dirty and the power is not clean, especially in older vehicles. I looked at using a MOSFET, some 555 timers and relays as an option but have not been able to come up with a reasonable solution.
As far as physically dirty, I concur. The only issue I see will be having to adjust the up and down times should things get so dirty that it impedes the movement. That is a reality I am willing to live with in my attempt to "modernize" or add "creature comforts" to my older vehicles.

Yes, and they had multiple teams of professionals from various disciplines working on this, including legal, mechanical, electrical, and electronic experts.