I am trying to control multiple (12) twincoil solenoids (the type in n-guage railway turnouts (minitrix)). I would be operating max 4 at any one time.
What is the best way to use an arduino UNO to achieve this? I have set up a test project to operate 2 solenoids using MOSFETs (I have 2 types IRF520 and IRF830). The test seems to work ok.
Instructions that came with them state that they should be used 14-16V AC, but have read online that 16V DC also works. In my test I can get a single one to operate at 12V DC, but 2 or more wont work at this voltage. I need a bigger power pack .
Is 16V AC or 16V DC be better suited to my project. Does it matter? I am also concerned about about whether my circuit can handle either. Are Mosfets the best way to turn on/ off 16V or would relay's or something else be better (I have started with Mosfets as they are smaller)-
I am looking for some guidance to point me in the right direction.
Below is the Sketch I have used.
/*
Turnout version 0,1
Test with 4 buttons controlling 2 turnouts
*/
const int switchPin1 = 2; //turnout switch buttons
const int switchPin2 = 3;
const int switchPin3 = 4;
const int switchPin4 = 5;
const int turnOut1a = 11; //turnout 1 straight track
const int turnOut1b = 10; // turnout 1 branch track (note that there can be either right or left branches)
const int turnOut2a =9;
const int turnOut2b = 8;
int switchState1 = 0; //Sets switch to off
int switchState2 = 0;
int switchState3 = 0; //Sets switch to off
int switchState4 = 0;
int turnOutState1 = 0;
int turnOutState2 = 0;// TurnOut is set to Straight (1= turnOut set to branch)
void setup() {
Serial.begin(9600); //opens serial port
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin3, INPUT);
pinMode(turnOut1a, OUTPUT);
pinMode(turnOut1b, OUTPUT);
pinMode(turnOut2a, OUTPUT);
pinMode(turnOut2b, OUTPUT);
}
void loop() {
switchState1 = digitalRead(switchPin1);
if (switchState1 == HIGH) {
digitalWrite(turnOut1a, HIGH);
delay(150);
digitalWrite(turnOut1a, LOW);
digitalWrite(turnOutState1, LOW);
Serial.print(turnOutState1);
}
else {
digitalWrite(turnOut1a, LOW);
}
switchState2 = digitalRead(switchPin2);
if (switchState2 == HIGH) {
digitalWrite(turnOut1b, HIGH);
delay(150);
digitalWrite(turnOut1b, LOW);
digitalWrite(turnOutState1, HIGH);
Serial.print(turnOutState1);
}
else {
digitalWrite(turnOut1b, LOW);
}
switchState3 = digitalRead(switchPin3);
if (switchState3 == HIGH) {
digitalWrite(turnOut2a, HIGH);
delay(150);
digitalWrite(turnOut2a, LOW);
digitalWrite(turnOutState2, LOW);
Serial.print(turnOutState2);
}
else {
digitalWrite(turnOut2a, LOW);
}
switchState4 = digitalRead(switchPin4);
if (switchState4 == HIGH) {
digitalWrite(turnOut2b, HIGH);
delay(150);
digitalWrite(turnOut2b, LOW);
digitalWrite(turnOutState2, HIGH);
Serial.print(turnOutState2);
}
else {
digitalWrite(turnOut2b, LOW);
}
{
//Serial.println(" = TurnOut1a"); // Name of turnout
//Serial.print(turnOutState); //print turnout straight (0) or branch (1)
//Serial.println(" = SwitchState1"); // name of turnout
//Serial.print(switchState1);
//Serial.println(" = SwitchState2"); // name of turnout
//Serial.print(switchState2);
}
}