cant figure out whats wrong with my code

This is the error message i keep getting when i try to compile

Arduino: 1.6.8 (Windows XP), Board: "Arduino/Genuino Uno"

C:\DOCUME~1\TAYLOR~1\LOCALS~1\Temp\build99571413ea8aeecab8c7a160a08e1ec4.tmp/core\core.a(main.cpp.o): In function `main':

C:\Documents and Settings\Taylor Miller\My Documents\Downloads\arduino-1.6.8-windows\arduino-1.6.8\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

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.

int forward = 13; // Pin 12 - Forward
int reverse = 12; // Pin 11 - Reverse
int left = 8; // Pin 10 - Left
int right = 7; // Pin 9 - Right

char val; // Variable to receive data from the serial port

void setup() {

  // initialize the digital pins as output
  pinMode(forward, OUTPUT);
  pinMode(reverse, OUTPUT);
  pinMode(left, OUTPUT);
  pinMode(right, OUTPUT); Serial.begin(9600); // Start serial communication at 9600bps

// Fordward action
void go_forward() {
  digitalWrite(forward, HIGH);
  digitalWrite(reverse, LOW);

// Reverse action
void go_reverse() {
  digitalWrite(reverse, HIGH);
  digitalWrite(forward, LOW);

// Left action
void go_left() {
  digitalWrite(left, HIGH);
  digitalWrite(right, LOW);

// Right action
void go_right() {
  digitalWrite(right, HIGH);
  digitalWrite(left, LOW);

// Stop turn action
void stop_turn() {
  digitalWrite(right, LOW);
  digitalWrite(left, LOW);

// Stop car
void stop_car() {
  digitalWrite(forward, LOW);
  digitalWrite(reverse, LOW);
  digitalWrite(right, LOW);
  digitalWrite(left, LOW);

// Read serial port and perform command
void performCommand() {
  if (Serial.available()) {
    val =;
  } else if (val == 'w') { // Forward go_forward(); }
  } else if (val == 's') { // Backward go_reverse(); }
  } else if (val == 'd') { // Right go_right(); }
  } else if (val == 'a') { // Left go_left(); }
  } else if (val == 'l') { // Stop Turn stop_turn(); }
  } else if (val == 'k') { // Stop stop_car(); }

    void loop();

There are several things wrong.

  1. You didn’t tell us what doesn’t work
  2. Read "how to post code properly" and then edit your message and put your code in code tags so that it is easier to read and copy/paste.
  3. Use the Auto Format tool in the IDE to clean up your code
  4. The line which begins with " } if (val == ‘w’) { //" is one very long line with lots of statements on it. You should never do this, especially since the // turns all of them into a comment and none of them get compiled. Put each statement on a line of its own.


Thanks Pete! I'm still kinda new to the arduino world sorry for the mistakes in the original post.

OK. You've got the code tags which is good. But there's still points 3 and 4 to do. The performCommand function isn't going to work until you've handled point 4.


I've tried everything I know of to fix I and it still won't compile

Post your current code.


  } else if (val == 's') { // Backward go_reverse();

Do you still have lines that look like this? The // makes everything on the same line after it a comment. So you have no command to run if that condition is true. You've commented out the command.

The clue's in the error message: there's no loop() function.

Well, there is, but it's inside performCommand() because the braces are out of whack.

The very last line of code is the closing brace of performCommand(), and loop()'s just above that (also on a pair of braces, strangely.)