Use of the Virtual Robot Arm

by isabel001 in Circuits > Arduino

277 Views, 0 Favorites, 0 Comments

Use of the Virtual Robot Arm

IMG_6643.png
IMG_6643.png
Captura de pantalla 2022-11-27 a las 23.15.33.png

For this project we have to get our robot to move the different parts of the arm (divided by structures) and reach a red ball that appears on the screen to finish the objective of the game.

Supplies

Captura de pantalla 2022-11-27 a las 22.55.34.png
Captura de pantalla 2022-11-27 a las 23.06.01.png
  • pressure sensors X2
  • arm change potentiometer 
  • transparent methacrylate box from servei estaciĆ³ 155 x 70 x 70 mm
  •  jumper cables
  • 2 resistors of 1000
  • 5/6 resistors of 240
  • Arduino board
  • breadboard
  • a brilliant mind

The Code

Here we can see the flow diagram:


//Developed by Isabel Ruiz and Jan Esteba - GEDI 101 - UATEA 2022

//This program sends joint position angles (in degrees) via serial com

//as a demo for connecting ROBOTARM_GAME_V4

/*This code uses two pressure sensors and 5 LED's to show the remote control in which fase of the robotic arm is selected

and with the pressure applied in each of the sensors the signal is sent to the arduino making a 5degree rotation when pressure is applied.

With the arduino Uno we are able to control the Robotic arm in an easy and intuitive way 

*/


//This is where we define the potenciometer value

long potenciometro;


// Here we define angle variables

float j0_angle = 0; // the angle we are going to send

float j1_angle = 0;

float j2_angle = 0;

float j3_angle = 0;

float j4_angle = 0;


// Define angle limits

float minrot0 = -360, maxrot0 = 360;

float minrot1 = 30, maxrot1 = 90;

float minrot2 = -120, maxrot2 = -60;

float minrot3 = -360, maxrot3 = 360;

float minrot4 = -60, maxrot4 = 60;



//We declare the LED for each pin in the arduino board

int LED_0 = 2;

int LED_1 = 3;

int LED_2 = 4;

int LED_3 = 5;

int LED_4 = 6;


int sensor1 = 0;

int sensor2 = 0;



void setup() {

 //We initialize the serial command to see in the serial monnitor

 Serial.begin(115200);


 //This is where we define the pinMode as an OUTPUT for every LED

 pinMode(LED_0, OUTPUT);

 pinMode(LED_1, OUTPUT);

 pinMode(LED_2, OUTPUT);

 pinMode(LED_3, OUTPUT);

 pinMode(LED_4, OUTPUT);


  

}


void loop() {


 // The value equals to the analogread of the potentiometer

 potenciometro = analogRead(A0);

 sensor1 = analogRead(A1);

 sensor2 = analogRead(A2);


 //We declare with if clause what we want the LED's to do with LOW's or HIGH's depending on the LED's status we want

 if (potenciometro == 0) {

  digitalWrite(LED_0, LOW);

  digitalWrite(LED_1, LOW);

  digitalWrite(LED_2, LOW);

  digitalWrite(LED_3, LOW);

  digitalWrite(LED_4, LOW);

 }

 /*If the value of the potentiometer is set between 0 or 205, LED0 turns ON and the rest OFF and sets an if clause for the sensors

  that if they are pressed, so the value of the analogread is higher than 10, does a + rotation or a - rotation of 5 in each reading*/

 else if (potenciometro > 0 && potenciometro <= 205) {

  digitalWrite(LED_0, HIGH);

  digitalWrite(LED_1, LOW);

  digitalWrite(LED_2, LOW);

  digitalWrite(LED_3, LOW);

  digitalWrite(LED_4, LOW);


  if (sensor1 < 10) {

   j0_angle += 5;

  }


  if (sensor2 < 10) {

   j0_angle -= 5;

  }

   Serial.println("J0_" + String(j0_angle, 3));

 }


 /*If the value of the potentiometer is set between 205 or 410, LED1 turns ON and the rest OFF and sets an if clause for the sensors

 that if they are pressed, so the value of the analogread is higher than 10, does a + rotation or a - rotation of 5 in each reading*/

 else if (potenciometro >= 205 && potenciometro <= 410) {

  digitalWrite(LED_0, LOW);

  digitalWrite(LED_1, HIGH);

  digitalWrite(LED_2, LOW);

  digitalWrite(LED_3, LOW);

  digitalWrite(LED_4, LOW);


  if (sensor1 < 10) {

   j1_angle += 5;

  }


  if (sensor2 < 10) {

   j1_angle -= 5;

  }

   Serial.println("J1_" + String(j1_angle, 3));

 }

 /*If the value of the potentiometer is set between 410 or 615, LED2 turns ON and the rest OFF and sets an if clause for the sensors

 that if they are pressed, so the value of the analogread is higher than 10, does a + rotation or a - rotation of 5 in each reading*/

 else if (potenciometro >= 410 && potenciometro <= 615) {

  digitalWrite(LED_0, LOW);

  digitalWrite(LED_1, LOW);

  digitalWrite(LED_2, HIGH);

  digitalWrite(LED_3, LOW);

  digitalWrite(LED_4, LOW);



  if (sensor1 < 10) {

   j2_angle += 5;

  }


  if (sensor2 < 10) {

   j2_angle -= 5;

  }

   Serial.println("J2_" + String(j2_angle, 3));

 }


 /*If the value of the potentiometer is set between 615 or 819, LED3 turns ON and the rest OFF and sets an if clause for the sensors

 that if they are pressed, so the value of the analogread is higher than 10, does a + rotation or a - rotation of 5 in each reading*/

 else if (potenciometro >= 615 && potenciometro <= 819) {

  digitalWrite(LED_0, LOW);

  digitalWrite(LED_1, LOW);

  digitalWrite(LED_2, LOW);

  digitalWrite(LED_3, HIGH);

  digitalWrite(LED_4, LOW);


  if (sensor1 < 10) {

   j3_angle += 5;

  }


  if (sensor2 < 10) {

   j3_angle -= 5;

  }

   Serial.println("J3_" + String(j3_angle, 3));

 }


 /*If the value of the potentiometer is set between 819 or 1023, LED3 turns ON and the rest OFF and sets an if clause for the sensors

 that if they are pressed, so the value of the analogread is higher than 10, does a + rotation or a - rotation of 5 in each reading*/

 else if (potenciometro >= 819 && potenciometro <= 1023) {

  digitalWrite(LED_0, LOW);

  digitalWrite(LED_1, LOW);

  digitalWrite(LED_2, LOW);

  digitalWrite(LED_3, LOW);

  digitalWrite(LED_4, HIGH);


  if (sensor1 < 10) {

   j4_angle += 5;

  }


  if (sensor2 < 10) {

   j4_angle -= 5;

  }

   Serial.println("J4_" + String(j4_angle, 3));

 }

 Serial.flush();  // wait for messages to be sent

 delay(500);     // wait for 5 seconds

}


Schematics

WhatsApp Image 2022-11-22 at 14.20.19.jpeg
Captura de pantalla 2022-11-27 a las 22.57.46.png

Here we have the schematics for understand better the code and use:


Flux Diagram

WhatsApp Image 2022-11-27 at 23.17.40 (1).jpeg

Photos of Development

IMG_6642.png
IMG_6641.png
IMG_6635.png
IMG_6633.png
IMG_6643.png

Some images during the process

Conclusion

As we can see, the box works properly and fulfills all its functions. 

And we have managed to create an intuitive and simple system to control the program in a "futuristic" way.

Here we have a video of how it works while we were creating the box.