- This topic has 9 replies, 2 voices, and was last updated 1 year, 9 months ago by
Keith.
- AuthorPosts
- November 15, 2023 at 1:55 pm #1921
Keith
KeymasterHi Ammar, can I check if you used my sketch or you drafted your own sketch?
1) if you have used my sketched, is it Proj_8a or Proj_8b?
2) if you have your own sketch, can you paste your sketch here so I can see what is wrong?Also, the left motors are working and you are using 6 AA batteries?
November 15, 2023 at 2:01 pm #1922ammar
Participant- I used your 8a sketch. I managed to get it the motors to run by changing the pin numbers. Your sketch uses pins 4 and 5 for left motor, and 9 and 2 for right motor. However, the right motors are still not following the instructions. It just runs on its own
November 15, 2023 at 3:13 pm #1923Keith
KeymasterTo clarify, the way your car is: Left motors (front & back) are following the sketch which is forward 2s, pause 1s, backward 2s, pause 1s, backward 2s, pause 1s, forward 2s, pause 3s. Right motors are not following command in sketch and are both rotating continuously in one direction? Can you share your sketch here so I can help to troubleshoot? Since, the motors are moving, it shouldn’t be a hardware issue.
November 16, 2023 at 6:17 pm #1925ammar
Participant/*
4WD Bluetooth Robot Car
Lesson : 3.15
Project : 8a
Project Name : DC Motor Control
*/const int leftMotor_ctrl = 4; // pin to control direction of B motor
const int leftMotor_pwm = 5; // pin to control PWM of B motor
const int rightMotor_ctrl = 7; // pin to control direction of A motor
const int rightMotor_pwm = 6; // pin to control PWM of A motorvoid setup() {
pinMode(leftMotor_ctrl, OUTPUT); // set pinMode for all motor control pins
pinMode(leftMotor_pwm, OUTPUT);
pinMode(rightMotor_ctrl, OUTPUT);
pinMode(rightMotor_pwm, OUTPUT);
}void loop() {
// Rotate all 4 motor in the same direction at the same speed for 2s. We are designating this as forward direction
digitalWrite(leftMotor_ctrl, HIGH); // set the direction control pin of B motor to HIGH
analogWrite(leftMotor_pwm, 100); // set the PWM control speed of B motor to 200. remember this value can be between 0 and 255.
digitalWrite(rightMotor_ctrl, HIGH); // set the direction control pin of A motor to HIGH
analogWrite(rightMotor_pwm, 100); // set the PWM control speed of A motor to 200
delay(2000);// Stop all motors for 1s
analogWrite(leftMotor_pwm, 0);//set the PWM control speed of B motor to 0
analogWrite(rightMotor_pwm, 0);//set the PWM control speed of A motor to 0
delay(1000);// Rotate all 4 motor in the same direction opposite to before at the same speed for 2s. This will be backward direction
digitalWrite(leftMotor_ctrl, LOW); // set the direction control pin of B motor to LOW
analogWrite(leftMotor_pwm, 100); // set the PWM control speed of B motor to 200
digitalWrite(rightMotor_ctrl, LOW); // set the direction control pin of A motor to LOW
analogWrite(rightMotor_pwm, 100); // set the PWM control speed of A motor to 200
delay(2000);// Stop all motors for 1s
analogWrite(leftMotor_pwm, 0);//set the PWM control speed of B motor to 0
analogWrite(rightMotor_pwm, 0);//set the PWM control speed of A motor to 0
delay(1000);// Rotate left motors backward and right motors forward. This turns car left for 2s.
digitalWrite(leftMotor_ctrl, LOW); // set the direction control pin of B motor to LOW
analogWrite(leftMotor_pwm, 100); // set the PWM control speed of B motor to 200
digitalWrite(rightMotor_ctrl, HIGH); // set the direction control pin of A motor to HIGH
analogWrite(rightMotor_pwm, 100); // set the PWM control speed of A motor to 200
delay(2000);// Stop all motors for 1s
analogWrite(leftMotor_pwm, 0);//set the PWM control speed of B motor to 0
analogWrite(rightMotor_pwm, 0);//set the PWM control speed of A motor to 0
delay(1000);// Rotate right motors backward and left motors forward. This turns car right for 2s.
digitalWrite(leftMotor_ctrl, HIGH); // set the direction control pin of B motor to HIGH
analogWrite(leftMotor_pwm, 100); // set the PWM control speed of B motor to 200
digitalWrite(rightMotor_ctrl, LOW); // set the direction control pin of A motor to LOW
analogWrite(rightMotor_pwm, 100); // set the PWM control speed of A motor to 200
delay(2000);// Stop all motors for 3s
analogWrite(leftMotor_pwm, 0);//set the PWM control speed of B motor to 0
analogWrite(rightMotor_pwm, 0);//set the PWM control speed of A motor to 0
delay(3000);}
November 17, 2023 at 6:03 am #1926Keith
KeymasterHi Ammar, thanks for providing the code. Can I check why have you used pin 7 and 6 for rightMotor_ctrl and rightMotor_pwm respectively instead of 2 and 9?
If you are connecting the motors to the Arduino board through the motor shield, you need to use pins 4, 5, 2 and 9. These configurations are hardwired due to internal circuitry of the motor shield. I also provided the explanation between 20 sec to 50 sec of the lesson. Let me know if using pin 2 and 9 causes any issue.November 17, 2023 at 6:20 am #1927ammar
ParticipantPreviously I used 9 and 2, the right motors don’t work at all so I tried different pins.
November 17, 2023 at 9:56 am #1928Keith
KeymasterCan you try const int rightMotor_ctrl = 2; const int rightMotor_pwm = 9; again?
This configuration should work. I used the same configuration for both projects in this lesson and the challenges under section 4.
Make sure
i) the connections are firm
ii) the blue & red jumper caps are plugged in
iii) none of the 6 batteries are out of juice.
You can try to increase the pwm to 200 from 100 if the wheels are not moving.
November 19, 2023 at 3:41 am #1929ammar
ParticipantI’ve tried all your suggestions, ive also tried increasing the speed to 300 but still no movement by the motor. I even swapped the connectors, left motor to a pins and right motor to b pin. the sketch is only providing output for B pins somehow. I apologise but i really need to rush this.
November 20, 2023 at 6:30 am #1930Keith
KeymasterHi Ammar, I will close this query as I have separately addressed it with you. For record and benefit of other students, the issue was that the manufacturer has updated their Motor Driver Board as can be seen on the Board. Due to this change, the sketch has to be updated such that:
pin 4 controls direction of spin of motors connected to point B
pin 5 controls speed of motors connected to point B
pin 2 controls direction of spin of motors connected to point A
pin 6 controls speed of motors connected to point A (instead of pin 9 which is the case for Motor Driver Board v1)
I will also be updating the lessons.
- AuthorPosts
You must be logged in to reply to this topic. Login here