element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
IoT: In the Cloud
  • Challenges & Projects
  • Project14
  • IoT: In the Cloud
  • More
  • Cancel
IoT: In the Cloud
Blog Arduino IoT Cloud controlled MKR Robot ARM: We have Movement
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join IoT: In the Cloud to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jomoenginer
  • Date Created: 15 Apr 2019 3:41 PM Date Created
  • Views 1405 views
  • Likes 10 likes
  • Comments 0 comments
  • p14 mkr 1010
  • robotics
  • arduino mkr 1000
  • morobotsch
  • arduino mkr wifi 1010
  • arduino
  • iotc
Related
Recommended

Arduino IoT Cloud controlled MKR Robot ARM: We have Movement

jomoenginer
jomoenginer
15 Apr 2019
image

Month of Robots

Enter Your Project for a chance to win robot prizes for your robot builds and a $200 shopping cart!  The Birthday Special: Robot Prizes for Robot Projects!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

IoT: In the Cloud - Arduino IoT Cloud controlled MKR Robot ARM

Overview

In a previous post, it was outlined how to get a Device Configured and a Thing created in the Arduino IoT Cloud. Here this is taken to the next step to configure multiple Thing Properties in the Arduino IoT Cloud to control a Robotics Arm.  Currently, since the Arduino IoT Cloud is still in Beta, there are some limitations.  These include:

  • Only a Single Device can be attached at a time
  • Only 1 Thing can be created per user at this time.
  • The 1 Thing can only have 5 Properties.

Previous Post:

Arduino IoT Cloud controlled MKR Robot ARM: Das Blinken LED

 

The Initial intent of this project was to have both a Robot Arm and a Conveyor Belt running together from the Arduino IoT Cloud, however due to the Single Device and Single Thing limitation, this will have to be rethought.

The devices were added to the Device Manager none the less.

image

 

NOTE: When configuring a MKR board for Arduino IoT Cloud, ensure there is nothing connected to the i2C signals (SDA (D11), SCL(D12)) otherwise the Crypto section of adding a Device will fail.  Also, this will cause issues with the Arduino IoT Cloud begin when the board boots up.

 

If a Thing has already been created, attempting to create a new one will result in an error.

image

 

Once the Thing is selected, The Thing Properties Windows will show.

image

 

Currently, 5 Properties have been created, thus due to the limitations of the Arduino IoT Cloud, selecting a 6th Property will produce and error.

image

 

To change the Associated Board for the Thing, click on the Circle Icon with the 'i' in the middle at the bottom left of the window.

image

 

The Robot Arm is made of separate sections which can be controlled separately:

  • Robot Base
  • Robot Lower Arm
  • Robot Upper Arm
  • Robot Gripper (not configured yet)

 

To control the separate sections of the Robot Arm, new Properties were created for each section.

PropertyTypeUpdateDescription
RobotBasePosinton changeControl Robot Base Position
RobotUpperPosinton changeControl Robot Upper Position
RobotLowerPosinton changeControl Robot Lower Position
RunDemoON/OFF (Bool)every 1sRun Robot Arm Position

 

NOTE: Currently, in the case of the RunDemo Property, this was set to update 'Regularly', however this behavior was not experienced.  There appears to be no difference in behavior if this is or is not set;  the Property updates when the selector is moved from On to Off.

 

 

Defines in Arduino Create Code

 

Variables:

int RobotBasePos;
int RobotUpperPos;
int RobotLowerPos;
bool RunDemo;

 

Methods

void onRobotBasePosChange();
void onRobotLowerPosChange();
void onRobotUpperPosChange();
void onRunDemoChange();

 

initProperties

  ArduinoCloud.addProperty(RobotBasePos, READWRITE, ON_CHANGE, onRobotBasePosChange); 
  ArduinoCloud.addProperty(RobotLowerPos, READWRITE, ON_CHANGE, onRobotLowerPosChange);
  ArduinoCloud.addProperty(RobotUpperPos, READWRITE, ON_CHANGE, onRobotUpperPosChange);
  ArduinoCloud.addProperty(RunDemo, READWRITE, 1 * SECONDS, onRunDemoChange);

 

For each Robot Arm Segment, when the associated Arduino IoT Cloud method is called, the moveArm method is called to move that section of the Arm.

 

onRobotBasePosChange

void onRobotBasePosChange() {
  // Do something
  moveArm(baseServo, RobotBasePos);
  Serial.print("Current Base Arm pos: ");
  Serial.println(baseServo.getArmPos());
  delay(30);
}

 

onRobotLowerPosChange

void onRobotLowerPosChange() {
  // Do something
  // RobotLowerPos
  moveArm(lowerArmServo, RobotLowerPos);
  Serial.print("Current Base Lower pos: ");
  Serial.println(lowerArmServo.getArmPos());
  delay(30);
}

 

