Adaptive Headlights

Hello all!

I have bought an Arduino Uno and have been playing around with it for a while and have finally come up with a project i'd like to do - Fully adaptive headlights as per top of the range BMWs Mercedes etc except on a Landrover Defender!

-The physical movement of the headlight units is not a problem, i'll use servos and linkages to move the lights. -For vehicle level detection I plan to use a single potentiometer on the rear axle top mount to detect how loaded the truck is and send this analogue input to the Arduino. -For the cornering i was going to use another potentiometer connected to the steering arm to sense steering angle again into the Arduino. -Light sensing would be nice (i.e turn the lights on when dark/off with light)

Now for the bit I'm really struggling with, I have played around with the "knob" sketch that is on the arduino software and can get basic control of the servos movements but that is as far is I've got.

I'd like to integrate electronic damping into the setup so the lights aren't bouncing everywhere over bumps and also have a snap to forwards code so that small steering corrections when going in a straight line don't make the lights "wonder" around

I have no idea how to add the automatic lights on function

It would be sweet if the lights did a test movement when the first switched on, for example full down then up to the correct level

If you have read this far, Thank you! and perhaps you'll read a little further?

I have next to no knowledge when it comes to programming but my mechanical and physical electrical skills are good, if someone would be willing to help walk me through writing a program to make this happen i would be most grateful, I believe that no other Landrover Defender in the world will have fully adaptive headlights if i can make this work with your help!

Many Thanks in Advance, George

I'd like to integrate electronic damping into the setup

Two ways to do that. One is to look for, and only react to, large changes. If the value of the pot changes by more than 3, move the lights. That may result in the lights not being reactive enough. The other is to ignore changes for a while after moving the lights. Say you read the pots only every 50 milliseconds. Jitter will then be ignored. Change the interval to what suits you.

I have no idea how to add the automatic lights on function

Add an LDR. Read the LDR. If the reading is low, it's dark. Turn the (relay controlling the) lights on. If it's high, it's light, so turn the (relay controlling the) lights off.

It would be sweet if the lights did a test movement when the first switched on, for example full down then up to the correct level

Having the lights do that because they came on because you entered a dark tunnel seems like a bad idea. Having the lights dance for a second when the Arduino is powered up is a different story.

Personally, given the questions you are asking here, I don't think you are ready to take on a safety critical project like this.

Thanks for your Comments, and speedy reply, most helpful!

The auto lights on/off function i had realized i needed a LDR but i didn't know if that would require some sort of threshold limits or maybe two sensors to stop the lights turning off under street lighting etc.

The test movement is actually a common thing on vehicles with adaptive lights. Well, certainly a few BMWs i have seen it on.

I know i have very limited knowledge of programming but I'm really determined to get this to work. I understand that headlights are safety critical however the adjustments won't stop them lighting the road completely and if the system were to fail on a journey i could always pull over, unplug the servos and physically move the headlights into their correct position.

Maybe some help on auto on off first and take it from there?

These "automatic on" headlights are becoming a genuine menace nowadays, with people driving with headlights on in the daytime and in car-parks, causing glare and eye fatigue, and also completely defeating the purpose of having motorcycles and emergency vehicles stand out by having their headlights on.

As in any other area, it is a matter of "crying wolf" - if many vehicles have their lights on, then vehicles driving with lights on in daytime will automatically be ignored or even automatically looked away from - there is no safety benefit at all and if anything, a definite hazard.

My advice then is - make sure your light sensor is very sensitive (so that it only responds to definite landscape darkness) and averages light over as wide an area as possible (so as not to respond to point sources), also with a considerable averaging time (at least five seconds, except when the car is first started) to avoid it tripping in car parks and underpasses.

Every car in Canada is equipped with headlights that are on whenever the motor is running. The brightness is usually some percentage of that of switched on headlights (60% comes to mind, but I am unsure of that figure). The only real argument I have with these is that the taillights do not come on at the same time. The reason for the headlights is for visibility in all ambient light conditions, and I think visibility would be enhanced by having the taillights on too. One of the hazards of these headlights is that drivers often forget to actually turn the headlights on as the ambient light decreases, because they see the (fainter) light from them, but that leaves the rear of the car unlit. I've personally had near-accidents because of this.

Perhaps you are not as plagued with heavy overcast, mist/fog, rain or snow as we are here.

On the other hand, perhaps you are referring to auto-on full brightness headlights, such as are found on (for example), the Hyundai Sonata Hybrid. My wife's has them, and the switch never noves off the auto position. Yes, they'll come on when going through a longish tunnel, but so what? If it's dark enough, you really should have them on.

