Controlling outputs in sequence with delay

Hi everyone,

I am doing a project for installing both rear and front view camera on my car. The car's stereo has an input pin that when pulled up ( car put in Reverse gear) , shows the AV input. so i thought i could use a sequencer to turn on the front camera when the key is in ACC (When i get in the car to start it) and the front camera's picture is shown for 10 seconds after that it switches off.

And when i put the car in the Reverse mode, it should always switch to the rear camera and when removed from reverse, open the front camera for again 10 seconds.

So here are my outputs:

Front camera AV out
Front camera power

Rear camera Av out

Here are my inputs:

Camera AV in on stereo
Camera AV signal (must be pulled up)
Car's reverse signal ( Pulled up when in reverse)
Car's ACC signal (Pulled up when key in ACC position)

And where are your questions?

If you don't have special electronic skills, I suggest a relay (or two) for switching between the front and rear camera signals.

The sketch below switches every 10 second on an output pin (3).
This signal should be used to control a relay - Google images for hardware diagram.

When the reverse signal is detected, it switches to the rear camera and blocks as long as the signal exists.

To get it working you might need to swap HIGH and LOW in some places, but that is left as an exercise.

//
//    FILE: carCameraSwitch.ino
//  AUTHOR: rob.tillaart
// VERSION: 0.0.1
// PURPOSE: demo
//
// Released to the public domain
//

const int reversePin = 2;
const int cameraPin = 3;

uint32_t lastCameraSwitch = 0;

#define CAMERA_FRONT HIGH
#define CAMERA_REAR  LOW


void setup()
{
  Serial.begin(9600);   // debugging purpose
  Serial.println(__FILE__);

  pinMode(reversePin, INPUT);
  pinMode(overridePin, INPUT);
  pinMode(cameraPin, OUTPUT);

  // quick check if both cameras work
  digitalWrite(cameraPin, CAMERA_FRONT);
  delay(2000);
  digitalWrite(cameraPin, CAMERA_REAR);
  delay(2000);
  digitalWrite(cameraPin, CAMERA_FRONT);
}


void loop()
{
  while (digitalRead(reversePin) == HIGH)
  {
    digitalWrite(cameraPin, CAMERA_REAR);
    Serial.println("CAMERA_REAR");
  }

  // switch every 10 seconds, not using delay as that blocks
  if (millis() - lastCameraSwitch > 100000)
  {
    lastCameraSwitch = millis();
    Serial.print(lastCameraSwitch);
    Serial.print("\t");
    if (digitalRead(cameraPin) == CAMERA_REAR )
    {
      digitalWrite(cameraPin, CAMERA_FRONT);
      Serial.println("CAMERA_FRONT");
    }
    else
    {
      digitalWrite(cameraPin, CAMERA_REAR);
      Serial.println("CAMERA_REAR");
    }
  }
}

DrDiettrich:
And where are your questions?

If you don't have special electronic skills, I suggest a relay (or two) for switching between the front and rear camera signals.

Yes i thought about using relays to control the AV video signal and the 12v trigger. I am need of help for the code :frowning:

DrDiettrich:
And where are your questions?

If you don't have special electronic skills, I suggest a relay (or two) for switching between the front and rear camera signals.

Thank you very much for the code, i beleive override pin should be an input. i tried the code with a few different variations but i cannot seem to get it to work.

Can you please check my crude drawing and again i need it to turn on both relays when powered on, wait for 15 seconds then turn both relays off.

then anytime a positive voltage is detected at R, it should only turn the trigger relay as long as voltage is present at R. (As reverse camera signal is normally connected/i]" to the AV in)
Right after R is not positive anymore, it should turn on both relays for 15 seconds then turn both relays off.
The idea is when i start the car arduino is powered and it turns on the front camera ( To get out of the parking)
Anytime in Reverse, it would always switch the reverse camera
and when removed from reverse (when one is parking) it would switch to front view for 10 seconds.
I think everyone should put this system in their car, considering car cameras now cost nearly $6 :smiley:



You probably don't need a relay to trigger the AV input. Just a couple of transistors. It might be worth experimenting to see of a 5V signal is enough to trigger it. But if you have already bought a dual relay module/shield, use that as you plan shows.

To feed a 12V signal into an Arduino input, you will need to use a voltage divider for each 12V signal. This sounds fancy, but all it is is a pair of resistors, for example 3K3 and 6K8 (remembering that the "12V" in a car can be 14V when the engine is running).

Hi everyone,

I am doing a project for installing both rear and front view camera on my car. The car's stereo has an input pin that when pulled up ( car put in Reverse gear) , shows the AV input.

please check my crude drawing and again when arduino is powered on i need it to turn on both relays, wait for 15 seconds then turn both relays off.

then anytime a positive voltage is detected at R (through a voltage divider), it should only turn the trigger relay as long as voltage is present at R. (As reverse camera signal is normally connected/i]" to the AV in)

Right after R is not positive anymore, it should turn on both relays for 15 seconds then turn both relays off.

The idea is when i start the car arduino is powered and it turns on the front camera ( To get out of the parking)

Anytime in Reverse, it would always switch the reverse camera
and when removed from reverse (when one is parking) it would switch to front view for 10 seconds.

I think everyone should put this system in their car, considering car cameras now cost nearly $6 :smiley: