Notifications
Clear all

Robot Car Continously Running Why ?

43 Posts
7 Users
0 Likes
9,014 Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 
Posted by: @gulshan
so Maybe I should try to First make a code that allows me to control the motor through simple wire connections from arduino through the joystick.

I would start with very simple projects making sure I understood the code with each project.  If you understand the code you will find it easy to debug and modify.

https://dronebotworkshop.com/dc-motors-l298n-h-bridge/

They can also be used for 2 way communications.


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

the serial port on my car side is not working I don't know why.

 

I have a question, does the l298n bridge draws too much current from supply cause it drained my battery from 12 v to straight 9 v or i guess my motor driver is damaged. some times it makes the motor rotate like kick start. take a look:-

 


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

@casey

Posted by: @casey

I would start with very simple projects making sure I understood the code with each project.  If you understand the code you will find it easy to debug and modify.

I used the code in that post and motors are still running weirdly.Take a look

Is it because of the motors the I am using here ? they are bo motors 200 RPM. 

The Code :-

/*
L298N Motor Control Demonstration with Joystick
L298N-Motor-Control-Demo-Joystick.ino
Demonstrates use of Joystick control with Arduino and L298N Motor Controller

DroneBot Workshop 2017
http://dronebotworkshop.com
*/

// Motor A

int enA = 9;
int in1 = 8;
int in2 = 7;

// Motor B

int enB = 3;
int in3 = 5;
int in4 = 4;

// Joystick Input

int joyVert = A0; // Vertical
int joyHorz = A1; // Horizontal

// Motor Speed Values - Start at zero

int MotorSpeed1 = 0;
int MotorSpeed2 = 0;

// Joystick Values - Start at 512 (middle position)

int joyposVert = 512;
int joyposHorz = 512;

void setup()

{

// Set all the motor control pins to outputs

pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

// Start with motors disabled and direction forward

// Motor A

digitalWrite(enA, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Motor B

digitalWrite(enB, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

}

void loop() {

// Read the Joystick X and Y positions

joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);

// Determine if this is a forward or backward motion
// Do this by reading the Verticle Value
// Apply results to MotorSpeed and to Direction

if (joyposVert < 460)
{
// This is Backward

// Set Motor A backward

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

// Set Motor B backward

digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

//Determine Motor Speeds

// As we are going backwards we need to reverse readings

joyposVert = joyposVert - 460; // This produces a negative number
joyposVert = joyposVert * -1; // Make the number positive

MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);

}
else if (joyposVert > 564)
{
// This is Forward

// Set Motor A forward

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set Motor B forward

digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

//Determine Motor Speeds

MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255);

}
else
{
// This is Stopped

MotorSpeed1 = 0;
MotorSpeed2 = 0;

}

// Now do the steering
// The Horizontal position will "weigh" the motor speed
// Values for each motor

if (joyposHorz < 460)
{
// Move Left

// As we are going left we need to reverse readings

joyposHorz = joyposHorz - 460; // This produces a negative number
joyposHorz = joyposHorz * -1; // Make the number positive

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorz, 0, 460, 0, 255);

MotorSpeed1 = MotorSpeed1 - joyposHorz;
MotorSpeed2 = MotorSpeed2 + joyposHorz;

// Don't exceed range of 0-255 for motor speeds

if (MotorSpeed1 < 0)MotorSpeed1 = 0;
if (MotorSpeed2 > 255)MotorSpeed2 = 255;

}
else if (joyposHorz > 564)
{
// Move Right

// Map the number to a value of 255 maximum

joyposHorz = map(joyposHorz, 564, 1023, 0, 255);

MotorSpeed1 = MotorSpeed1 + joyposHorz;
MotorSpeed2 = MotorSpeed2 - joyposHorz;

// Don't exceed range of 0-255 for motor speeds

if (MotorSpeed1 > 255)MotorSpeed1 = 255;
if (MotorSpeed2 < 0)MotorSpeed2 = 0;

}

// Adjust to prevent "buzzing" at very low speed

if (MotorSpeed1 < 8)MotorSpeed1 = 0;
if (MotorSpeed2 < 8)MotorSpeed2 = 0;

