Thread: Switch question
View Single Post
  #9  
Old 06-13-2021, 12:45 PM
Wombii's Avatar
Wombii Wombii is offline
Green Horn
 
Join Date: Feb 2018
Location: Norway
Posts: 231
Wombii is on a distinguished road
Default Re: Switch question

Very nice servo switch!
I don't know if this helps, but if you wanted to replace it with an arduino nano or something, the following code should in theory emulate it, reading one radio channel and switching two outputs. I just wrote it, but I haven't tested it. You could add a couple more channels.
Note that the arduino can only output signal levels of current, less than 20mA per pin, so you'd need some transistors or relays to actually switch the solenoid and pump. Or hook up small esc's or servo boards (or battleswitches?) to the arduino and control those with the servo library instead of switching the outputs high and low.

Code:
//give the pins human readable names
const byte inputPin = 8;

const byte outputPin_A = 2;
const byte outputPin_B = 3;

void setup() {
  // put your setup code here, to run once:

  //Set output pins to type "output". This means the pins switches between 5v and GND. You need to use external resistors to limit current under 20mA.
  pinMode(outputPin_A,OUTPUT);
  pinMode(outputPin_B,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  int radioSignal = 0;
  radioSignal = pulseIn(inputPin,HIGH);            //Reads the pulsewidth of the input pin


  if (radioSignal > 1700)                          //if switch is up set output A to 5v and B to 0v
  { 
    digitalWrite(outputPin_A,HIGH);
    digitalWrite(outputPin_B,LOW);
  } 
  else if (radioSignal < 1300 && radioSignal > 0)  //if switch is down set output A and B to 5v
  { 
    digitalWrite(outputPin_A,HIGH);
    digitalWrite(outputPin_B,HIGH);
  } 
  else                                             //if switch is centered or no signal set output A and B to 0v
  {
    digitalWrite(outputPin_A,LOW);
    digitalWrite(outputPin_B,LOW); 
  }

}
Reply With Quote