I made an RC controller for a drone airplane project. The controller sends pre-flight instructions and also has two joysticks that overrides the aircraft instructions if I need to take control. I used a 433 mhz transmitter and receiver. It works well.
Here is some test code I made while testing transmission and receiving the joystick pot values. This just reads 3 pots of the joystick and transmits it to the receiver. The receiver reads the signal and converts it back to 3 pot values that can be used to control servos. I used a Mega in the transmitter and a micro in the receiver. I hope this helps.
Here is the transmitter code:
// Modified from VirtualWireexample by Mike McCauley (mikem@open.com.au)
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// Modified for Obeien Project. To be used on an Arduino Mega
// with joystick for rudder and elevator signal, and pot for
// motor signal. May be merged with Touch Screen to send
// pre flight commands.
//
//
//
// Mod: Three Sensor input (2 joysticks) sent to control PWS on reciever
// Set up for MEGA
// Circuit: Transmitter input on pin 24, LED on pin 24 (w/330 ohm resistor),
// pot 1 (u/d) output pin to pin A8, pot 2 (r/l) output pin to pin A9, pot3 (u/d) on pin A10.
// Mod by: Dave Gundlach, June 2013
#include <VirtualWire.h>
int sensor1Data; // Data varable for pot 1
int sensor2Data; // Data varable for pot 2
int sensor3Data; // Data varable for pot 3
char sensor1Char[4]; // Charactor array for pot 1
char sensor2Char[4]; // Charactor array for pot 2
char sensor3Char[4]; // Charactor array for pot 3
char sensor123Char[10]; // Combined array for pot 1, 2 & 3
void setup(){
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode(24, OUTPUT); // LED output
pinMode(A8, INPUT); // JS1 input (pot 1 u/d)
pinMode(A9, INPUT); // JS1 input (pot 2 r/l)
pinMode(A10, INPUT); // JS2 input (pot 3 u/d)
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_set_tx_pin(22); // pin 24 is used to transmit data
}
void loop(){
sensor1Data= analogRead(A8); // read JS1 (pot 1)
sensor2Data= analogRead(A9); // read JS1 (pot 2)
sensor3Data= analogRead(A10); // read JS2 (pot 3)
// Note: Needed values from 0-255, added 100 to values so there are
// always 3 charactors
sensor1Data = map(sensor1Data, 0, 1023, 100, 279); // map sensor output
sensor2Data = map(sensor2Data, 0, 1023, 100, 279); // map sensor output
sensor3Data = map(sensor3Data, 0, 1023, 100, 279); // map sensor output
itoa(sensor1Data, sensor1Char, 10); // convert sensor data to char
itoa(sensor2Data, sensor2Char, 10); // convert sensor data to char
itoa(sensor3Data, sensor3Char, 10); // convert sensor data to char
for (int i=0; i<3; i++){
sensor123Char[i] = sensor1Char[i]; // put sensor 1 caractors in
}
for (int i=0; i<3; i++){
sensor123Char[i+3] = sensor2Char[i]; // put sensor 2 caractors in
}
for (int i=0; i<3; i++){
sensor123Char[i+6] = sensor3Char[i]; // put sensor 3 caractors in
}
sensor123Char[9] = '\0';
Serial.println(sensor123Char); // debug check
digitalWrite(24, HIGH); // Flash an LED to show transmitting
vw_send((uint8_t *)sensor123Char, strlen(sensor123Char));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(24, LOW); // turn off LED
//delay(10); // small delay for smooth control
}
Here is the receiver code:
// modified from example sketch for VirtualWire by Mike McCauley (mikem@open.com.au)
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// To be used for Obiein Project. This version was ran on the MEGA but will
// needed to be adapted for the Micro. This Micro will be a dedicated processor
// for communications only and will be connected to flight control processor by
// serial connection
//
//
//
// MOD: Three Sensor input from transmitter (two joysticks) to control the servos on a second micro.
// This uses the Arduino micro
// Circuit: Reciever output to Pin 11, Serial output to the second micro on Tx pin 1 of the micro.
// Mod by Dave Gundlach, June 2013
#include <VirtualWire.h>
long timerLED; // timer for LED on
int sensor1Data; // Data variable for pot 1 (joy1 up/dn)
int sensor2Data; // Data variable for pot 2 (joy1 l/r)
int sensor3Data; // Data variable for pot 3 (joy2 up/dn)
char sensor1Char[4]; // Charactor array for pot 1
char sensor2Char[4]; // Charactor array for pot 2
char sensor3Char[4]; // Charactor array for pot 3
void setup(){
Serial1.begin(115200);
pinMode(13, OUTPUT); // Recieve LED
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (millis() >= timerLED){ // check if LED timer has expired
digitalWrite(13, LOW); // turn LED off
}
if (vw_get_message(buf, &buflen)){ // Non-blocking
int i;
digitalWrite(13, HIGH); // Flash a light to show received good message
timerLED = millis()+100; // set LED timer
// Message with a good checksum received, dump it.
for (i = 0; i < 3; i++){ // convert buffer into char
sensor1Char[i] = char(buf[i]); // pot 1 value
}
// Transmitter added 100 so each value will will always have 3 charactors
sensor1Data = atoi(sensor1Char)-100; // convert to integer and subtract 100
for (i = 0; i < 3; i++){
sensor2Char[i] = char(buf[i+3]); // pot 2 value
}
sensor2Data = atoi(sensor2Char)-100+1000; // convert to integer and subract 100
for (i = 0; i < 3; i++){
sensor3Char[i] = char(buf[i+6]); // pot 3 value
}
sensor3Data = atoi(sensor3Char)-100+2000; // convert to integer and subract 10
Serial1.println(sensor1Data); // send data to serial
Serial1.println(sensor2Data); // send data to serial
Serial1.println(sensor3Data); // send data to serial
for (i=0; i<4; i++){
sensor1Char[i] = 0; // clear array
sensor2Char[i] = 0; // clear array
sensor3Char[i] = 0; // clear array
}
}
}
Here is a picture of my controller:
Dave
