element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Projects
  • Products
  • Arduino
  • Arduino Projects
  • More
  • Cancel
Arduino Projects
Blog Maccanum Robot Wireless
  • Blog
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fabiolus
  • Date Created: 25 Jun 2025 1:59 PM Date Created
  • Views 43 views
  • Likes 1 like
  • Comments 0 comments
  • robot
  • Maccanum
  • wireless
Related
Recommended

Maccanum Robot Wireless

fabiolus
fabiolus
25 Jun 2025

project:

https://github.com/Fabiolus2020/MaccanumRobotWireless

video demo:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

controller sketch

//Fabiolus 2021/07/23

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 myRadio(8, 9); // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

//data being sent to the receiver, joystick position, pot values and button count.
struct package
{
  int joyposX;
  int joyposY;
  int potValue;
  int stateNum;
  int SideWayRightState;
  int SideWayLeftState;
  int ForwardRightState;
  int ForwardLeftState;
  int BackwardRightState;
  int BackwardLeftState;
};


//define object for wieless communication
typedef struct package Package;
Package data;

// Define Joystick Connections
#define joyY A0
#define joyX A1

// Define Joystick Values - Start at 512 (middle position) this might change depending on batteries and motor type.
int joyposX = 512;
int joyposY = 512;
//int modeCount;

//defining joystick button followed by declaring variables and build mechanical state machine to keep count of joystick and have 3 modes
const int buttonPin  = 7;
int buttonState      = 0;     // current state of the button
int lastButtonState  = 0;     // previous state of the button
int modeState        = 0;     // remember current led state
int stateNum;

//LED pin only two modes for this robot
#define ledModeStatusCount A3


// Set initial motor speed at 0
int motorspeedModeOne = 0;
int motorspeedModeTwo = 0;

// Set button for diagonal mode drive, upon pushing button specific direction is iniated.
#define buttonSideWayRight 0
#define buttonSideWayLeft 6
#define buttonForwardRight 2
#define buttonForwardLeft 3
#define buttonBackwardRight 4
#define buttonBackwardLeft 5

int SideWayRightState;
int SideWayLeftState;
int ForwardRightState;
int ForwardLeftState;
int BackwardRightState;
int BackwardLeftState;


//Define potentiometer
#define Pot A2
int potValue = 0;

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  //define Radio as object
  myRadio.begin();

  //set the address
  myRadio.openWritingPipe(address);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS );
  myRadio.setChannel(115);

  //Set module as transmitter
  myRadio.stopListening();

  pinMode(ledModeStatusCount, OUTPUT);
  digitalWrite(ledModeStatusCount, LOW);
  //joystick select/push button
  pinMode(buttonPin, INPUT_PULLUP);  // initialize the button pin as a input

  pinMode(buttonSideWayRight, INPUT_PULLUP);
  pinMode(buttonSideWayLeft, INPUT_PULLUP);
  pinMode(buttonForwardRight, INPUT_PULLUP);
  pinMode(buttonForwardLeft, INPUT_PULLUP);
  pinMode(buttonBackwardRight, INPUT_PULLUP);
  pinMode(buttonBackwardLeft, INPUT_PULLUP);
  delay(10);

}

void loop() {
  //prepare to capture data to pass wirelessly using data for identifier.
  myRadio.write(&data, sizeof(data));

  // read the pushbutton input pin
  buttonState = digitalRead(buttonPin);
  // check if the button is pressed or released
  // by comparing the buttonState to its previous state, this is the best I could get to being bulletproof and no debouning effect using joystick
  if (buttonState != lastButtonState) {

    // change the state of the led when someone pressed the button
    if (buttonState == 0) {
      data.stateNum++;
      if (data.stateNum > 2) data.stateNum = 0;
    }

    // remember the current state of the button
    lastButtonState = buttonState;
  }

  data.joyposX = analogRead(joyX);
  data.joyposY = analogRead(joyY);
  data.potValue = analogRead(Pot);

  // Serial.print(data.joyposX);
  // Serial.println("joyposX");
  // Serial.println(data.joyposY);
  // Serial.println("joyposY");
  // Serial.println(data.potValue);
  //Serial.println(data.stateNum);

  if (digitalRead(buttonSideWayRight) == LOW) {
    data.SideWayRightState = 0;
  }
  else {
    data.SideWayRightState = 1;
  }
  if (digitalRead(buttonSideWayLeft) == LOW) {
    data.SideWayLeftState = 0;
  }
  else {
    data.SideWayLeftState = 1;
  }
  if (digitalRead(buttonForwardRight) == LOW) {
    data.ForwardRightState = 0;
  }
  else {
    data.ForwardRightState = 1;
  }
  if (digitalRead(buttonForwardLeft) == LOW) {
    data.ForwardLeftState = 0;
  }
  else {
    data.ForwardLeftState = 1;
  }
  if (digitalRead(buttonBackwardRight) == LOW) {
    data.BackwardRightState = 0;
  }
  else {
    data.BackwardRightState = 1;
  }
  if (digitalRead(buttonBackwardLeft) == LOW) {
    data.BackwardLeftState = 0;
  }
  else {
    data.BackwardLeftState = 1;
  }

    Serial.println(data.SideWayRightState);
   Serial.println(data.SideWayLeftState);
   Serial.println(data.ForwardRightState);
   Serial.println(data.ForwardLeftState);
   Serial.println(data.BackwardRightState);
   Serial.println(data.BackwardLeftState);

}

