Arduino Controlled Automatic Headlights(Programing Noob)

I'm new to programing and was wondering if I could use an Arduino board as a control module. I want to make a module that can turn my trucks headlights on when it senses its dark out. Components that would be used is a photo cell and it would be hard wired into the trucks fuse board. Here's a wiring diagram of an aftermarket module I saw( $135.00! OUCH! smiley-eek)
http://photobucket.com/wiringdiagramexample

Back in the 50's there was a car (I think GM product) that had auto dimming headlights when meeting another car headlights. It wouldn't be good if headlights or overhead street lights turned your headlights off.

I know exactly what your talking about. My moms 65(???) Impala had it and she loved it. Although I'd have to disagree with the street light idea because my 03 Tahoe has it and the sensor is in the center of the dash right by the windshield. I'm completely new to programing and would like to know how to make this work.

The picture is really small so I can't see what's going on there. Just turning on headlights doesn't actually need arduino. You can use a Schmitt trigger to trigger on the voltage on a voltage divider involving the light sensitive resistor and a fixed resistor in series.

Here's something you can read:

Depending on what weather you have in your region, you could probably easily get cheap enough parts for a Schmitt trigger but I'm not sure about arduino's atmega328P chip. I wouldn't leave my arduino in my car in the cold north.

There were probably a proposal to polarize all headlights in the same direction and windshield so to reduce glare from on-coming traffic. The same problem occurs (too dark to see oncoming traffic :))

An arduino can do it but you can do it without an arduino probably cheaper, a photocell and a resitor can form a voltage divider, which along with a potentiometer going to a comparator can form an adjustable light level trigger,
That ouput would go to a transistor to drive the relay that the headlights are normally powered by
Honestly the hardest part is getting to the wires of the relay nicely and correctly powering it

The other post is probably a better idea as the comparator will probably cause it to flicker when it gets close to the threshold
the schmitt trigger is not as sensitive

I fixed the picture, you have to click on it and then you can zoom in if needed. How would I go about making one of these then using what you guys suggested. I would be getting my photocell off of ebay out of a similar vehicle. Here's what it looks like http://www.ebay.com/itm/AUTOMATIC-HEAD-LIGHT-LAMP-SENTINAL-SENSOR-25713063-/230707219783?pt=Motors_Car_Truck_Parts_Accessories&vxp=mtr&hash=item35b738cd47, it has a smoked lens to prevent any accidental shut offs.

I wish to do a similar project, however, I can’t figure out the programming.
The Arduino will be powered on all the time.
My photocell outputs 200 maximum with the current resistor. I have already run a Serial.println sketch to map the appropriate light level values.

When the car turns on, it will send a regulated signal to the Arduino pin 2. This will simply tell the Arduino that the car is on.

—When the sun is setting—
When the ambient light reaches a value of <20, the Arduino will activate the relay to turn on the RUNNING lights.
When the ambient light reaches a value of <10, the Arduino will activate the relay to turn on the HEADLIGHTS.

—When the sun is rising—
When the ambient light reaches a value of >20, the Arduino will deactivate the relay to turn off the HEADLIGHTS.
When the ambient light reaches a value of >30, the Arduino will deactivate the relay to turn off the RUNNING lights.

When the car turns off, input pin 2 will lose it’s signal.
If the ambient light is <10, the Arduino will leave the RUNNING and HEADLIGHTS on for the value of a potentiometer multiplied by 59.
(Potentiometer Maximum = 1020ms (1.2 seconds) x 59 = 60,180ms (60.180 seconds)
When the time set by the multiplied potentiometer value has passed, the Arduino will turn off the RUNNING and HEADLIGHTS and ignore the photocell. The Arduino will then flash an LED for 10ms (0.1 Second) every 2000ms (2 Seconds). It will continue to do this until power is restored to Pin 2.

I purposely had the running lights turn on at 20 and off at 30 for a couple reasons. Once their on, they won’t turn off unless the ambient light gets significantly brighter. Same thing with the headlights. They turn on at 10 but won’t turn off unless the light reaches 20. This also eliminates the problem with the lights strobing when the photocell level is on the edge of a specific value.

So far, I got the circuit to turn LED’s (Standing in for the running and headlights) on and off very reliably, but I also want the addition of having the headlights staying on for up to 60 seconds after I turn the car off so I can see the stairs to my apartment, and fake having an alarm.

In addition, I also know how to read the state of a switch and a potentiometer, and I know how to make an LED blink for 10ms every 2000 ms.
I can’t figure out how to make all these elements to work together in the order I want them to.

If anyone can help me with the code for this, I would greatly appreciate it.

That doesn't sound too hard,
do you have any code so far?

Yes. I have this:

int led1 = 3;
int led2 = 4;

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
int sensorValue = analogRead(A7)/4; //Read the analog sensor, then devide it’s value by 4 to reduce it’s maximum reading form 1023 to 255
Serial.println(sensorValue); // Send the sensorValue to the Serial Monitor when available
delay(100); // delay in between reads for stability
if (sensorValue < 20) { // If the sensorValue is 20 or less
digitalWrite(led1, HIGH);} // turn on LED
if (sensorValue > 30) { // If the sensorValue is 30 or higher
digitalWrite(led1, LOW);} // turn off LED
if (sensorValue < 10) { // If the sensorValue is 10 or less
digitalWrite(led2, HIGH);} // turn on LED2
if (sensorValue > 20) { // If the sensorValue is 20 or higher
digitalWrite(led2, LOW);} // turn off LED2
// By leaving a value of 10 between on and off, it prevents excessive switching on and off when the value is bordering the threshold.
}

