Let's Make Robots!

SUMBA - a sumo robot and my first project

pushes other bots out of the arena

Hi everybody, as some people allready know i am new to LMR and robots all together, meaning this is my first robot.

It was originally going to be a holiday project but when my science teacher gave us a holiday assignment that had rather open criteria, the bot for fun got given 4 weeks to be finished, so now with a bit over 2 weeks left I almost have the entire bot assembeled.

The chasses dimensions are 15cm wide X 15cm long X 5cm high

 

At the moment all i have is the unfinished chasse asembled (I still need to add holes for the wheels and skrew down the motor), and the code that i believe is finished, it may need some editing once i hook up the senors and test the whole thing out. 

here is a fritz of the wiring it will be more compact when actually put together, those are 1K resistors.

here 

also with the code im using PWM to control the motors because I have an NPN transistor between the motors and the batterys and i dont want to burn out the motors.

Here is the code:

(EDITED CODE) changed after seeing the comment by bdk6

CHANGE LOG: when one motor is running the other is set to off

 

 

#define RIGHTDC 5

#define LEFTDC 6

#define MIDDLEIR A0

#define LEFTIR A1

#define RIGHTIR A2

 

#define DANGER 1000

 

#define HALFSPEED 127

#define STOP 0

 

void setup() {

  pinMode(RIGHTDC, OUTPUT);

  pinMode(LEFTDC, OUTPUT);

}

 

void loop() {

  if (analogRead(MIDDLEIR) < DANGER) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if (analogRead(RIGHTIR) < DANGER) {

    analogWrite (LEFTDC, HALFSPEED);

    analogWrite (RIGHTDC, STOP);

  } else if (analogRead(LEFTIR) < DANGER) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, STOP);

  } else if ((analogRead(LEFTIR) < DANGER) &&

             (analogRead(MIDDLEIR) < DANGER)) {

               analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

 

  } else if ((analogRead(RIGHTIR) < DANGER) && 

             (analogRead(MIDDLEIR) < DANGER)) {

               analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if ((analogRead(LEFTIR) < DANGER) && 

             (analogRead(MIDDLEIR) < DANGER) && 

             (analogRead(RIGHTIR) < DANGER)) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if ((analogRead(LEFTIR) < DANGER) && 

             (analogRead(RIGHTIR) < DANGER)) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else {

    analogWrite(LEFTDC, STOP);

    analogWrite(RIGHTDC, HALFSPEED);

  }

}

 

 

(OLD CODE)

#define RIGHTDC 5

#define LEFTDC 6

#define MIDDLEIR A0

#define LEFTIR A1

#define RIGHTIR A2

#define DANGER 1000

#define HALFSPEED 127

 

void setup() {

  pinMode(RIGHTDC, OUTPUT);

  pinMode(LEFTDC, OUTPUT);

}

 

void loop() {

  if (analogRead(MIDDLEIR) < DANGER) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if (analogRead(RIGHTIR) < DANGER) {

    analogWrite (LEFTDC, HALFSPEED);

  } else if (analogRead(LEFTIR) < DANGER) {

    analogWrite(RIGHTDC, HALFSPEED);

  } else if ((analogRead(LEFTIR) < DANGER) &&

             (analogRead(MIDDLEIR) < DANGER)) {

               analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

 

  } else if ((analogRead(RIGHTIR) < DANGER) && 

             (analogRead(MIDDLEIR) < DANGER)) {

               analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if ((analogRead(LEFTIR) < DANGER) && 

             (analogRead(MIDDLEIR) < DANGER) && 

             (analogRead(RIGHTIR) < DANGER)) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else if ((analogRead(LEFTIR) < DANGER) && 

             (analogRead(RIGHTIR) < DANGER)) {

    analogWrite(RIGHTDC, HALFSPEED);

    analogWrite(LEFTDC, HALFSPEED);

  } else {

    analogWrite(LEFTDC, 0);

  }

}

 

If you see anything that you think i could improve on please tell me, as i said i am a beginner and i would love any help that can be supplyed to me.

 

 

 

(MAJOR EDIT!!!)

i haven't updated this in a while so here is what has happened with my bot.

First off, the gear box that i was going to use had shafts that were  3 ml in diameter and they did not fit my wheels, so i looked for new wheels and coudnt find any to the right size so instead i got new motors, this leads to my next problem.

i looked for the motor on the website of the place that my sister works at and got her to buy them for me, i stuffed up and didnt look at the dimensions and i got motors that were much larger than i originally thought.

to combat this problen i got rid of three walls and the roof to make room for the new motors and battery pack.

i also edited the front of the bot so that the sensors had somewere to be placed seeing as they were originally going to be attatched to the roof.

finally, when i was about to finish the robot i found the the cable ties i had bought to hold the motors down weren't long enough.

 

by tommorow i should have the robot done and be ironing out the bugs so expect videos and pictures soon.

 there will also be updated code as i do not need to use PWM any more

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

As bdk6 suggested, but remember that this does not allow for the motors to go in reverse. For that, you should change from this type circuit to an H-bridge circuit.

                           (Click this drawing to view it bigger.)

thanks for the suggestion but for this robot I dont feel that I need it to reverse.

I see an awful lot of places in your code that sets either the left or right motor to half speed, and one place that sets the left motor to 0, but I don't see ANY code that sets a motor back to full speed or stops the right motor.  I suspect that code will make your bot wiggle around some at first, finally settling into permanent circles to the left.  But that's just me.

i have the code at half speed because of how the npn transistors work, you see by using PWM to only send 50% through it make only half of the power from the batterys get through, i am doing this becasue i am powering the 3 volt motors with 6 volts of power.

as with the going aroung in a circle, we may only know when i get everything hooked up, it will then be a case of working out the bugs.

You may want to re-read what I wrote then take a "walk" through your code, pretending you are the robot, and see what happens.

i am now realising what you meant and will edit the code when possible, also it says half speed but it really actually is full speed

based on the fritzing image, you are going to need some resistors between the arduino and the transistors.  Else you are likely to burn out both.  Also, if you have the transistors between +V and the motors, you probably want to change that and put them between the motors and ground.  But DON'T do that without the resistors!  Plus, you really should have some suppression diodes for the inductive kickback.

i do have some 1 K resistors that go between the arduino and the transistors, i will update that imediatly. thanks

Welcome to LMR...

people generally try an ostacle avoider at first ,but you are after a sumo. I would definitely like to see it finished.

I suppose a sumo bot, in simple terms is the inverse?!

if it sees and object it goes for it, if not it looks for one!

that and an edge sensing function and you are onto a winner! (well, the project will work, you wont nessecarily win)