//******************************************************************** //* * //* RV-Project.Com * //* Camera Switch * //* * //* Apr-06-2018 * //* * //* Use With Hardware: * //* MCS-2A Rev A * //* * //* This sketch is intended for use with "bland version" Camera * //* Switch boards. This software is licensed by Creative Commons * //* for non-commercial use only, and must be used within that scope. * //* * //* Sketch works with Atmel ATTiny85-10 and above. ATTiny85 must be * //* set for 8Mhz internal clocking. If default 1Mhz internal clock * //* is used, time delay (on period) will not be accurate. * //* * //* This version of the camera switch is a simple latching version. * //* It is intended to be used with a positive going 12V trigger, as * //* you may find from a brake light circuit. Once triggered, the * //* switch stays on until it times out. The salient characteristics * //* of this switch are; Opto isolated input, surge suppressed input, * //* output, and power supply line voltage, trigger can be momentary * //* or constant (i.e. brake light or tail light), and MOSFET switch * //* camera circuit. * //* * //* While latching a momentary signal is obvous, what is less obvous * //* is the ability to monitor a tail-light circut, for example; why * //* that is even necessary, since 12V is available all of the time * //* from the tail-lights. However, many tail light circuits are * //* overloaded, at least from a voltage drop perspective, so in this * //* instance, the switch acts like a remote relay to ensure 12V is * //* applied to the camera even if the trigger (tail-light) circuit * //* is voltage deficient. Maintaining 12V ensures the camera has * //* sufficient voltage for maximum performance and transmit range. * //* board has the same pim=-outs for pins 1 thru 4. * //* * //* One might wonder why use such a sophisticated setup when a sim- * //* ple relay would work for a tail-light circuit. Well it would. * //* However, remember we have a variable delay that we can dial in, * //* so imagine a scenario where you pull into a rest stop, turn your * //* vehicle off. If a sufficient delay is dialed in, the camera will * //* stay on during the duration of the stop. * //* * //* Or perhaps you are backing your RV in, and that includes turning * //* the vehicle on and off a couple of times. An off delay will pre- * //* vent the camera from shutting off and turning back on each time * //* you start or stop the vehicle. * //* * //* Of course, the primary reason for using this switch is for a * //* a connection to the brake light, or any other momentary trigger, * //* such as backup lights. * //* It's simply flexible enough that it can be used for a tail-light * //* or other constant-on circuit. But also remember this device has * //* voltage surge suppression to protect the camera as well. * //* * //* This is a very simple sketch and useful for a first time project * //* for those wanting to learn the Arduino IDE. * //******************************************************************** unsigned long delayValue=2; //change to 2 (seconds) for testing. int triggerValue = 512; int Trigger = 0; // hardware pin assignments int triggerPin = 2; //physical pin 3 int cameraPin = 3; //physical pin 2 int delayPinA = 0; //physical pin 7 int delayPinB = 1; //physical pin 6 int delayPinC = 2; //physical pin 5 //timer variables unsigned long previousMillis = 0; void setup(){ pinMode(delayPinA,INPUT); pinMode(delayPinB,INPUT); pinMode(delayPinC,INPUT); pinMode(cameraPin,OUTPUT); digitalWrite(cameraPin, LOW); //initialize with camera off. // read the delay switches and set delayValue from 30 minutes to 3 1/2 hours in 30 minute increments. if(digitalRead(delayPinC)==LOW) delayValue = 1800; // 30 minutes in seconds if(digitalRead(delayPinB)==LOW) delayValue = delayValue + 3600; // 1 hour in seconds if(digitalRead(delayPinA)==LOW) delayValue = delayValue + 7200; // 2 hours in seconds delayValue = delayValue * 1000; // convert seconds to mS // since the delay value is read in Setup, the ATTiny85 must be reset before any changes are // made. This can be done via reset pin or power cycling the board. } //********************************* End Setup ******************************** void loop() { unsigned long currentMillis = millis(); Trigger = analogRead(triggerPin); //read the trigger voltage // Note: By default, the camera turns on when the trigger goes above 2.5V as measured at the // output of the OptoIsolator. This is a "positive going trigger". To create a negative trigger // i.e. triggers on ground, change the "<" on the next line to ">". // The default value of 512 for the triggerValue should be sufficient for most purposes, but can // be set to different values. 0 = 0V and 1023 = 5V. When setting this value, measure the voltage // on the ATTiny85 physical pin 3 in both conditions (with input ON and input OFF). Once you // have the ON and OFF voltage threshold, set the sensitivity midway between the two voltages. // Calculate the threshold number by "thresholdset / .00048"; which maps 0-5V to the ADC output of 0-1023 if(Trigger < triggerValue) //set the sensitivity { digitalWrite(cameraPin,HIGH); previousMillis = currentMillis; delay(500); //delay prevents debouncing. } if(currentMillis - previousMillis > delayValue) //if the delay timer exceeds the last trigger event... { digitalWrite(cameraPin,LOW); //turn the output MOSFET off. } } //********************************* End Loop ********************************