Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Postby ryu_kyo » Thu Aug 18, 2016 10:48 am

Hi, I am a bit new with Arduino coding and electronic stuffs and need some guidance on my line follower project. I am replicating Edubot constructions using Lego bricks and using electronic components below:

Arduino UNO
Cytron 2 Amp Motor Driver Shield
LSS05 sensor
11.1V LiPo battery

Upon uploading the sketch (I got it from the Edubot tutorial) and test the robot. It going too fast, is this because of LiPo battery that I used? Do I need to "step down" the voltage?

I've also tried to use coding below (PID) and could anyone advise on how to modify the code so that it can be used with this shield?

CODE: SELECT_ALL_CODE
float Kp=0,Ki=0,Kd=0;
float error=0, P=0, I=0, D=0, PID_value=0;
float previous_error=0, previous_I=0;
int sensor[5]={0, 0, 0, 0, 0};
int initial_motor_speed=100;

void read_sensor_values(void);
void calculate_pid(void);
void motor_control(void);

void setup()
{
 pinMode(9,OUTPUT); //PWM Pin 1
 pinMode(10,OUTPUT); //PWM Pin 2
 pinMode(4,OUTPUT); //Left Motor Pin 1
 pinMode(5,OUTPUT); //Left Motor Pin 2
 pinMode(6,OUTPUT); //Right Motor Pin 1
 pinMode(7,OUTPUT);  //Right Motor Pin 2
 Serial.begin(9600); //Enable Serial Communications
}

void loop()
{
    read_sensor_values();
    calculate_pid();
    motor_control();
}

void read_sensor_values()
{
  sensor[0]=digitalRead(A0);
  sensor[1]=digitalRead(A1);
  sensor[2]=digitalRead(A2);
  sensor[3]=digitalRead(A3);
  sensor[4]=digitalRead(A4);
 
  if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1))
  error=4;
  else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1))
  error=3;
  else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0))
  error=2;
  else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0))
  error=1;
  else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
  error=0;
  else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
  error=-1;
  else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
  error=-2;
  else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
  error=-3;
  else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
  error=-4;
  else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
    if(error==-4) error=-5;
    else error=5;

}

void calculate_pid()
{
    P = error;
    I = I + previous_I;
    D = error-previous_error;
   
    PID_value = (Kp*P) + (Ki*I) + (Kd*D);
   
    previous_I=I;
    previous_error=error;
}

void motor_control()
{
    // Calculating the effective motor speed:
    int left_motor_speed = initial_motor_speed-PID_value;
    int right_motor_speed = initial_motor_speed+PID_value;
   
    // The motor speed should not exceed the max PWM value
    constrain(left_motor_speed,0,255);
    constrain(right_motor_speed,0,255);
   
   analogWrite(9,initial_motor_speed-PID_value);   //Left Motor Speed
    analogWrite(10,initial_motor_speed+PID_value);  //Right Motor Speed
    //following lines of code are to make the bot move forward
    /*The pin numbers and high, low values might be different
    depending on your connections */
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
}
ryu_kyo
Fledgling
 
Posts: 1
Joined: Wed Aug 17, 2016 5:54 pm

Re: Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Postby ZaM » Wed Aug 24, 2016 5:08 pm

Hi, just set initial_motor_speed lower than 100 and also need to set max PWM value lower than 255.

Explanation for this code, 255 is highest speed and 0 is lowest speed. You can change 255 to 50 for example.
// The motor speed should not exceed the max PWM value
constrain(left_motor_speed,0,255);
constrain(right_motor_speed,0,255);
ZaM
Moderator
 
Posts: 78
Joined: Tue Nov 23, 2010 4:16 pm

Re: Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Postby vidya shini » Tue Feb 13, 2018 4:09 pm

I have cy arduino Uno+ Blue Bee+xbee Shield+2amotor driver...How to Connect This Things and Make a Mobile Control robot...
vidya shini
Newbie
 
Posts: 9
Joined: Tue Feb 13, 2018 4:01 pm

Re: Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Postby Idris » Wed Feb 14, 2018 4:41 pm

Hi vidya shini,

The question is too general. Could you specify which area did you stuck? If you are beginner with Arduino, why not start with very basic first? Understand the concept, digital input output, analog PWM, Serial communication, etc...

We believe there have tons of Arduino online tutorial you can refer to.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Cytron 2 Amp Motor Driver Shield & LSS05 sensors

Postby vidya shini » Sat Feb 17, 2018 5:00 pm

Idris WROTE:Hi vidya shini,

The question is too general. Could you specify which area did you stuck? If you are beginner with Arduino, why not start with very basic first? Understand the concept, digital input output, analog PWM, Serial communication, etc...

We believe there have tons of Arduino online tutorial you can refer to.


actually my project about detected obstacle using ultrasonic.
1)ultrasonic sensor should detect obstacle and send msg to my num using gsm 900A module.
2)the wheel robot should move to detect obstacle..
component that i bought in cytron
1 sk40c kit
2 cytron arduino
3 xbee shield
4 high range ultrasonic sensor module 1013
5 bluetooth bee with module
6 motor shield 2am motor
vidya shini
Newbie
 
Posts: 9
Joined: Tue Feb 13, 2018 4:01 pm


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 16 guests

cron