Tart Robotics
Published © GPL3+

A DIY Remote-Controlled Rescue Robot with Arduino and Lego

Make a teleoperated rescue robot out of Lego Technic, Arduino boards, off-the-shelf DC and servo motors, and NRF communication modules.

IntermediateFull instructions provided5 hours8,907

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Nano R3
Arduino Nano R3
×1
SparkFun Motor Driver - Dual TB6612FNG (1A)
SparkFun Motor Driver - Dual TB6612FNG (1A)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
TT DC 1:120 gear-motor
×1
Modulo Joystick
Modulo Joystick
×1
SparkFun Transceiver Breakout - nRF24L01+ (RP-SMA)
SparkFun Transceiver Breakout - nRF24L01+ (RP-SMA)
×2
Buzzer
Buzzer
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×1
DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
TaydaElectronics DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
×1
Screw M3 30mm
×1
Screw M3 16mm
×2
Machine Screw, M2
Machine Screw, M2
×2
Lock nut m3
×3
Nut m2
×1
Hardware, Washer
Hardware, Washer
×4
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
mini bread board
×2
bread board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Schematic diagram of rescue robot circuit

Schematic diagram of the operator console circuit

Code

Rescue Robot

C/C++
Upload this code to your rescue robot's Arduino Uno.
/*
  Rescue Robot
    The idea:
    In this project, we will show you how to make a teleoperated rescue robot out of Lego Technic pieces,
    Arduino boards, off-the-shelf DC and servo motors, NRF communication modules, and joystick module.
    The current project uses an Arduino Uno and Nano boards as the main controller of the
    robot and the operator console, respectively
    The circuit:
    - In this circuit, an Arduino UNO is used. Any other types of Arduino
    can be used of course but do not forget to change the pin configurations
    if you want to change the circuit on your preference.
    Visit the Tart Robotics blog for more information:
    https://www.tartrobotics.com/blog
*/

#define servo 2
#define motor_leftpwm 5
#define motor_rightpwm 6
#define motor_left_d 3
#define motor_left_a 4
#define motor_right_a 9
#define motor_right_d 8
#define buzzer A5
#define aux_gnd_1 A4
#define aux_gnd_2 A3
#define aux_vcc A2

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>

RF24 radio(10, 7); // CE, CSN
Servo gripper;

const byte address[6] = "00001";
int gripperPos = 90;

void setup() {

  Serial.begin(115200);
  pinMode(servo, OUTPUT);
  pinMode(motor_left_a, OUTPUT);
  pinMode(motor_left_d, OUTPUT);
  pinMode(motor_right_a, OUTPUT);
  pinMode(motor_right_d, OUTPUT);
  pinMode(motor_rightpwm, OUTPUT);
  pinMode(motor_leftpwm, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(aux_gnd_1, OUTPUT);
  pinMode(aux_gnd_2, OUTPUT);
  pinMode(aux_vcc, OUTPUT);

  digitalWrite(motor_left_a, HIGH);
  digitalWrite(motor_left_d, HIGH);
  digitalWrite(motor_right_a, HIGH);
  digitalWrite(motor_right_d, HIGH);
  digitalWrite(aux_gnd_1, LOW);
  digitalWrite(aux_gnd_2, LOW);
  digitalWrite(aux_vcc, HIGH);
  gripper.attach(servo);
  gripper.write(90);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    char message[32] = "";
    radio.read(&message, sizeof(message));
    if (message[0] == '1')closeGripper();
    else if (message[1] == '1')openGripper();
    if (message[2] == '1')digitalWrite(buzzer, HIGH);
    else digitalWrite(buzzer, LOW);
    driveRobot(message[3], message[4], message[5], message[6]);
  }
}

// Gripper
void closeGripper() {
  gripperPos++;
  gripper.write(gripperPos);
  delay(10);
}

void openGripper() {
  gripperPos--;
  gripper.write(gripperPos);
  delay(10);
}

