What seems to be the error in this program? I couldn't be able to run from the codes given by the Youtubers. This is the code.
Code:
//Arduino Bluetooth Controlled Car
//Before uploading the code you have to install the necessary library
//Note - Disconnect the Bluetooth Module before hiting the upload button otherwise you'll get compilation error message.
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install
//After downloading the library open Arduino IDE >> go to sketch >> Include Libray >> ADD. ZIP Libray >> Select the downloaded
//ZIP File >> Open it >> Done
//Now You Can Upload the Code without any problem but make sure the bt module isn't connected with Arduino while uploading code
#include <AFMotor.h>
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command;
void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop(){
if(Serial.available() > 0){
command = Serial.read();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}
void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255);//Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255);//Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void back()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the button
motor2.setSpeed(0); //Define minimum velocity
motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum velocity
motor3.run(RELEASE); //stop the motor when release the button
motor4.setSpeed(0); //Define minimum velocity
motor4.run(RELEASE); //stop the motor when release the button
}
Code:
This is the error. Please help. I am making a project for the expo next year.
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:12: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:13: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:14: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:15: undefined reference to `AF_DCMotor::AF_DCMotor(unsigned char, unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `Stop':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:97: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:98: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:99: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:100: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:101: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:102: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:103: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:104: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `back':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:61: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:62: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:63: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `right':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:85: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:86: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:87: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `forward':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:49: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:50: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:51: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `left':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:73: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:74: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:75: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:76: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:77: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:78: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:79: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\AppData\Local\Temp\cc6mzJoU.ltrans0.ltrans.o: In function `right':
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:88: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:89: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:90: undefined reference to `AF_DCMotor::run(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:91: undefined reference to `AF_DCMotor::setSpeed(unsigned char)'
C:\Users\RJ\Desktop\BLUETOOTH_CAR/BLUETOOTH_CAR.ino:92: undefined reference to `AF_DCMotor::run(unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Last edited by a moderator: