Using an Arduino as an RC reciever module

Hi guys, I've gotten myself stuck with a project that is kinda very important and ran into an obstacle. I'm building a quadcopter(I'm posting in Robotics because it seemd appropriate) and here's the deal. I've made the TX and RX parts using the 433MHz module. The first thing i'm doing is trying to just send a pot value to one of those Hobbyking's KK flight controllers. I've tried sending it signals using the servo library. using servo.write(val) didn't do any good. I've also tried using servo.writeMicroseconds(val) but to no avail. Does anyone have any expirience in this as Google gave no results. Also the input signal from Receiver for the KK board is given as 1520us for 4 channels. If it all works i'll be making a blog for a buildalong for the cheapest UAV ever made.

you post this on my birtday ,, i wil give you my present :astonished:
http://forum.arduino.cc/index.php?topic=257823
you probely want to see this !

Well happy birthday i guess. Anyway I just went and borrowed a remote, but I figured out how it works in the meantime and just decided it isn't as simple as i thought it would be. Mostly because it's hard to get the hardware here :frowning:

Not clear what you're trying to do here. You have an Arduino controller (starting with a simple pot first) and you're trying to figure out how to send the signal via your 433MHz transceiver to another Arduino+transceiver combination sitting on top of a KK board?

Yeah that was the idea, more or less. Basically i didn't want to pay for a big remote control and the reciever and everything. So yes, I wanted to have one arduino board send a pot value to another via the 433MHz and then have that one relay the signal to the KK. It works and all BUT i could never figure out how to send multiple values.

i have a example ,,

// SERIAL INPUT R= ROLL T =TROTTLE P =PITCH A =AUX Y =YAW 
// INPUT WIL BE LIKE THIS TRUE SERIAL ,, 
// R100T200P200A0Y1024 AND 
#include <Servo.h> 
typedef enum {  NONE, GOT_T, GOT_Y, GOT_P, GOT_R,GOT_A} states;


states state = NONE;

unsigned int currentValue;
int trot =0;
int yaw =0;
int pitch =0;
int roll =0;
int aux =0;
int servo =0;
Servo myservo;

void setup ()
{
  Serial.begin (115200);
  state = NONE;
  myservo.attach(7); 
  myservo.write(0);
}  // end of setup
void processT (const unsigned int value)
{
  trot =value; 
} // end of processTHROTTLE

void processY (const unsigned int value)
{
  // do something with YAW 
  Serial.print ("YAW =");
  Serial.println (value);
  yaw =value;
} // end of processYAW

void processP (const unsigned int value)
{
  // do something with PITCH 
  Serial.print ("PITCH = ");
  Serial.println (value);
  pitch =value;  
} // end of processPITCH

void processR (const unsigned int value)
{
  // do something with ROLL
  Serial.print ("ROLL = ");
  Serial.println (value);
  roll =value;  
} // end of processROLL

void processA (const unsigned int value)
{
  // do something with AUX 
  Serial.print ("AUX = ");
  Serial.println (value);
  aux =value;  
} // end of processAUX
void handlePreviousState ()
{
  switch (state)
  {
  case GOT_T:
    processT (currentValue);
    break;
  case GOT_Y:
    processY (currentValue);
    Serial.println ("PPM YAW OUT");
    Serial.println (yaw);
    delay (100);
    break;
  case GOT_P:
    processP (currentValue);
    Serial.println ("PPM PITCH OUT");
    Serial.println (pitch);
    delay (100);
    break;
  case GOT_R:
    processR (currentValue);
    Serial.println ("PPM ROLL OUT");
    Serial.println (roll);
    delay (100);
    break;
  case GOT_A:
    processA (currentValue);
    Serial.println ("PPM AUX OUT");
    Serial.println (aux);
    delay (100);
    break;
  }  // end of switch  

  currentValue = 0; 
}  // end of handlePreviousState

void processIncomingByte (const byte c)
{
  if (isdigit (c))
  {
    currentValue *= 10;
    currentValue += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousState ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'Y':
      state = GOT_Y;
      break;
    case 'P':
      state = GOT_P;
      break;
    case 'T':
      state = GOT_T;
      Serial.println ("WHAHAHAHAHAH");
      break;
    case 'R':
      state = GOT_R;
      break;
    case 'A':
      state = GOT_A;
      break;
    default:
      state = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
} // end of processIncomingByte

void loop ()
{
  if (Serial.available ())
    processIncomingByte (Serial.read ());
    delay (1);
    myservo.write(trot);
  // do other stuff in loop as required
  
}  // end of loop

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