Oh yeah, the reason why this is a task connecting the buttons is because I'm trying to get the left and right buttons on one side, and the cw and ccw (forward and backwards) on the other. Also my Arduino Nano is in the middle.
Good evening you all. I'm trying to figure out a code, to make my 2 front wheels to turn at a certain speed. The previous code is to control the speed for the back wheels. The following is an experimentation for turning the front wheels at a moderate speed. Can I please get some help with this please?
type or paste code here
#define mAl 5 // PWM motor pin IN2
#define mAr 6 // PWM motor pin IN1
#define TsA 3 // button for clockwise motor A
#define BsA 2 // button for counter clockwise motor A
#define mBl 11 // PWM motor pin IN2
#define mBr 10 //PWM motor pin IN1
#define LsB 9 // button for counter clockwise motor B
#define RsB 8 // button for clockwise motor B
void setup() {
Serial.begin(9600);
pinMode(mAl, OUTPUT);
pinMode(mAr, OUTPUT);
pinMode(TsA, INPUT);
pinMode(BsA, INPUT);
pinMode(mBl, OUTPUT);
pinMode(mBr, OUTPUT);
pinMode(LsB, INPUT);
pinMode(RsB, INPUT);
digitalWrite(mBl, HIGH);
digitalWrite(mBr, LOW);
analogWrite(mBl, 60);
} analogWrite(mBr, 60);
void loop() {
int Pot = analogRead(A0);
Pot = map(Pot, 0, 1023, 0, 255);
Serial.println(Pot);
int top = digitalRead(TsA);
int bottom = digitalRead(BsA);
if(top == LOW && bottom == HIGH)
{
analogWrite(mAl, Pot);
digitalWrite(mAr,LOW);
}
else if(top == HIGH && bottom == LOW)
{
digitalWrite(mAl, LOW);
analogWrite(mAr, Pot);
}
else{
digitalWrite(mAl, HIGH);
digitalWrite(mAr,HIGH);
}
}
To do this you must measure the speed of the wheels. All you are doing is changing the power going to the motors.
Yes sir, so what command can I use on this part?
Make sure mL and mR are on the same timer, use pins 3 and 11, 9 and 10 or 5 and 6. The PWM frequency from pins 3 & 11 (timer 2), and 9 &10 (timer 1), is about 488 Hz, from pins 5 & 6 (timer 0), 976 Hz. Mixing timers can make the difference you are seeing.
Use pins 3 & 11 for one motor, 9 & 10 for the other.
Thanks so much. I'll try when I get off of work.
So let me get this right, since 5 and 6 is already connected to mAL and mAR (motor A Left and Right). The front wheels I want to turn left and right at a slower pace, has to be connected to pins, 3, 9-11? What's the command to make this happen? Is it the in command, I'm attempting to load, because it's not working.
Okay, sorry. Finally made it home. So is this a valid command for a change of speed? I think since one is inside of the {, it's one of the reasons why it's not working.
Found a good Arduino reference page. Pins 3, 9-11 are 480 Hz. Pins 5 and 6 and 980 Hz. I got the code to go through. Like I thought, since the analogWrite command was inside the bracket that's why it wasn't working. Just have to do some extensive wiring to connect my, " turn left and right" buttons
.
Okay, this should be my last question. I saw a setup for NRF24L01, a transmitter and receiver. How do I add that code, to the code I have already setup?
Thanks so much
. Just realized I'm going to have to get a dual motor driver. I just got the first driver I saw, after I got a dc motor, while trying to conjure up a project. I wanted to buy another single motor board, but a dual motor board will take up less space. Trying to figure out a way to eliminate all this space between the adapter and the antenna also. I'm going to have to find some kind of steeple shape, to fill the void.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.