Edit: I forgot to mention... emergency vehicles have flashing blue and/or red lights, usually xenon strobes. They are definitely easily distinguishable from cars with headlights on. Snow plows are even more brightly lit, with the various lights operating with differing flash periods. Of course folks still run into the back of them, but that's just because a too-large percentage of drivers are idiots.

lar3ry:
Perhaps you are not as plagued with heavy overcast, mist/fog, rain or snow as we are here.

Correct, and that is exactly the point.

If you cannot see the road ahead, then knowing where an oncoming car is, is absolutely necessary.

When you can see the road ahead, and the cars travelling on it - on the correct side of the road, the situation reverses - glaring headlights prevent accurate observation of the behaviour of the oncoming traffic and potential hazards such as people pulling out to overtake or even anomalies on one’s own side of the road.

Paul__B: When you can see the road ahead, and the cars travelling on it - on the correct side of the road, the situation reverses - glaring headlights prevent accurate observation of the behaviour of the oncoming traffic and potential hazards such as people pulling out to overtake or even anomalies on one's own side of the road.

60% headlights when the motor is running are definitely NOT in the category of 'glaring' headlights. They do, however, make the cars more visible, and if it's bright enough to see the road, they offer no significant glare; not under any conditions.. Additionally, as conditions deteriorate, drivers do not have to react to the dropping visibility, as they have no choice in the matter; their lights are on. The only time I am ever bothered by glaring lights is at night, when headlights are required to be full on anyway. Again, emergency vehicles do not rely on headlights for identification. Perhaps it's different in Australia.

But we digress. I agree with your other comments about wide-angle and time-sensitive averaging.

http://www.austlii.edu.au/au/legis/nt/consol_reg/avsr324/s85.html http://www.vicroads.vic.gov.au/Home/SafetyAndRules/SaferVehicles/VehicleDesignStandardsAndAccessories/FogAndDrivingLights.htm Here in Australia we have regulations for running lights for daytime operation, 25W max light. Does not state LED or Incandescent. Also some brief conditions on adaptive lights. Tom..... :)

TomGeorge:
Here in Australia we have regulations for running lights for daytime operation, 25W max light.

Which are systematically ignored. :smiley:

The problem we have is that as in the reference, cars are imported configured for those European conditions which simply are not present here.

TomGeorge:
Does not state LED or Incandescent.

Though the latter reference notes the current use of LEDs - which are now quite passably comparable in brightness to headlights when seen on axis.

One of the problems of low-beam headlights is of course, that they become equivalent to high beam as the car comes over a crest - one of the exact times you do not want glaring headlights.

Whiklst I do not have the problem myself, I do live in “gerry” country, where a significant number of drivers suffer from cataracts and are even more importuned by glare.

Thanks for all of you input.

Automatic headlights are a very common thing on newer cars, even small city cars here in the UK and almost a standard feature on high end and luxury cars. I appreciate the turning on under bridges is an irritation and that's why I need programming help, also I happen to ride a motorbike and welcome people driving with their headlights on in certain light conditions.

So if I can try and coax the conversation back towards my original question, can anybody help walk me through the programming for the aforementioned project?

Cheers, George

Grafty99: So if I can try and coax the conversation back towards my original question, can anybody help walk me through the programming for the aforementioned project?

It all seems feasible, but there are several different technological problems you will need to address to complete it. I think it would be sensible to tackle the different functional areas separately and gradually work towards your overall solution.

Turning the lights on can be done by using a light dependent resistor (LDR) to detect the ambient light level. You could smooth the reading over a few seconds to prevent the lights being affected by shadows and bridges if you want, a simple decaying average would be sufficient. The simplest algorithm would be to turn the lights on when the ambient light is below a threshold. If you want to be able to fade them progressively then that implies applying pulse width modulation, which means you'd need to control them electronically rather than just via a relay. It's conceptually simple but you'd need to build an electronic circuit capable of switch twenty amps or so and deal with all the cooling issues involved. I don't know how well vehicle lights would take to being pulse width modulated, but if it's an ordinary incandescent bulb I suppose it should be OK. If you're using HID then that would be very different.