// Set the motor speeds

analogWrite(enA, MotorSpeed1);
analogWrite(enB, MotorSpeed2);

}

 

What changes should I make ?

This post was modified 4 years ago by Gulshan

   
ReplyQuote
(@freddie43)
Member
Joined: 4 years ago
Posts: 24
 

@gulshan

My motors are 6v. Are you sure yours can handle 12v?

Have you gone back to basics yet and tried the controller with potentiometers hooked up to the Arduino and sending PWM signals to the motors?

There is a good tutorial at https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

BTW Better to post your code via the link at the bottom of the reply box:  'Choose a files or drag and drop it here'
-
It doesn't clog up the posts then.

This post was modified 4 years ago by Freddie43

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

The code looks the same but I notice you are using a joystick controller shield?
Perhaps the pins used are different to those in the dronebot example?
https://www.allaboutcircuits.com/projects/level-up-arduino-joystick-shield-v2.4/

The motors I think are 5v or 9v although i doubt 12v is the issue as that will probably just make them go extra fast and maybe burn out.  I can't make out your actual wiring from the video.

Check all your wiring to make sure it is correct.

Also found using wireless connection,
https://maker.pro/arduino/projects/funduino-arduino-joystick-shield-controlled-robot


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@gulshan

Not long ago, there was some really good information on how to post formatted code to this forum.  It's not necessary, but if you want people to look at your code to help you, you need to actually help them to help you, by making your posted code easy to read, otherwise no one will look at it.

Here is a link for how to go about presenting your code in this forum:

Sticky post for editing?


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

@gulshan

All you said was "bo motor", so I googled that, and all it says is "battery operated" which isn't very helpful

From the way it's jumping, it looks to me like the PWM frequency might be wrong. Somebody who understands this better than me should look, cuz I don't see where the frequency is being set. 

And I also don't know if those motors are even PWM motors. They might be just regular DC motors. Saying that the motor is Battery Operated doesn't tell you enough about the motors


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@gulshan

Maybe you put some debug Serial.print's after you read the joystick's values, to check them ?

void loop() {
unsigned long currentTime;
static unsigned long time0 = millis();
// Read the Joystick X and Y positions
  joyposVert = analogRead(joyVert); 
joyposHorz = analogRead(joyHorz);
currentT  = millis();
if (currentTime - time0 > 500) {
  time0 = currentTime;
  Serial.print("V="); Serial.println(joyposVert);
  Serial.print("H="); Serial.println(joyposHorz);
  }

...

Eric


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 
Posted by: @zeferby

Maybe you put some debug Serial.print's after you read the joystick's values, to check them ?

Yea, check what they say when you let go of the handles, and make that (+- 5 or so) the "off" position


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
Posted by: @casey

Also found using wireless connection,
https://maker.pro/arduino/projects/funduino-arduino-joystick-shield-controlled-robot

I used this Code too but motors are not even responding and like no data is being transmitted at all. Take a look:-


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
Posted by: @freddie43

My motors are 6v. Are you sure yours can handle 12v?

Have you gone back to basics yet and tried the controller with potentiometers hooked up to the Arduino and sending PWM signals to the motors?

Actually the motors that I am using are 12V 200 RPM Motors an on the Internet I read Somewhere they are called as the Geared BO Motors. by a Buck-Boost Converter I am running them at the 10 volts. I tried to use the motor control using the l298n from the post that bill Posted earlier and they work fine both of them. Take I Look :-

 i am also going to try the code from the Howtomechatronics.com


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
Posted by: @gulshan

 i am also going to try the code from the Howtomechatronics.com

I tried the Howtomechatronics code for the motor control but the results are not as good as expected. Take a Look:-


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
Posted by: @spyder

They might be just regular DC motors

no They have to be the PWM motors Cause I was able to control them Using Potentiometers. Maybe there is some error inside the code or I guess I have to Buy New Robot Chassis.


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
Posted by: @frogandtoad

Here is a link for how to go about presenting your code in this forum:

Sticky post for editing?

Thank You It was Very Helpful


   
ReplyQuote
Page 2 / 3