//Driverobot
void driveRobot(char X_dir, char Y_dir, char X, char Y) {
  int X_val, Y_val;
  if (X == '4')X_val = 240;
  else if (X == '3')X_val = 180;
  else if (X == '2')X_val = 120;
  else if (X == '1')X_val = 60;
  else if (X == '0')X_val = 0;
  if (Y == '4')Y_val = 240;
  else if (Y == '3')Y_val = 180;
  else if (Y == '2')Y_val = 120;
  else if (Y == '1')Y_val = 60;
  else if (Y == '0')Y_val = 0;
  if (X_dir == '1')X_val *= -1;
  if (Y_dir == '1')Y_val *= -1;

  float r = 0.75 * sqrt(pow(X_val, 2) + pow(Y_val, 2));
  float theta = atan2(Y_val, X_val);
  if (theta < 0)theta += 2 * PI;
  float rightMotorVal, leftMotorVal;
  float slope = 4 / PI;
  if (theta <= PI / 2) {
    leftMotorVal = 1;
    rightMotorVal = -1 + slope * theta;
  } else if (theta <= PI) {
    leftMotorVal = 1 - slope * (theta - PI / 2);
    rightMotorVal = 1;
  } else if (theta <= 3 * PI / 2) {
    leftMotorVal = -1;
    rightMotorVal = 1 - slope * (theta - PI);
  } else if (theta <= 2 * PI) {
    leftMotorVal = -1 + slope * (theta - 3 * PI / 2);
    rightMotorVal = -1;
  }

  leftMotorVal *= r;
  rightMotorVal *= r;

//Motors
  int rightMotorDir = rightMotorVal < 0 ? 1 : 0;
  int leftMotorDir = leftMotorVal < 0 ? 1 : 0;
  rightMotorVal = floor(abs(rightMotorVal));
  leftMotorVal = floor(abs(leftMotorVal));

  if (rightMotorDir) {
    digitalWrite(motor_right_a, HIGH);
    digitalWrite(motor_right_d, LOW);
    analogWrite(motor_rightpwm, rightMotorVal);
  } else {
    digitalWrite(motor_right_a, LOW);
    digitalWrite(motor_right_d, HIGH);
    analogWrite(motor_rightpwm, rightMotorVal);
  }

  if (leftMotorDir) {
    digitalWrite(motor_left_a, LOW);
    digitalWrite(motor_left_d, HIGH);
    analogWrite(motor_leftpwm, leftMotorVal);
  } else {
    digitalWrite(motor_left_a, HIGH);
    digitalWrite(motor_left_d, LOW);
    analogWrite(motor_leftpwm, leftMotorVal);
  }
}

Operator Console

C/C++
Upload this code to the Arduino Nano of your rescue robot's operator console.
/*
  Operator Console:
    The idea:
    In this project, we will show you how to make a teleoperated rescue robot out of Lego Technic pieces,
    Arduino boards, off-the-shelf DC and servo motors, NRF communication modules, and joystick module.
    The current project uses an Arduino Uno and Nano boards as the main controller of the
    robot and the operator console, respectively
    The circuit:
    - In this circuit, an Arduino nano is used. Any other types of Arduino
    can be used of course but do not forget to change the pin configurations
    if you want to change the circuit on your preference.
    Visit the Tart Robotics blog for more information:
    https://www.tartrobotics.com/blog
*/

#define js_click A0
#define js_y A1
#define js_x A2
#define yellow_button 5
#define green_button 4
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
int jsY_offset, jsX_offset;

void setup() {
  Serial.begin(115200);
  pinMode(js_click, INPUT_PULLUP);
  pinMode(js_y, INPUT_PULLUP);
  pinMode(js_y, INPUT_PULLUP);
  pinMode(yellow_button, INPUT_PULLUP);
  pinMode(green_button, INPUT_PULLUP);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  jsY_offset = analogRead(js_y);
  jsX_offset = analogRead(js_x);
}

void loop() {
  int jsX = jsY_offset - analogRead(js_y);
  int jsY = jsX_offset - analogRead(js_x);
  int jsC = digitalRead(js_click);
  int yellowButton = !digitalRead(yellow_button);
  int greenButton = !digitalRead(green_button);
  char yellowButton_char = yellowButton == 0 ? '0' : '1';
  char greenButton_char = greenButton == 0 ? '0' : '1';
  char jsY_dir = jsY > 0 ? '0' : '1';
  char jsX_dir = jsX > 0 ? '0' : '1';
  char jsC_char = jsC == 0 ? '1' : '0';
  char jsY_abs, jsX_abs;
  if (abs(jsY) > 400)jsY_abs = '4';
  else if (abs(jsY) > 300)jsY_abs = '3';
  else if (abs(jsY) > 200)jsY_abs = '2';
  else if (abs(jsY) > 100)jsY_abs = '1';
  else if (abs(jsY) > 0)jsY_abs = '0';
  if (abs(jsX) > 400)jsX_abs = '4';
  else if (abs(jsX) > 300)jsX_abs = '3';
  else if (abs(jsX) > 200)jsX_abs = '2';
  else if (abs(jsX) > 100)jsX_abs = '1';
  else if (abs(jsX) > 0)jsX_abs = '0';

  const char message[] = {yellowButton_char, greenButton_char,
                          jsC_char, jsX_dir, jsY_dir, jsX_abs, jsY_abs
                         };
  radio.write(&message, sizeof(message));
}

Credits

Tart Robotics

Tart Robotics

15 projects • 49 followers
Our mission is to provide children with novel robotic tools, to inspire them to become future innovators.

Comments