This video demonstrates how to wirelessly control two DC motors using two Arduino Unos. One Arduino acts as a controller with a joystick and XBee module, while the other acts as a receiver with a motor shield and XBee module. The video shows the connections and provides a basic overview of the code used to read joystick input and control the motors wirelessly.
Project#1
DualVNH5019MotorShield library
2 x Arduino Uno
2 x xbee series 1
1 x tumb joystick
1 x 9 Volt power pack
1 x Pololu VNH5019 Motor Shield
2 x 12 Volt dc motors
1 x power supply 12V
GitHub:
https://github.com/Fabiolus2020/ArduinoUno_1Joystick_2Motors_2Xbees_DualVNH5019MotorShield
EasyTrasnfer library:
https://github.com/madsci1016/Arduino-EasyTransfer
Example Sketch:
Pololu VNH5019 user guide
https://www.pololu.com/docs/0J49/all
How to program Xbees
https://learn.sparkfun.com/tutorials/exploring-xbees-and-xctu/all
Demo Video
controller sketch
//created by Fabiolus 2021/01/08 #include <EasyTransfer.h> //create two objects EasyTransfer ETout; const int potpin1 = A0; const int potpin2 = A1; struct SEND_DATA_STRUCTURE { //put your variable definitions here for the data you want to receive //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO int valX; int valY; }; SEND_DATA_STRUCTURE txdata; void setup() { Serial.begin(9600); //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. ETout.begin(details(txdata), &Serial); } void loop() { txdata.valY = analogRead(potpin1); txdata.valX = analogRead(potpin2); ETout.sendData(); }
receiver sketch
//created by Fabiolus 2021/01/08 #include <DualVNH5019MotorShield.h> #include <EasyTransfer.h> DualVNH5019MotorShield md; void stopIfFault() { if (md.getM1Fault()) { Serial.println("M1 fault"); while (1); } if (md.getM2Fault()) { Serial.println("M2 fault"); while (1); } } EasyTransfer ETin; struct RECEIVE_DATA_STRUCTURE { //put your variable definitions here for the data you want to receive //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO int valX; int valY; }; RECEIVE_DATA_STRUCTURE rxdata; void setup() { Serial.begin(9600); md.init(); //initiates default pololu shield pins ETin.begin(details(rxdata), &Serial); } void loop() { for (int i = 0; i < 5; i++) { if (ETin.receiveData()) { rxdata.valY = map(rxdata.valY, 0, 1023, -255, 255); rxdata.valX = map(rxdata.valX, 0, 1023, -255, 255); if (rxdata.valX >= 10) { md.setM1Speed(rxdata.valX); md.setM2Speed(rxdata.valX); stopIfFault(); } else if (rxdata.valX <= -10) { md.setM1Speed(rxdata.valX); md.setM2Speed(rxdata.valX); stopIfFault(); } else if (rxdata.valY <= -10) { md.setM1Speed(rxdata.valY); md.setM2Speed(-rxdata.valY); stopIfFault(); } else if (rxdata.valY >= 10) { md.setM1Speed(-rxdata.valY); md.setM2Speed(rxdata.valY); stopIfFault(); } else { md.setM1Speed(0); md.setM2Speed(0); } } delay(10); } }