Let's Make Robots!

Help me please with ugv robot chassis from DAGU

Hello im newbie and I come from indonesia

Hello I am new to arduino but I am interested with how to build robot, .. I have made ​​2 robot using arduino unoR3 but when I buy an robot chassis car from dagu that uses steering wheels in front of car with two dc motors ( one for steering with skb-220 pot and one more for move forward and move backwards ) with micro magician robot controller using atmega168 I confused to program this robot controller to be able to run well with my chassis car.

I had great difficulty in programming how to control the dc motor with potentiometer especially in controlling the position of dc motors, how dc motors that move to the right, center and left.and then I have asked the Mr Russell Cameron and I get code like this:

car impact and edge detection

#include "Constants.h"
#include "IOpins.h"

// define global variables

unsigned long time,IRtimer;
//int q1,q2,q3,q4,qt;
int qt;
int steer;
int angle;
int impact,impv,impc;
int c,av[avn*2];
int x,xav,X;
int y,yav,Y;
int motor;
byte IR;

void setup()
  for(int i=0;i<100;i++)

void loop()

void impactdetection()
  // array "av" use to store values for averaging
  // constant "avn" is the number of values to be averaged
  // instant angle reading stored as "ang"
  // instant impact reading stored as "imp"

  //-------------------------------------------------------- Filter sensor data to reduce noise ------------------------------------
  av[c]=analogRead(0)-537;                                // read accelerometer x-axis
  av[c+avn]=analogRead(1)-583;                            // read accelerometer y-axis

  c++;                                                    // increment averaging array index
  if(c>(avn-1)) c=0;                                      // reset index

  for(int i=0;i<avn;i++)                                  // average x-axis and y-axis values to filter noise                                
    x+=av[i];                                             // sum x-axis values
    y+=av[avn+i];                                         // sum y-axis values
  x/=avn;                                                 // x=mean x-axis
  y/=avn;                                                 // y=mean y-axis

  int oi=impv;                                            // store previous impact value prior to update
  int ang=int(atan2(double(y),double(x))*180/PI);         // direction of impact: left=90 degrees - forward=0 degrees - right=-90 degrees
  impv=sqrt(sq(x)+sq(y));                                 // magnitude of impact: hypotenuse of x and y values

  //---------------------------------------------------------- due to body vibration only initial impact values useful ----------------
  int differential=oi-impact;                             // differential = old impact value - current impact value
  if(differential>imp)                                    // compare previous average to present value
    if(impc==0) time=millis();
    impc++;                                               // increment impact counter if impact detected
    if (impc==impsn)                                      // impact=impsn value, later values discarded due to vibration
      Serial.print("\t Y:");
      Serial.print("\t Impact:");
      Serial.print("\t Angle:");
      impc=0;                                               // reset impact counter when vibration subsides

void impactresponse()
  if (impact>0)
    if(millis()-time<500)                                  // stop for 500mS after impact
      analogWrite(steerA,0);                               // turn off steering motor
      analogWrite(motorA,255);                             // engage electronic braking
      motor=0;                                             // reset motor speed
    else                                                   // time greater than 500mS
      if(millis()-time<2500)                               // from 500-2300mS after impact
        if(X>0)                                            // increment motor speed to move away from object
          if (motor<-220) motor=-220;
          if(motor>motormax) motor=motormax;

        if(Y<0)                                            // increment steering motor speed to move away from object
          if (steer<-200) steer=-200;
          if(steer>200) steer=200;
        if(millis()-time>2200 && motor<0) motor=0;
      else                                                  // time from impact greater than 2000mS
        impact=0;                                           // reset impact response
    if(steer>3) steer-=4;
    if(steer<-3) steer+=2;
    if(motor<motormax) motor++;

  if (motor>0)

void steering()
  int steering=analogRead(steerP);
  int steerspeed=(steer+512-steering)*3;
  if (steering<spright && steerspeed<0) steerspeed=0;
  if (steering>spleft && steerspeed>0) steerspeed=0;

  if (steerspeed>steermax) steerspeed=steermax;
  if (steerspeed<-steermax) steerspeed=-steermax;

  //Serial.print("Steering pot:"); Serial.print(steering);
  //Serial.print("\t Steer speed:"); Serial.println(steerspeed);

  if (steerspeed>0)

int q1,q2,q3,q4,t,m;
void linesensor()
  if(t>2 && m==0)
  if(t>4 && m==1)

with constant.h like this :

#define steermax   250    // maximum PWM value for steering motor
#define motormax   180    // maximum PWM value for drive motor
#define spright    295    // steering position minimum value
#define spleft     750    // steering position maximum value
#define avn         35    // number of samples for averaging
#define imp         35    // minimum impact value
#define impsn        1    // impact sample number

and IOPins.h like this :

#define motorA      3    // PWM     output - drive motor pin  A
#define motorB      11   // PWM     output - drive motor pin  B

#define steerA      5    // PWM     output - steer motor pin  A
#define steerB      6    // PWM     output - steer motor pin  B
#define steerP      7    // Analog   input - steer position   pot

#define IRleds      2    // Digital output - IR    LEDs
#define sensQ1      6    // Analog   input - photo transistor 1
#define sensQ2      5    // Analog   input - photo transistor 2
#define sensQ3      4    // Analog   input - photo transistor 3
#define sensQ4      3    // Analog   input - photo transistor 4

#define Xaxis       0    // Analog   input - accellerometer   X
#define Yaxis       1    // Analog   input - accellerometer   Y
#define Zaxis       2    // Analog   input - accellerometer   Z

