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;
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
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.
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?
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 Arduino Playground - HomePage)
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.