programming help

I recently discovered the arduino and it has rekindled an interest in electronics I haven't pursued since I was young.

I have been studying everything I can find and have worked thru many tut's and projects. the hardware stuff is coming back easily but programming is definitely my weak point.

I am attempting to create a device to give modern style control of the power windows in my old car. it should open the window fully with a quick press of the button and stop with a second press or when it reaches the limit (current sensor). If the button is held longer then it should stop on release.

This seems as if it should be fairly simple but I haven't been able to wrap my head around it yet. I would greatly appreciate it if someone could point me in the proper direction.

edit: Maybe this should of been in the programming forum if so feel free to move it

There is a neat example of multiple uses of a button here. It may give you some ideas.


I'm not quite sure I'd use a microcontroller for something like this... The logic isn't that complicated, and it could probably be accomplished with and-gates, or-gates, flip-flops, etc. But then again, it depends on what you are more comfortable with and whatever seems easier... For example, it's kind-of silly to blink an LED with the Arduino, but I can download & run the Blink LED example in a couple of minutes, whereas it would take me a coupe of hours to breadboard a 555 timer to blink an LED.

but programming is definitely my weak point.

OK... The "trick" to programming is to write a little code at a time and "develop" your program.

As a beginner, try to write one or two lines of code a time. Test-compile and test-run as you go along. This isn't quite as easy as it sounds because your code has to "make sense" to the complier. For example, if you cut-off the bottom-half of any of the example programs, they generally won't compile.

Of course, experienced programmers write more than one or two lines at a time, but NOBODY sits down and writes the whole program at once!

It's also helpful to use the serial monitor to keep track of what your program is doing. For example, you can display variable values or just send messages such as "button pushed", "limit reached", "window-up" or "window down" so you know what your program is doing (or what it's supposed to be doing). And, you can use LEDs... You could use an "up LED" and a "down LED" to test things before connecting a motor.

The "trick" to any project is to break it into parts. For example, there is hardware and software associated with inputs (sensing the switch and the motor current*), and hardware & software that runs the motor one direction or the other. Then there is the program logic that decides what to do with the inputs.

I think I'd start with the input. Make sure your sketch can read the switches & current before controlling the motor with the Arduino.

Read-through the Language Reference and some of the examples. You won't understand or remember everything in the language reference, but it's not that much to read through, and you'll get a good idea if the things you can do.

The two most important concepts in programming are conditional execution (if-statements, etc.) and loops (doing things over and over, usually until some condition is reached). When you understand those two concepts, you'll have a good understanding of how programming "works".

If-statements are most-likely going to be the key to your project... If the button is pushed-up momentarily, do this... If it's held-up or pushed-down, do that...

  • I don't know how modern power windows work, but there might be a microswitches to sense when the window is fully-up or fully-down. If you want to monitor the current, note that there is an initial "kick" in current when you start the motor and you'll have to ignore that.

One feature I wish my windows had is I wish they'd go up with the key off. Or, it would be OK if they would just stay active for a minute or two after the key is turned-off. Or, maybe it would be nice if I could roll-up the windows with the remote door lock... Maybe by pushing the button twice, or something like that.


Thank you for the link. that does give me some clue on how it might be accomplished


Thank you for the sound advice. this is but the first part of my project. I also want to control the door locks and door "poppers"(open the doors) and eventually add bluetooth and control it all with a phone app, so you can see why I chose to use an arduino.

I like your idea to have the window close automatically when leaving the vehicle, also have a few other idea's too. but they are for a later date.

I have never seen any limit switches on any of the doors I have worked on and using a current sensor seems the safest since it would also stop if it encountered a obstruction. I will have to remember to deal with the start up spike.

As a follow-on to @DVDdoug's excellent advice the Thread planning and implementing a program may be useful.


yeah, I found that thread yesterday. most excellent. while I haven't finished it yet the first line stopped me in my tracks. I had already started trying to modify the code in the link you sent me and it made me realize I was going about it wrong.

so now I am first trying to strip out the parts of it I don't need(double click,long press and hold)while keeping it functional and trying to really understand how it works before moving on to my stuff.

I see your posts all over this forum. many thanks for all the help you provide for us "newbies"

You might look at power window switches on ebay, they may already contain the electronics to do what you want.