robot runs fine but when the robot hit something, the robot is just go ahead and just turn left, actually i want the robot can
moves backward and steering front wheels turned to the left or to the right then stop and move forward when he hits something.
Is there anyone here who has ever tried to make this robot, ... can share your knowledge to me and teach me how to make this robot.

I want my robot can moves like this site http://www.youtube.com/watch?v=bd1FIBiKBTY and my robot just move like this http://www.youtube.com/watch?v=5KXwgajWRAc&feature=youtu.be

please help me to programmed this microcontroller

forgive me if my english is not good I hope someone can help me in this forum to solve my problem


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
If you read the manual for the controller you will find the library gives you a command for motor control. If you look at the microM examples you will find sample code for controlling the motors.

Look, buddy, you have to take Oddbot's advice here, you are going to have to learn code step-by-step. I am happy to reply to emails, but A) you asked about the Tadpole steering (which is incredibly different that the car you have) and B) you were asking for more code!

You can email, G+, IM, DM or Tweet to anyone you like, but it is not going to make code magically appear!

Sir I am a beginner and i dont know about c language and i dont know how to start learning that. cause i learn by my self not anyone can teach me here so im try to learn form other people,................yesterday Mr oddbot send link to arduino reference i was read it but im still confusing how to use A3906 dc motor driver pin out except L293D.

Im just try to learn and try to understanding the other people code to move their robot cause in here robot spare part is still very expensive and spare parts are rarely sell.But any way thanks for your answer and forgive me if I'm disturbing your time...

I hope you're not mad at me

You need to understand, we taught ourself to program the Arduino, no one taught us, it is not that hard, you are simply not making the effort!

Start by looking at the example codes supplied with the Arduino IDE. When you understand how to blink a LED then go onto making it fade on and off.

There is no short cut.

I have to make my dc motor can move forward and reverse with HIGH and LOW commands with my experiments code like this:

#include <microM.h>
int BackMotorForward=5;
int BackMotorReverse=7;
int FrontMotorLeft=6;
int FrontMotorRight=8;

void setup()
void loop()
   digitalWrite(FrontMotorRight,LOW);        // turn the front motor off
   digitalWrite(BackMotorForward, HIGH);   // turn the back motor forward
   digitalWrite(BackMotorReverse, LOW);   // turn the back motor reverse
    digitalWrite(FrontMotorLeft,HIGH);         // turn the front motor left
   delay(10000);               // wait for  10 seconds
   digitalWrite(FrontMotorRight, HIGH);   // turn the front motor right
   digitalWrite(BackMotorForward, LOW);  // turn the back motor off
   digitalWrite(BackMotorReverse, HIGH); // turn the back motor reverse
   digitalWrite(FrontMotorLeft,LOW);     // turn the front motor off

Did my code is right sir??it is just to make me understand how this microcontroller and dc motor work but im still confusing about steering dc motor using potentiometer feedback especially how to make the dc motor can run to the center position like dc motor servo, so i try to ask mr chris carpenter,i hope the dc motor can be driven potentiometer like servo motor without PID.

I am glad you want to reply every my questions sir, im sorry if my english is not good sir


As I told you this code is very old and written before I wrote the microM library. As you are a beginner, sample code written by someone else will only confuse you.

You will be far better off writing your own code than trying to understand mine and it will be easier for you if you use the microM library. Start simple and learn to write one part of the program at a time.

  • If you have not programmed before, learn to blink the D13 LED on the board.
  • learn to use the microM library to control the motors (look at the microM library example code).
  • learn to use the feedback pot in the steering to control speed and direction of steering motor.
  • learn to use the accelerometer (look at MicroM library example code).
  • learn to use the front line following sensors.

If I could give you code that did exactly what you wanted you still would not understand it until you have done these things.


I have try to change motor-- ; if (motor<-220) motor=-220; value in to 225, 0, 170 and delete but the dc motor still would not to run backward and i have try to combine between microM library and your code but still the same

I have to add define motormin with 0 values in constant.h but my problem still the same the dc motor cannot run backward until I burning out my battery case after that I try to asked you again how to program this microcontroller because I was afraid if i burning out my microcontroller.
in making a robot with arduino usually I copy paste from existing programs and seek to modify or add something to my robot and I am trying to understand the meaning of the code is,
I know atmega about 2 months sir
sorry sir
I still can not make my own code because I was so blind in c language and no teacher to teach me because usually i am learned from internet by looking then copy the code and understanding or modify that code help me sir how to make the program code as youtube

these robots - robots that I have been made from copying the program code and I modified the code from internet sir


If these robots without program taken from Herbie photovore


You cannot learn anything by using other peoples code.

Arduino C is very easy but you must take the time to read how to use the commands.
Bookmark this page: http://arduino.cc/en/Reference/HomePage

Download and read the Micro Magician manual:

If you are not willing to read these and learn then we cannot help you.


Ok sir thanks for your advice and i will try to learn from your advice hope i can to program my robot by my self im interested with micro magician robot controller because this controller just use 5 volts power supply its very can save my battery power.

I am not the right person to help with your robot.  There are a lot of people who can offer much better help than I.  But I do have some advice for you on how to ask your questions.  First, use a subject that describes the problem.  "Pls help"  doesn't give any idea what the problem is.  Second, spell out your words instead of using text speak abbreviations.  It helps to avoid confusion, especially if English is not your native language.  Third, your English is not that bad.  Just try your best with it and if the information a person needs to help you is there, they can find it.

Good luck!