RC Switch

I would like to do a rc switch for my airmodels. I need to control a relay with the Arduino by an RC radio, like Futaba. It’s very usefull this switches. To switch cameras, lights, smoke and other devices.

I think I can connect a circuit like this one and then control it with Arduino and PWM income from RC Receiver.

I found this code on the Internet about receiving PWM with Arduino. What’s the next step to control a relay?

This code is for remote control the arduino with a conventional RC controller, like futaba, etc. I connected the central circuit of my RC helicopter to arduino (were suppose to be connected the servos) to digital pin 7 for axis “X” and digital pin 8 for axis “Y”.

int xPin = 7; //Pin IN of servo Axis X
int yPin = 8; //Pin IN of servo Axis Y
int timeX = 0; //Show the readed control position
int timeY = 0;
long lastPulseX = 0; // the time in milliseconds of the last pulse
long lastPulseY = 0;
long mstime = 0; // reads the time in miliseconds
long hptime = 0; // Reads the time in Microseconds

extern volatile unsigned long timer0_overflow_count;

unsigned long hpticks (void)
{
return (timer0_overflow_count << 8) + TCNT0;
}

void setup() {
Serial.begin(9600);
pinMode(xPin, INPUT); //The R/C signal pin as an input pin
pinMode(yPin, INPUT);
}
void loop() {

if(millis() - lastPulseX >= 5) //Read Axis X every 5 milis
{
while(!digitalRead(xPin) == HIGH) //Waits for signal coming from axis X
{
continue;
}
mstime = millis();
hptime = hpticks()*4; //When the signal arrives, here we going to record the start time of reciving
while(!digitalRead(xPin) == LOW){
continue;
}
mstime = millis();
timeX = (hpticks()*4) - hptime; //Here takes the diferences of the Start and finish times, the result is the signal from RC.
Serial.println(timeX); //Print the results
Serial.print ("\t");
hptime = 0;
lastPulseX = millis();
}

///////////////////////////The same, but now for axis Y

if(millis() - lastPulseY >= 5)
{
while(!digitalRead(yPin) == HIGH){
continue;
}
mstime = millis();
hptime = hpticks()*4;
while(!digitalRead(yPin) == LOW){
continue;
}
mstime = millis();
timeY = (hpticks()*4) - hptime;
Serial.print(timeY);
Serial.print ("\t");
hptime = 0;
lastPulseY = millis();
}
}

I am not sure what you want to do.

To get that code to work, you would connect pins 7 and 8 to two channels from your RC receiver. Run the sketch and view the output on the serial monitor to see how the value of timeX and timeY change as you control the RC transmitter. You can then add some code to detect the appropriate levels of these variables to drive a relay using a transistor.

But its not clear what you want the arduino to do that you can't do with that circuit connected to the receiver output.

I want Arduino detect the signal and then send a signal to one output connected to that sub circuit.

For example, Futaba servos signal centered are 1,500ms, low position 1,000ms and high 2,000ms.

When arduino detects less that 1,250ms switch the relay, andmore that 1,750ms switch the relay.

If you monitor the time variables as mentioned in reply#1 you can use this to switch the transistor.

For example:
if(timeX <1250)
digitalWrite(relayPin(HIGH);
else
digitalWrite(relayPin(LOW);

But I was wondering why you didn’t jut use the circuit you posted in your original post.

If you want the Arduino to monitor all channels so it can control the aircraft as well as switch a relay then I would suggest different code for this.

I published a library for decoding all channels from a radio control receiver here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228137503

This is probably more appropriate for your application then the code in the first post. To use this you connect the composit signal from all channels into a single arduino pin. What receiver do you have?

Thank you. That's What I need.

I need somethint like this: http://www.robotmarketplace.com/marketplace_teamdelta_rc.html

With that code I can do that.

My receiver is Futaba. I dont have it right now. I know where is the pin from PWM signal. Because I'm working with Paparazzi UAV autopilot.

I am confused because if you are using an Arduino onboard and you are decoding the receiver output then you don’t need any of the devices in that link, you can drive a relay or solenoid using an arduino digital output ( see http://www.arduino.cc/playground/uploads/Learning/solenoid_driver.pdf)

Ok. I will use that schematic for a relay instead of a solenoide. I use the same code that you mention, right? Thank you, this is all new for me.

Ok. I will use that schematic for a relay instead of a solenoide. I use the same code that you mention, right? Thank you, this is all new for me.

The advantage of the code in your first post is that it does not need the composite PPM signal, it can be connected to individual channel outputs. The advantage of the code linked in reply#3 is that it decodes all channels in the background so the Arduino sketch does not have to wait for any pulses.

Either way you would check if the pulse width was above or below your desired threshold to determine if you turned the relay on or off.

Ok. Now I understand better this. I will do like you said. Read all channels. I have my rc receiver hacked for the paparazzi autopilot. It will be good also for arduino. One more time, thanks a lot.