Introduction: RF Joystick for Arduino

About: Creative Computing Club provides technology based learning opportunities for all ages and abilities to participants in Suffolk. We deliver courses on computer programming, video game design, hardware program…

This is a very simple Instructable which will help you learn how to wirelessly control a second Arduino and the components attached to it. This could be used to control motors on a car, servos on a robotic arm or propellars on a drone.

To complete this example you will need:

2 X Arduino Unos

2 X USB Cables for Arduinos

1 X Dual Axis Analogue Joystick

An assortment of male to male, male to female and female to female jumper leads.

4 X LED's

4 X 200Ω Resitors

1 X 433mhz Transmitter

1 X 433mhz Receiver

Arduino Software

RCSwitch Arduino Library

Setup

Firstly download and install the the Arduino Software as per developer instructions for your operating system, secondly download and unzip the RCSwitch Arduino Library. Place the folder inside the Arduino/libraries folder located in your Documents folder. This will allow Arduino to access it.

Step 1: Transmitter

This sketch will send either the number 1,2,3,4 or 5 depending on the position of the joystick and it will only send

a number if it is different from the previous number it read from the joystick. It will transmit it using "Digital Pin 10" and using the command "mySwitch.send(pos, 23);". The "23" is a number unimportant in these examples however they could be used to determine which signal is going to which receiver if there was more than one.

RF Controlled Joystick

Before this example will work you will need to work out your joysticks "dead zone", these are the horizontal and vertical values of the joystick of when it is not in use. In the code replace the "VALUE" with 0, run the code and then selct tools from the menu in the Arduino software and select Serial Monitor, this will provide you with the two values. Stop the program and replace the two 0's with those values.

Hardware Setup Transmitter

In this example we need four "female to male" jumper leads the first goes from "GND" to "GND" the second goes from "VCC" to "5v". The third "HOZ" to "AO" and finally "VER" to "A1". Now to connect the transmitter. Firstly use a "female to male" jumper lead to connect the "GND" to "GND" on the lefthand side of the board next to "Digital Pin 13". Secondly using a "Female to Female" jumper lead connecting the "VCC" to the top left "5v" header pin. Finally use a "female to male" jumper lead to connect the "ATAD/DATA" pin to "Digital Pin 10". You are now set up to send some data wirelessly.

Arduino Code Transmitter Code

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int hozdead= VALUE ;
int verdead= VALUE ;
int pos = 0;
int oldpos=100;
int val = 0;
int val2 = 0;
void setup() {
    Serial.begin(9600);
    mySwitch.enableTransmit(10);
}
void loop() {
    //Read JoyStick
    val = analogRead(0);
    val2 = analogRead(1);
    Serial.println(val);
    Serial.println(val2);
    //UP 1
    if (val> verdead+30){pos=1; Serial.println(pos);}
    //DOWN 2
    if (val< verdead-30){pos=2; Serial.println(pos);}
    //RIGHT 3
    if (val2> hozdead+30){pos=4; Serial.println(pos);}
    //LEFT 4
    if (val2< hozdead-30){pos=3; Serial.println(pos);}
    //DEAD ZONE 5
    if (val>verdead-20 && val< verdead+20 && val2>hozdead-20 && val2< hozdead+20)
    {
         pos=5; Serial.println(pos);
    }
    mySwitch.send(pos, 23);
}

Now let's make a receiver!

Step 2: Receiver

By now we should have the transmitter setup and transmitting 1,2,3,4 and 5 depending on the position of the

joystick. Now on this the Receiver Arduino we are going to wait for a signal, read it and decide which light to turn on or off.

Hardware Setup Receiver


Now to connect the receiver. Firstly use a "female to male" jumper lead to connect the "GND" to "GND" on the righthand side of the board. Secondly use a "female to male" jumper lead to connect the "DOUT" pin to "Digital Pin 2". Finally using a "Female to Female" jumper lead connecting the "VCC" to the top left "5v" header pin.

Using a "male to male" jumper lead Digital Pin 4" goes to a "220Ω" and then on to a "LED". Using a "male to male" jumper lead "Digital Pin 5" goes to a "220Ω" and then on to a "LED". Using a "male to male" jumper lead "Digital Pin 7" goes to a "220Ω" and then on to a "LED". Using a "male to male" jumper lead "Digital Pin 9" goes to a "220Ω" and then on to a "LED". These four "LED's" are then returned to "GND" using Using a "male to male" jumper leads.

You are now set up to receive some data wirelessly.

Arduino Code Receiver

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int pos = 0;
void setup() {
    Serial.begin(9600);
    pinMode(4,OUTPUT);
    pinMode(5,OUTPUT);
    pinMode(8,OUTPUT);
    pinMode(9,OUTPUT); 
    mySwitch.enableReceive(0);
}
void loop() {
    if (mySwitch.available()) {
        int value = mySwitch.getReceivedValue();
        if (value > 0) {
            if (mySwitch.getReceivedValue()==1){digitalWrite(4,HIGH);}
            else if (mySwitch.getReceivedValue()==2){digitalWrite(5,HIGH);}
            else if (mySwitch.getReceivedValue()==3){digitalWrite(8,HIGH);}
            else if (mySwitch.getReceivedValue()==4){digitalWrite(9,HIGH);}
            else if (mySwitch.getReceivedValue()==5){
                digitalWrite(4,LOW);
                digitalWrite(5,LOW);
                digitalWrite(8,LOW);
                digitalWrite(9,LOW);
            }
        }
        mySwitch.resetAvailable();
    }
}


And there you have it you should now be able to control the LEDs via a joystick on the first Arduino.

Hope you like it, please leave comments if you can think of any improvements or you use it in any of your projects.

Creative Computing Club

www.creativecomputingclub.com

Step 3: