Hello - and thanks in advance for anyone that can assist! I am attempting to develop an ardunio system that receives a 12v external signal and uses that to open / close a linear actuator using a pair of relays. The actuator will open/close the cabinet where the speaker is housed that is supplied by the amplifier.
I am using an Arduno Uno, 2 5v relays and an RGB led and I have a voltage divider circuit that drops the 12v external voltage to 5v. I am pretty happy with the wiring as per the attached diagram, but the programming eludes me and I've spent considerable hours in this regard. Totally new to arduino programming. I'd like a sketch to do this. Amplifier 5v signal is to Pin9, RGB is to Pins 5,6,7 and cathode to Ardunio GND.
Relays are connected to pins 2 and 3
Sketch should do this:
RGB Led is Blue to show power is on to Ardunio (RGB of 0, 0, 255)
On receiving a 5v signal to Pin 9 which means Amplifier is on, RGB led changes to Orange (255, 70, 0) to show Amp on
Arduino then opens one relay and closes the other which activates the linear actuator opening he door, and turns RGB Green for 15 seconds, then returns to its normal 'power on' Orange state (once door closed after 15 seconds)
If 5v signal stops (ie Amplifier power is off) then the second relay opens, and first closes, both for 15 seconds to allow linear actuator to close door. RGB is Red during this.
RGB then returns to its normal 'power on' Orange state.
I have got the RBG working fine, the voltage regulator circuit works fine, I have been playing with some code but just can't get it to work. Perhaps someone could point me in the right direction?
many thanks in advance
// Prior to Setup
int green_light_pin = 5; ;// Green pin connected to digital pin 9
int blue_light_pin = 6; // Blue pin connected to digital pin 10
int red_light_pin = 7; // Red pin connected to digital pin 11
int RelayPinOne = 2; // Pin of relay module one
int RelayPinTwo = 3; // Pin of relay module two
int DenonPin = 9; // Pin of 12V in from Denon Amp trigger down to 5v via resistor system
int AmpState = 0; // variable for recording the Amp status
// Setup
void setup() {
pinMode(green_light_pin, OUTPUT); // sets the greenPin as an output
pinMode(blue_light_pin, OUTPUT); // sets the bluePin as an output
pinMode(red_light_pin, OUTPUT); // sets the redPin as an output
pinMode(DenonPin, INPUT); // sets the Amp pin as input
pinMode(RelayPinOne, OUTPUT); //Set pin connected to relay One as an output
digitalWrite(RelayPinOne, LOW); // Set pin to LOW to turn relay off
pinMode(RelayPinTwo, OUTPUT); //Set pin connected to relay Two as an output
digitalWrite(RelayPinTwo, LOW); // Set pin to LOW to turn relay off
AmpState = digitalRead(DenonPin); // read the state
RGB_color(0, 0, 255); // turn LED Blue to show Arduino power on
delay(2000);
}
// Loop
void loop() {
RGB_color(255, 70, 0); // turn LED Orange
delay(2000);
switch (AmpState) {
case HIGH:
RGB_color(0, 255, 0); // turn LED Green for actuator opening
delay(2000); // delay 2000 milliseconds or 2 seconds
break;
case LOW:
RGB_color(255, 0, 0); // turn LED Red closing
delay(4000);
break;
}
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}