Hi there. I was trying to control a motor wireless with a joystick. I've tried a couple tutorials but none work. I would prefer controlling a DC motor, but at this point....I just want to control a motor wireless with a joystick (not vie Bluetooth.)
Could someone please post a link to a video or project that would help me control a servo or dc motor wireless via a joystick? Thanks so much!
Edit: I would appreciate if I could control it with a Joystick shield.
If not BlueTooth, what have you tried using to connect wireless?
Ive used 2 transiever (hc12)
Nearly identical post here. Please do not cross post. Cross posting wastes time.
Ok...but can you please anwser though
@engineer123498
Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.
Here is tested example code for wirelessly transmitting and receiving the values from an analog joystick and one normally open momentary switch using NRF24 radios. The radios are wired according to Robin2's simple rf24 tutorial and uses the example code (modified) from the tutorial as a basis.
Sending code:
// Example from Robin2's simple rf24 tutorial modified by c goulding
// to transmit 2 joystick axes and one switch state.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define JoyX A0 // Joystick X pin connected to A0 on the UNO
#define JoyY A1 // Joystick Y pin connected to A1 on the UNO
int Switchpin = 4; // Digital pin connected to switch output
#define CE_PIN 9
#define CSN_PIN 10
const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
int dataToSend[3];
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
void setup()
{
pinMode(JoyX, INPUT);
pinMode(JoyY, INPUT);
pinMode(Switchpin, INPUT_PULLUP);
digitalWrite(Switchpin, HIGH);
Serial.begin(9600);
Serial.println("SimpleTx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3, 5); // delay, count
radio.openWritingPipe(slaveAddress);
}
//====================
void loop()
{
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis)
{
send();
prevMillis = millis();
}
}
//====================
void send()
{
bool rslt;
dataToSend[0] = (analogRead(JoyX));
dataToSend[1] = (analogRead(JoyY));
dataToSend[2] = (digitalRead(Switchpin));
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
Serial.print("Joy X : ");
Serial.println(dataToSend[0]);
Serial.print("Joy Y : ");
Serial.println(dataToSend[1]);
Serial.print("Button : ");
Serial.println(dataToSend[2]);
Serial.println("========");
if (rslt)
{
Serial.println(" Acknowledge received");
}
else
{
Serial.println(" Tx failed");
}
}
//================
receiving code:
// SimpleRx - the slave or the receiver
// Modified by c. goulding (AKA groundfungus) to receive
// 2 joystick inputs and a switch state
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
# include <Servo.h> // add servo library
#define CE_PIN 9 // **** change for your setup
#define CSN_PIN 10 // **** change for your setup
const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN);
Servo servo; // create instance of servo
int dataReceived[3]; // this must match dataToSend in the TX
bool newData = false;
int xData = 0;
int yData = 0;
boolean switchState = true;
//===========
void setup()
{
Serial.begin(9600);
Serial.println("SimpleRx Starting");
servo.attach(3); // attach servo
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
//=============
void loop()
{
getData();
showData(); // will write to servo here
}
//==============
void getData()
{
if ( radio.available() )
{
radio.read( &dataReceived, sizeof(dataReceived) );
newData = true;
}
}
void showData()
{
if (newData == true)
{
//Serial.print("Data received ");
//Serial.println(dataReceived);
xData = dataReceived[0];
yData = dataReceived[1];
switchState = dataReceived[2];
Serial.print("x pos ");
Serial.print(xData);
Serial.print(" y pos ");
Serial.print(yData);
Serial.print(" switch ");
Serial.println(switchState);
newData = false;
}
}