Introduction: RF Joystick for Arduino

Picture of RF Joystick for Arduino

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

Picture of 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

Picture of 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:

Comments

Howar1 (author)2017-10-01

Hello, can i use arduino mini pro + arduino UNO for this project instead of 2x arduino UNO?

Thanks <3

ROBOTSMACKER (author)2017-08-04

What is the change if we want to use a pot metre instead of a joystick.

I wanted to send values for each value from the pot metre.

JesseA48 (author)2017-06-27

How can i change the pin of the receiver/transmitter?

AlbertoP39 (author)2017-03-28

big project
how can I add 3 buttons fire?
Thanks, it's very kind of you

b

MohamedE146 (author)2017-03-22

nice tutorial , thank you,..... but i am getting this error msg when compiling;

Arduino: 1.6.12 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Mohamed\AppData\Local\Temp\ccWjAw5T.ltrans0.ltrans.o: In function `main':

ccWjAw5T.ltrans0.o:(.text.startup+0x2e6): undefined reference to `RCSwitch::send(unsigned long, unsigned int)'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino/Genuino Uno.

option enabled in File -> Preferences.

gabontz (author)2016-09-10

How can be the code of the transmitter implemented to use for example 4 simple switches?

pscheimann (author)2015-12-29

indeed, nice and simple. Good work.
Is there any way we can improve the transmission speed so that the changes are taking place faster?

ronakpatel5391 (author)2015-07-25

please help me i got this error"Arduino: 1.6.1 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

sketch_jul25a.ino:3:14: error: 'VALUE' was not declared in this scope

sketch_jul25a.ino:4:14: error: 'VALUE' was not declared in this scope

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

ronakpatel5391, the error you're getting is because you need to find the horizontal and vertical "Dead Zone" values of your joystick and replace "VALUE" for each one with it. I hope this helps!

tomatoskins (author)2015-03-19

What a great project!

CCCSuffolk (author)tomatoskins2015-03-19

Thanks, it was our first one :)

fcfelix (author)2015-03-19

Very nice, will definitely come in handy some times.

Did you think about switching the Arduinos with core Atmega328 chips? Could that be done?

fcfelix (author)fcfelix2015-03-19

Just found one. With Attiny.

https://www.instructables.com/id/Receiving-and-send...

Mix both instructables and and you have a very nice cheap solution for more projects.

CCCSuffolk (author)fcfelix2015-03-19

Good stuff, we tend to use "off the shelf" parts as we teach 11 to 16-year-olds, but those would be good for the older students.

About This Instructable

13,433views

68favorites

License:

Bio: 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 ... More »
Add instructable to: