Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
braybjj
Published © GPL3+

The Centaurus (Mark 1)

Heavy-duty and Swift movement from DC Motors with control from an IR Remote, and a fashionable mustache for the ladies.

IntermediateFull instructions provided184
The Centaurus (Mark 1)

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Jumper wires (generic)
Jumper wires (generic)
Lots of them!
×1
Resistor 330 ohm
Resistor 330 ohm
×8
ELEGOO EL-KIT-012 UNO Project Smart Robot Car Kit V 3.0
ELEGOO EL-KIT-012 UNO Project Smart Robot Car Kit V 3.0
(Optional) Here, I took used some parts from the Elegoo Uno R3 Kit, but you can use any other 4 sets of durable wheels, motors, etc..
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
H-BRIDGE KIT 2GO
Infineon H-BRIDGE KIT 2GO
×1
DC Motor, 12 V
DC Motor, 12 V
×4
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1
Shift Register- Parallel to Serial
Texas Instruments Shift Register- Parallel to Serial
To customize LEDs appearance
×1
LED (generic)
LED (generic)
1 Green, 1 Red, 2 White 4 Blue
×8
Elegoo IR Remote
Again, it doesn't have to be from the Elegoo kit, this is just where I got mine from
×1
IR receiver (generic)
×1
Mustache
Must Have! Otherwise don't even bother trying
×1

Hand tools and fabrication machines

Wood
For a slick and heavy-duty chassis
Jig Saw
To cut the wood as needed
Wood Sander
For a smooth look if your cutting from regular wood planks
Wood Carver
For the interior, and to for the LEDs
Drill
Screws
Soldering iron (generic)
Soldering iron (generic)
Tape, Duct
Tape, Duct
Rarely needed, but just in case
Tape, Velcro® Stick On Tape/Strip
Tape, Velcro® Stick On Tape/Strip
For the top layer to stay in place when Centaurus is on the run

Story

Read more

Code

The Centaurus (Mark 1) - Code

Arduino
Here is the first ever code of The Centaurus, hope you find this useful!
//-------------------------------------
//Code by Brayden Ford (Circuit-Praxis)
//-------------------------------------
//Welcome To Centaurus's Code
//-------------------------------------

//library for dual motor driver
#include <SparkFun_TB6612.h>

//library for remote
#include <IRremote.h>

//ultra sonic sensor pins
int trigPin = 3;
int echoPin = A2;
int pingTravelTime;

//remote
int IRpin = A0;
String Command;
IRrecv IR(IRpin);
decode_results cmd;

//dual motor driver pins
#define AN1 12
#define BN1 7
#define AN2 4
#define BN2 8
#define PWMA 5
#define PWMB 6
#define STBY 9

//constants for motor configuration
const int offsetA = 1;
const int offsetB = -1;

//define duel motor driver pins
Motor motor1 = Motor(AN1, AN2, PWMA, offsetA, STBY);
Motor motor2 = Motor(BN1, BN2, PWMB, offsetB, STBY);

//delay
int dt = 100;

// Rnadom pattern for turning function
long randomTurn = 43;

//Shift regigister pins for LEDs
const int dataPin = A3;
const int clockPin = 13;
const int latchPin = 2;

//(LEDs) when forward 
byte fLeds = 0b11111111;
//when slowed down
byte sLeds = 0b01111110;
//when slowed down more
byte ssLeds = 0b00111100;
//default LEDs
byte dLeds = 0b01111110;
//when back
byte bLeds = 0b10000001;
//turn LEDs off
byte oLeds = 0b00000000;

void setup() {
  //setup serial monitor
  Serial.begin(9600);

  //IR remote
  IR.enableIRIn();

  //ultra sonic sensor setup
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //shift register
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  // Rnadom pattern for turning to mimic AI features
  randomSeed(40);
  
}

void loop() {

  //wait until button has been pressed
  while (IR.decode(&cmd) == 0) {

  }

  ////////////////////////////////if IR = up arrow button - go forward
  if (cmd.value == 0xFF629D) {
    IR.enableIRIn();
    delay(60);
    IR.resume();
    forward(motor1, motor2, 255);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, bLeds);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00011000);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00100100);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b01000010);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b10000001);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b11111111);
    digitalWrite(latchPin, HIGH);
  }
      else{
       if (cmd.value != 0xFF42BD) {
       IR.enableIRIn();
       delay(60);
       IR.resume();
       }
    }

  ////////////////////////////////if IR = down arrow button - go back
  if (cmd.value == 0xFFA857) {
    IR.enableIRIn();
    delay(60);
    IR.resume();
    back(motor1, motor2, -160); 
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, bLeds);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b10000001);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b01000010);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00100100);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00011000);
    digitalWrite(latchPin, HIGH);
    delay(40);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
  }

  ////////////////////////////////if IR = left arrow button - turn left
  if (cmd.value == 0xFF22DD) {
    IR.enableIRIn();
    delay(60);
    IR.resume();
    motor1.brake();
    motor2.drive(255);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b10000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b01000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00100000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00010000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00001000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000100);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000010);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
  }

  ////////////////////////////////if IR = right arrow button - turn right
  if (cmd.value == 0xFFC23D) {
    IR.enableIRIn();
    delay(60);
    IR.resume();
    motor1.drive(255);
    motor2.brake();
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000010);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000100);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00001000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00010000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00100000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b01000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b10000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
    digitalWrite(latchPin, HIGH);
    delay(20);
  }

  ////////////////////////////////if IR = OK button - stop
  if (cmd.value == 0xFF02FD) {
    IR.enableIRIn();
    delay(60);
    IR.resume();
    forward(motor1, motor2, 0);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, fLeds);
    digitalWrite(latchPin, HIGH);
  }

  ////////////////////////////////////IR = # (number sign button)
  if (cmd.value == 0xFF52AD) {
    IR.enableIRIn();
    delay(10);
    IR.resume();
    //turn on each LED
    for (int i = 0; i < 256; i++) {
      //take the latchClock low so the LEDs don't
      //change while you're sending in bits
      digitalWrite(latchPin, LOW);
      //shift out the bits
      shiftOut(dataPin, clockPin, MSBFIRST, i);
      digitalWrite(latchPin, HIGH);
      delay(60);
      //wait until button has been pressed
      while (IR.decode(&cmd) == 0) {
        if (cmd.value == 0xFF52AD) {
          for (int i = 0; i < 256; i++) {
            //take the latchClock low so the LEDs don't
            //change while you're sending in bits
            digitalWrite(latchPin, LOW);
            //shift out the bits
            shiftOut(dataPin, clockPin, MSBFIRST, i);
            digitalWrite(latchPin, HIGH);
            delay(60);
          }
        }
      }
    }
  }
      ////////////////////////////////////if IR = * (star button)
  if (cmd.value == 0xFF42BD) {
    AI_driving();

  }
}

  void AI_driving(){
  
    //initialize and print vision distance of Centaurus
    Serial.print(" ");
    Serial.print("Distance of View is: ");
    Serial.println(pingTravelTime);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(10);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    pingTravelTime = pulseIn(echoPin, HIGH);
    delay(100);

    //forward
    if (pingTravelTime > 3000) {
      forward(motor1, motor2, 255);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, fLeds);
      digitalWrite(latchPin, HIGH);
    }

    //slow down
    if (pingTravelTime < 3000 && pingTravelTime > 2500) {
      forward(motor1, motor2, 200);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, sLeds);
      digitalWrite(latchPin, HIGH);
    }

    //slow down more
    if (pingTravelTime < 2500 && pingTravelTime > 2000) {
      forward(motor1, motor2, 160);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, ssLeds);
      digitalWrite(latchPin, HIGH);
    }

    //back
    if (pingTravelTime < 600 && pingTravelTime >= 0) {
      back(motor1, motor2, -180);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, bLeds);
      digitalWrite(latchPin, HIGH);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
      digitalWrite(latchPin, HIGH);
      delay(140);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b10000001);
      digitalWrite(latchPin, HIGH);
      delay(140);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b01000010);
      digitalWrite(latchPin, HIGH);
      delay(140);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b00100100);
      digitalWrite(latchPin, HIGH);
      delay(140);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b00011000);
      digitalWrite(latchPin, HIGH);
      delay(140);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
      digitalWrite(latchPin, HIGH);
      delay(140);
    }

    //turn (random direction)
    if (pingTravelTime > 600 && pingTravelTime < 2200) {
      //generate and print decesion thought process system
      randomTurn = random(2);
      Serial.print(" randomTurn Value is: ");
      Serial.print(randomTurn);
      if (randomTurn == 1) {
        motor1.drive(200);
        motor2.brake();
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000010);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000100);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00001000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00010000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00100000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b01000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b10000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
      }
      if (randomTurn == 0) {
        motor1.brake();
        motor2.drive(200);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b10000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b01000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00100000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00010000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00001000);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000100);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000010);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001);
        digitalWrite(latchPin, HIGH);
        delay(80);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, 0b00000000);
        digitalWrite(latchPin, HIGH);
        delay(80);
      }
    }
    //forward
    if(pingTravelTime < 0) {
      forward(motor1, motor2, 255);
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, fLeds);
      digitalWrite(latchPin, HIGH);
    }

  }

//------------------------------------------------------------------------
//Thanks for visiting the code of Centaurus. Hope you find this useful!
//------------------------------------------------------------------------

Credits

braybjj

braybjj

0 projects • 0 followers

Comments