receiver sketch:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 myRadio(8, 9); // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

struct package
{
  int joyposX;
  int joyposY;
  int potValue;
  int stateNum;
  int SideWayRightState;
  int SideWayLeftState;
  int ForwardRightState;
  int ForwardLeftState;
  int BackwardRightState;
  int BackwardLeftState;
};

typedef struct package Package;
Package data;

// Set initial motor speed at 0
int motorspeedModeOne = 0;
int motorspeedModeTwo = 0;

void setup() {
  Serial.begin(9600);
  AFMS.begin(4000);  // OR with a different frequency, say 4KHz
  while (!Serial);

  myRadio.begin();
  //set the address
  myRadio.openReadingPipe(0, address);
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS );
  //Set module as receiver
  myRadio.startListening();
}

void loop() {
  if ( myRadio.available())
  {
    myRadio.read( &data, sizeof(data) );
    if (data.joyposX < 485)//Going Forward
    {
      if (data.stateNum == 1)
      {
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        motorspeedModeOne = map(data.joyposX, 485, 0, 0, 255);
        myMotor1->setSpeed(motorspeedModeOne);
        myMotor2->setSpeed(motorspeedModeOne);
        myMotor3->setSpeed(motorspeedModeOne);
        myMotor4->setSpeed(motorspeedModeOne);
      }
      else if (data.stateNum == 2)
      {
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.joyposX > 600)//Going Backward
    {
      if (data.stateNum == 1)
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        motorspeedModeOne = map(data.joyposX, 600, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeOne);
        myMotor2->setSpeed(motorspeedModeOne);
        myMotor3->setSpeed(motorspeedModeOne);
        myMotor4->setSpeed(motorspeedModeOne);
      }
      else if (data.stateNum == 2)//Going Backward
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.joyposY > 600)//Going left
    {
      if (data.stateNum == 1)
      {
        myMotor1->run(FORWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(BACKWARD);
        motorspeedModeOne = map(data.joyposY, 600, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeOne);
        myMotor2->setSpeed(motorspeedModeOne);
        myMotor3->setSpeed(motorspeedModeOne);
        myMotor4->setSpeed(motorspeedModeOne);
      }
      else if (data.stateNum == 2)//Going left
      {
        myMotor1->run(FORWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(BACKWARD);
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.joyposY < 470)//Going right
    {
      if (data.stateNum == 1)
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(FORWARD);
        motorspeedModeOne = map(data.joyposY, 470, 0, 0, 255);
        myMotor1->setSpeed(motorspeedModeOne);
        myMotor2->setSpeed(motorspeedModeOne);
        myMotor3->setSpeed(motorspeedModeOne);
        myMotor4->setSpeed(motorspeedModeOne);
      }
      else if (data.stateNum == 2)//Going right
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(FORWARD);
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.SideWayRightState == 0) {//GREEN BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        myMotor1->setSpeed(255);
        myMotor2->setSpeed(255);
        myMotor3->setSpeed(255);
        myMotor4->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.SideWayLeftState == 0) {//GREEN BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        myMotor1->setSpeed(255);
        myMotor2->setSpeed(255);
        myMotor3->setSpeed(255);
        myMotor4->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.ForwardRightState == 0) {//YELLOW BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(RELEASE);
        myMotor2->run(RELEASE);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        myMotor3->setSpeed(255);
        myMotor4->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(RELEASE);
        myMotor2->run(RELEASE);
        myMotor3->run(FORWARD);
        myMotor4->run(FORWARD);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    if (data.ForwardLeftState == 0) {//YELLOW BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(RELEASE);
        myMotor4->run(RELEASE);
        myMotor1->setSpeed(255);
        myMotor2->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(FORWARD);
        myMotor2->run(FORWARD);
        myMotor3->run(RELEASE);
        myMotor4->run(RELEASE);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
      }
    }
    else if (data.BackwardRightState == 0) {// BLUE BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(RELEASE);
        myMotor4->run(RELEASE);
        myMotor2->setSpeed(255);
        myMotor3->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(BACKWARD);
        myMotor2->run(BACKWARD);
        myMotor3->run(RELEASE);
        myMotor4->run(RELEASE);
        myMotor1->setSpeed(motorspeedModeTwo);
        myMotor2->setSpeed(motorspeedModeTwo);
      }
    }
    else if (data.BackwardLeftState == 0) {// BLUE BUTTON
      if (data.stateNum == 1)
      {
        myMotor1->run(RELEASE);
        myMotor2->run(RELEASE);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        myMotor3->setSpeed(255);
        myMotor4->setSpeed(255);
      }
      else if (data.stateNum == 2)
      {
        motorspeedModeTwo = map(data.potValue, 0, 1023, 0, 255);
        myMotor1->run(RELEASE);
        myMotor2->run(RELEASE);
        myMotor3->run(BACKWARD);
        myMotor4->run(BACKWARD);
        myMotor3->setSpeed(motorspeedModeTwo);
        myMotor4->setSpeed(motorspeedModeTwo);
      }
    }
    myMotor1->run(RELEASE);
    myMotor2->run(RELEASE);
    myMotor3->run(RELEASE);
    myMotor4->run(RELEASE);
  }
}

controller schema

https://github.com/Fabiolus2020/MaccanumRobotWireless/blob/main/controller_bb.png

receiver schema:

https://github.com/Fabiolus2020/MaccanumRobotWireless/blob/main/receiver_bb.png

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube