My first robot

so i made my first robot! had a lot of hurdles during the process, just trial and error. But after finishing my goal i have a lot of questions. But first the parts I used.

http://www.radioshack.com/make-it-robotics-starter-kit/2770168.html#.VMsCVmjF91g

I've heard a lot of people say this is an expensive kit but it had everything i was looking for in one box at a radioshack i was checking out. Comes with

2 infrared light sensors that I couldn't figure out how to use beyond knowing if an object was white or black using the library that came with it.

a motor shield that i think i might need a different one perhaps? better? because of an issue im having.

2 wheels and 2 motors and 1 roll along the ground third wheel thing like a mouse trackball

some batteries

some other stuff but thats the important part.

I also bought this ultrasonic sensor, thought it was a pretty dang good way to detect collisions. This things actually very awesome, it can tell the distance to my ceiling or far wall and farther really accurately. I just check for 2 inch distance and activate collision.

http://www.radioshack.com/radioshack-ultrasonic-range-sensor/2760342.html#.VMsR4mjF91g

I also scavenged two 4 ohm speakers that are in line with eachother so i assume they were equal to one single 8 ohm speaker and used the proper resister for that calculation. I can play 8 bit sounds through these and have a few short songs it plays like part of the mario theme.

and lastly an infrared receiver that i took from an airhogs remote control helicopter i had. It properly receives ir codes and a library i have helps me decode it and do actions.

So the robot works autonomously and that was my goal in putting this all together. It moves forward and if it detects collision then it turns left. I can also control it myself with my samsung tv remote or my android phone that has a tv remote app that i use for the same tv (same codes) but i can program any ir codes to work with the robot.

My problems with my robot so far.

it seems unable to move forward and use the ultrasonic sensor at the same time, I'm hoping this is just a program error on my end. To get around this setback that i hope is not an incompatability with parts, I simply move the robot forward for one second then power down the motors and wait long enough for the ultrasonic to get its turn and get the distance reading, then decide if it should move for a second forward or for a second to the left if a collision is detected, repeat.

I think it would be a lot easier to use the motors and the ultrasonic sensors at the same time, its a lot less jerky.

The robot sees in pretty much a straight line forward which is a setback of the ultrasonic sensors without sweeping, and my current method of autonamousy for the robot gets it stuck on objects it cant see on the sides of it.

What details can I give you guys to help me maybe find the answer to some of these issues. I'll post the full code but my labtop overheated earlier and i lost about an hour of code which got me my finished product intelligence. I'll redo that and post what I have. I'll post pics too.

Well done: sounds like that was quite a learning experience for you.

Here's a wild guess until you post your code: the fact that you can't use the ultrasound while you're on the move, might be due to the use of delay(). When a delay() is in play, nothing else happens. You should look at Blink Without Delay to see how to get round that problem.

(But that's just a guess.....)

Thanks for the post JimboZA, I can't actually use the delays to delay my robot in between the sonar and moving, instead i count seconds that go by by esstially doing this

unsigned long moveCurrentMillis = millis();
if(moveCurrentMillis - movePreviousMillis > MOVE_INTERVAL)
{
    movePreviousMillis = moveCurrentMillis;  
   
}

and yeah was a great learning experience for me, i always use forums as a last option incase i hit a wall, but i was able to achieve the whole thing without any outside help, just a bunch of reading and web surfing, trial and error. Was an awesome experience, I even edited some c code at one point to get two libraries to work together, was amazed how similar arduino programming feels to my native language actionscript 3.0 where i've made tons of flash games prior.

actually since my current code is the bulk of stuff to look at ill go ahead and post the whole thing linked. This code does not currently get the autonomous i was able to achieve as its an hour before because I lost an hour of programming earlier. I'll still post the updated code when I finish it.

http://pastebin.com/LZa3WV0c

Well I’m not fully versed in the arduino programming language so it took awhile to get back my lost progress, but I did it! My robot has a freewill mode that when activated makes it move forward when no object is detected and turn left when one is detected.

But if I don’t stop my robots motors before attempting to activate the ultrasonic sensor, the sensor doesn’t work! I am 90% sure this is a hardware problem due to incompatibility or constraints because I don’t see how my programming could be causing this issue.

Will you guys please help me find the issue? what should I post? My motorshield connects directly to my arduino uno (it lays on top of it and connects to several pins.) The rest of my connections I connect to the motorshield including the ultrasonic sensor which i put into pin 7. I’m 90% sure the motorshield uses some of the arduinos pins or something similar for the motors, overriding. So I think the problem therein lies?

heres just the loop with the ir receiver stuff omitted for space

void loop() 
{
  long RangeInInches;
  long RangeInCentimeters;
  ultrasonicCount++;
  if(ultrasonicCount >= ultrasonicCountMax)
  {
    ultrasonicCount = 0;
    
    ultrasonic.DistanceMeasure();// get the current signal time;
    RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
  
    if(freewill == true)
     {
       if(RangeInInches <= 5)
       {
         if(move_count == 0)
         {
           movingForward = false;
           movingLeft = true;
           movingRight = false;
           movingBackward = false;
         }
         ledState = HIGH;
         digitalWrite(RED_LED, ledState);
       } else {
         if(move_count == 0)
         {
           movingForward = true;
           movingLeft = false;
           movingRight = false;
           movingBackward = false;
         }
         ledState = LOW;
         digitalWrite(RED_LED, ledState); 
       }
     }
   }
   
  unsigned long moveCurrentMillis = millis();
  if(moveCurrentMillis - movePreviousMillis > MOVE_INTERVAL)
  {
    movePreviousMillis = moveCurrentMillis;  
  
    if((movingForward == true || movingBackward == true)||(movingLeft == true || movingRight == true))
    {
       if(move_count >= MOVE_COUNT_MAX)
       {
          line_following.all_stop();
          movingForward = false;
          movingLeft = false;
          movingRight = false;
          movingBackward = false;
          dont_move_count = 0;
       }
       else
       {
         move_count++;
       }
       
       
    }
       if(dont_move_count >= DONT_MOVE_COUNT_MAX)
       {
          line_following.all_stop();
          movingForward = false;
          movingLeft = false;
          movingRight = false;
          movingBackward = false;
          move_count = 0;
       }
       else
       {
         dont_move_count++;
       }
   }
  
    if(movingForward == true)
      line_following.go_backward(robot_move_speed);
    if(movingLeft == true)
      line_following.turn_left(turn_rate); 
    if(movingRight == true)
      line_following.turn_right(turn_rate);
    if(movingBackward == true)
      line_following.go_forward(robot_move_speed);

}

and heres the full code: http://pastebin.com/TASexJyV

Video

http://vid777.photobucket.com/albums/yy56/alecz127/Mobile%20Uploads/20150204_130219_zps9aotysv7.mp4

Hi, Alecz, well done mate, not the prettiest robot , but hey it works.

It would be good if you posted your entire code, if it won't fit then attach it, using the attach facility in the REPLY, not QUICK REPLY window.

There may be a conflict with timers and library functions causing your erratic operation, also you may have a power supply problem as you add hardware.

You could get your ultrasonic sensor to scan by mounting it on a small servo, they swing through 180Deg, so you could have it parked at 90 and then scan left and right.

Tom...... :)