Steering and elevating headlamps is mainly a mechanical problem (you would need to design a mechanism which holds the lamp assembly securely and prevents it rattling and avoids loading the servo due to bumps etc, and then add a linkage/mechanism to move it as required. The software side seems simple enough, but making the hardware reliable enough might be a problem - especially sensor inputs such as steering angle sensors.

Since you're planning to implement several independent features I suggest that you adopt an synchronous (non-blocking) approach from the outset. It will make the initial implementation slightly more complicated but you will appreciate the benefits as soon as you start trying to control multiple things at the same time.

PeterH thanks for your detailed reply, in no particular order; the mechanical side I am confident I can get to work faily simply, the sensors aren't a problem as I have got ride height sensors off a air suspended vehicle, adapted to mine. The movement of the lights I am also confident about as I'm using 25kg rated servos (powered by a separate power supply)

Although I could fade my lights as they are high power led units, I want to keep it simple and use a relay for basic on/off

When you say non-blocking do you mean write one program to do all functions then add the sensors and servos as I go?

Cheers, George

By non-blocking I mean that the program doesn't stop and wait (block) for something to happen. The 'blink' example is an example of a blocking sketch. The 'blink without delay' is an example of a non-blocking sketch. The blocking approach is simpler for trivial sketches but when you start trying to control multiple independent things you will appreciate the advantages of the non-blocking approach.

Hi, we would need to know what the output is from the ride height sensor to setup the input for the arduino. Some maths would have to be done probably because the lights are not over the height sensors. The arduino can do the dimming and auto operation, but I agree with Graffy99 about the type of lights you want to control.

Tom....... :)

Grafty99: Hello all!

I have bought an Arduino Uno and have been playing around with it for a while and have finally come up with a project i'd like to do - Fully adaptive headlights as per top of the range BMWs Mercedes etc except on a Landrover Defender!

That sounds like a really neat project!

I can give you some ideas, concept wise (as opposed to actual code).

For the steering tracking, what you want is for the lights to follow the wheel, but not wander a small amount due to normal driving.

Therefore, you would need two things: (1) A low pass filter (i.e. averaging many position readings) to remove "high frequency" signals (that is, small steering movements during actual driving). However, the low pass filter would slow down response time and the lights would lag behind the wheel movement, so you would also need (2) A deadband. If the wheel moves around, but within a small range, just average it. But if it moves more than the deadband, respond to it immediately (then go back to averaging).

For light elevation adjustment due to load, that would be a simple low pass filter (digital filter - that is, averaging samples). The axle will be bouncing all over the place, but the average position will be defined by the load in the car, so all you need here is a LONG average time... probably in the minutes range.

For auto on and off, that's the most difficult. Where you put your sensor (what will determine on and off? Day and night?). Also, you will need a low pass (digital) averaging filter so that momentary light sources (a passing car with headlights) doesn't fool your system into thinking it's daytime. Also, reflections from roadsigns can false trigger your system.

Google the history of auto makers trying to make auto headlight dimmers and you will be surprised at the problems they had!

Another thing, I don't know what your location is, but if you are going to do this on a car that you drive on the road, there are probably laws that state how bright your lights must be, how they must be aligned, etc... and your motorized system will no doubt be illegal on a road car.

Lastly, be aware that a car is a VERY hostile environment for electronics. There is vibration, humidity and voltage swings as well as voltage spikes. Your circuit needs to be able to handle all of these (especially voltage spikes and voltage droops due to starting the engine or turning on lights/fans/heaters/etc....). Vibration is another killer. Your mounting and wiring will need to be able to handle vibration. Also, most automotive electronics are either potted in epoxy or else covered in a thin plastic layer called a "conformal coating" to keep out moisture and humidity.

Ruggedizing electronics for an automotive environment is a whole branch of engineering in itself.

Good luck! Sounds like a really fun project!

If you are in the UK, you probably want to first check how such a modification fits in with the MOT - I could easily see fitting a homebuild device to the headlights would get you a fail.

I'm not too worried about the legality of it, if the system fails for whatever reason I will have a manual switch to turn it off and then I can physically move the lights into the correct position.

As for sensor inputs, they are two potentiometers. One does axle height and the other steering position.

Most cars with automatic lights have the sensor on the dash or in the windscreen, I plan on doing the same, would it be possible to put a delay in the software so that the lights only turn off if the light level has been above the threshold for, say, 5 minutes?

You may not be worried, but as another road user I am! How can you possibly know if your lights are “in the right position” while you are driving along and not dazzling other road users.

There’s a reason things like this are checked in an MOT! If they are enforced by law, that is saying this is of sufficient importance that you should not be dicking about with it yourself!

In the UK there are some extensive regulations about lighting but I don't think there is anything explicitly prohibiting DIY light steering as long as the light is correctly e-marked, uses a legal bulb and is correctly aligned. The only check I've ever seen at an MOT is a simple alignment check. A plain old static setup on a car without load leveling can point the lights all over the place so a DIY installation would need to be pretty bad to be worse than that.

I'm really not here for an argument, I would like help with the programming to make this work, I am a responsible person and if I see that every driver passing me is flashing their lights then I'll pull over and adjust them down.

I also agree, there is no legislation on diy auto adjustment, one the system is up and running I will test the beam height against a wall with varying loads to make sure the lights stay in the correct position, then when I'm satisfied I can have the alignment checked by an mot station, but for that to happen i need help, not an argument on how it isn't going to work

Please can someone help me to write some code?