Here is a starting point.

const long headlightDelay = 5000;   // 5 Seconds (Adjust as needed)

const int LDR = A0;                 // Light resistor
const int ignition = 2;             // Ignition switch HIGH==On LOW==Off
const int strobe = 13;              // Alarm strobe LED
const int sideLights = 3;           // Sidelight LED
const int headLights = 4;           // Headlight LED

int ldrAverage = 0;                 // Rolling average of LDR value to smooth out readings
long headlightOnTime = 0;           // Time headlights were turned on
boolean sidelightState = false;     // Flag, state of sidelights
boolean headlightState = false;     // Flag, state of headlights

void setup() {
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    pinMode(sideLights, OUTPUT);
    pinMode(headLights, OUTPUT);
    pinMode(strobe, OUTPUT);
    pinMode(ignition, INPUT_PULLUP);
    ldrAverage = analogRead(LDR);       // Prime the average
}

// the loop routine runs over and over again forever:
void loop() {
Serial.println("Ignition on"); 
    while (digitalRead(ignition) == HIGH){          // Only operate lights if ignition is on
        ldrAverage = (ldrAverage + analogRead(LDR))/2;          //Read the analog sensor
//Serial.print("Light Level:"); 
//Serial.println(ldrAverage);   // Send the ldrAverage to the Serial Monitor when available
        delay(50);                                  // delay in between reads for stability
        if ((ldrAverage < 80) && (sidelightState == false)) {    // If the ldrAverage is 20 or less
            digitalWrite(sideLights, HIGH);         // turn on LED
            sidelightState = true;
            Serial.println("Sidelights On");
        }
        if ((ldrAverage > 120) && (sidelightState == true)) {    // If the ldrAverage is 30 or higher
            digitalWrite(sideLights, LOW);          // turn off LED
            sidelightState = false;
            Serial.println("Sidelights Off");
        }
        if ((ldrAverage < 40) && (headlightState == false)) {    // If the ldrAverage is 10 or less
            digitalWrite(headLights, HIGH);         // turn on headLights
            headlightState = true;
            headlightOnTime = millis();             // Get time lights were turned on
            Serial.println("Headlights On");
        }
        if ((ldrAverage > 80) && (headlightState == true)) {     // If the ldrAverage is 20 or higher
//long tmp = millis();
//Serial.println(headlightOnTime);
//Serial.println(tmp);
            if ((millis() - headlightOnTime) > headlightDelay){
                digitalWrite(headLights, LOW);      // turn off headLights
                headlightState = false;
                Serial.println("Headlights Off");
            }
        }
    }
    headlightOnTime = millis();                     // Get time ignition was turned off
    // Ignition is off
Serial.println("Ignition off"); 
    while (digitalRead(ignition) == LOW){           // Only operate if ignition is off
        if (headlightState == true) {               // If headlights on
            if ((millis() - headlightOnTime) > headlightDelay){
                digitalWrite(headLights, LOW);      // turn off headLights
                headlightState = false;
                Serial.println("Headlights Off");
                digitalWrite(sideLights, LOW);      // turn off LED
                sidelightState = false;
                Serial.println("Sidelights Off");
            }
        }
        digitalWrite(strobe, HIGH);                 // turn on alarm strobe
        delay(20);
        digitalWrite(strobe, LOW);                  // turn off alarm strobe
        delay(1980);
    }
    ldrAverage = analogRead(LDR);                   // Re-prime the average

}

Holy Crap! You're awesome! Thank you.
Now I will load this and analyze what you did here so I can figure out how to do similar projects in the future.
If I do build this, then I will be sure to provide a link here to the schematic.

Thank you.

for the sensor i would do it in 2 parts

an LDR in the dash to sense day and night and do an avg reading so streetlight does not cause false readings…

and then a photocell in a tube aimed at the ongoing traffic… the tube because it then will only see what is coming directly from the point you aim it at. only dim when the light level changes fast…

dont know if it would work but its an idea