HI!,
I have a problem about this code below
#include<AFMotor.h>
#define Lir 6
#define Rir 7
#define trig 2
#define echo 4
AF_DCMotor RF (4);
AF_DCMotor RR (3);
AF_DCMotor LF (1);
AF_DCMotor LR (2);
byte mspeed = 255;
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(Lir, INPUT);
pinMode(Rir, INPUT);
Serial.begin(9600);
RF.setSpeed(mspeed);
RR.setSpeed(mspeed);
LF.setSpeed(mspeed);
LR.setSpeed(mspeed);
goFront();
}
i'm testing my components before starting my project. when i testing my motor driver.
i included pinMode for my ir sensors and the ultrasonic sensor.after i including the pinMode my motors are not working. when i comment them my motors are running good.what is the reason for that?
The easier you make it to read and copy the code the more likely it is that you will get help
Please follow the advice given in the link below when posting code , use code tags and post the code here
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
you forgot to add newPing library..
you are using ultrasonic sensors so , us should include newping library.
ok,but including the pinMode motors R not work !
send me the circuit diagram and all the parts
give me some time i will code and submit...
bro upload this sketch and try ,
first check the pins properly i may assigned the pins inorder
#include <AFMotor.h>
#include <NewPing.h>
#define RIGHT 6
#define LEFT 7
#define TRIGGER_PIN A0
#define ECHO_PIN A1
#define MAX_DISTANCE 100
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
AF_DCMotor Motor1(1, MOTOR12_1KHZ);
AF_DCMotor Motor2(2, MOTOR12_1KHZ);
AF_DCMotor Motor3(3, MOTOR34_1KHZ);
AF_DCMotor Motor4(4, MOTOR34_1KHZ);
void setup()
{
Serial.begin(9600);
pinMode(RIGHT, INPUT);
pinMode(LEFT, INPUT);
}
void loop()
{
unsigned int distance = sonar.ping_cm();
Serial.print("distance");
Serial.println(distance);
int Right_Value = digitalRead(RIGHT);
int Left_Value = digitalRead(LEFT);
Serial.print("RIGHT");
Serial.println(Right_Value);
Serial.print("LEFT");
Serial.println(Left_Value);
if((Right_Value==0) && (distance>=10 && distance<=30)&&(Left_Value==0)){
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(200);
Motor3.run(FORWARD);
Motor4.setSpeed(200);
Motor4.run(FORWARD);
}else if((Right_Value==0) && (Left_Value==1)) {
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(0);
Motor3.run(BACKWARD);
Motor4.setSpeed(0);
Motor4.run(BACKWARD);
}else if((Right_Value==1)&&(Left_Value==0)) {
Motor1.setSpeed(0);
Motor1.run(BACKWARD);
Motor2.setSpeed(0);
Motor2.run(BACKWARD);
Motor3.setSpeed(200);
Motor3.run(FORWARD);
Motor4.setSpeed(200);
Motor4.run(FORWARD);
}else if((Right_Value==1)&&(Left_Value==1)) {
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}else if((Right_Value==0) && (Left_Value==0)) {
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(200);
Motor3.run(BACKWARD);
Motor4.setSpeed(200);
Motor4.run(BACKWARD);
}
else if(distance > 1 && distance < 10) {
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}
}
If you are going to post code then please do it properly
The easier you make it to read and copy the code the more likely it is that you will get help
Please follow the advice given in the link below when posting code , use code tags and post the code here
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
thanx bro,but when goes forward 1 motor is not working!
ok i will fix you also check your motor driver
my motor driver is working goood
because i made a bluetooth car last week .