onRobotUpperPosChange

void onRobotUpperPosChange() {
  // Do something
  moveArm(upperArmServo, RobotUpperPos);
  Serial.print("Current Upper Arm pos: ");
  Serial.println(upperArmServo.getArmPos());
  delay(30);
}

 

 

Each Arm segment code calls the moveArm method to move to appropriate position.

void moveArm(RobotArm& roboArm,int robotPos)
{
  volatile auto currentPos = roboArm.getArmPos();
  if (currentPos < robotPos)
  {
    while (currentPos < robotPos)
    {
       currentPos += roboArm.getArmPosInc();
       roboArm.setArmPos(currentPos);
       roboArm.updateArmPos();
       delay(50);
    }
  } else {
    while (robotPos < currentPos)
    {
      currentPos -= roboArm.getArmPosInc();
      roboArm.setArmPos(currentPos);
      roboArm.updateArmPos();
      delay(50);
    }
  }
}

 

 

The RunDemo Property is changed when the selector switch goes from Off to On which then calls the onRunDemoChange method.

Since this did not update every 1 second as expected, an alternate was used by creating a start state variable that is set to Start if the RunDemo property is set to True.

This will then call the runRobotArmDemo method every 200 milliseconds.

 

Main 'loop' code

void loop() {
  ArduinoCloud.update();
  // Your code here 
  if (arm_start_state == ArmStates::ARM_MOVE_START)
  { 
    currentMillis = millis();
    if (currentMillis - startMillis >= period)
    { 
        runRobotArmDemo();
        startMillis = currentMillis;
    }
  }
}

 

onRunDemoChange

void onRunDemoChange() {
  // Set arm start state based on RunDemo value


  if (RunDemo)
  {
    arm_start_state = ArmStates::ARM_MOVE_START;
  } else {
      arm_start_state = ArmStates::ARM_MOVE_STOP;
  }
}

 

runRobotArmDemo

void runRobotArmDemo(void)
{
  //static uint16_t basePos = baseServo.getPosCent();
  static uint16_t destPos = 10;
  Serial.print("Current Base pos: ");
  Serial.println(basePos);

  switch (arm_state)
  {
    case ArmStates::ARM_MOVE_CENTER:
         switch(arm_next_state)
         {
             case ArmStates::ARM_MOVE_RIGHT:
                 arm_state = ArmStates::ARM_MOVE_RIGHT;
                 arm_next_state = ArmStates::ARM_MOVE_CENTER;
                 Serial.print("Case move Right: ");
                 break;

             case ArmStates::ARM_MOVE_LEFT:
                 arm_state = ArmStates::ARM_MOVE_LEFT;
                 arm_next_state = ArmStates::ARM_MOVE_CENTER;
                 Serial.print("Case move Left: ");
                 //destPos = 10;
                 break;
         }
         break;
    case ArmStates::ARM_MOVE_LEFT:
                  Serial.print("In Move Left ");
                 //if (basePos <= baseServo.getPosCent() && basePos > destPos) {
                 if (basePos >= destPos) {
                 // Keep moving left
                    basePos--;
                 } else {
                    if (destPos == 10) {
                        arm_state = ArmStates::ARM_MOVE_CENTER;
                        arm_next_state = ArmStates::ARM_MOVE_RIGHT;
                        destPos = 90; 
                    } else {
                        arm_state = ArmStates::ARM_MOVE_CENTER;
                        arm_next_state = ArmStates::ARM_MOVE_LEFT;
                        destPos = 10;
                    }
                 } 
                 break;
    case ArmStates::ARM_MOVE_RIGHT: 
                 Serial.print("In Move Right: ");
                 if (basePos <= destPos) {
                 // Keep moving right
                    basePos++;
                 } else {
                     if (destPos == 170) {
                         arm_state = ArmStates::ARM_MOVE_CENTER;
                         arm_next_state = ArmStates::ARM_MOVE_LEFT;
                         destPos = 90;
                     } else {
                         arm_state = ArmStates::ARM_MOVE_CENTER;
                         arm_next_state = ArmStates::ARM_MOVE_RIGHT;
                         destPos = 170;
                     }
                 } 
                 break;

    case ArmStates::ARM_MOVE_STOP: break;
  }

    moveArm(baseServo, basePos);  
}

 

 

These are called by the Property Widgets

image

 

 

If the Monitor window is selected in the Arduino Create Editor, the updated position for the Arm movements are shown.

image

 

Video Showing the Robot Arm being controlled by the Arduino IoT Cloud Thing interface.

NOTE: At about 5:54 into the video I attempt to show a demo of the Robot Arm movement, however I did not have the Web CAM active at this point.  I do repeat it later in the video.

 

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

  • 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