Elegoo smart car modding sketch won't upload - adding libraries to sketches

Hi all,

I’m trying to make some modifications to this elegoo smart robot car I bought but I’m having trouble uploading my sketch.

The odd thing is I can upload the original sketch that was provided for the elegoo to the elegoo uno R3 board. the elegoo runs on an UNO R3 from what i can tell.

However When I upload my modified sketch I get this error:

avrdude: ser_open(): can’t open device “\.\COM3”: The system cannot find the file specified.

I can upload my modified sketch to the other arduino uno that came with my arduino starter kit but not the elegoo smart robot car’s board

I’m wondering if it has to do with this library I included in my sketch; newping.h

any tips would be much appreciated!

thanks,

Tim,

#include <NewPing.h>

//www.elegoo.com

#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define LED 13
#define TRIGGER_PIN 12
#define ECHO_PIN 13
#define MAX_DISTANCE 400

unsigned char carSpeedRotate = 150;
unsigned char carSpeedDrive = 100;
bool state = LOW;
float distance, duration;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int iterations = 5;

void forward(){ 
  analogWrite(ENA,carSpeedDrive);
  analogWrite(ENB,carSpeedDrive);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  Serial.println("Forward");
}

void back(){
  analogWrite(ENA,carSpeedDrive);
  analogWrite(ENB,carSpeedDrive);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Back");
}

void left(){
  analogWrite(ENA,carSpeedRotate);
  analogWrite(ENB,carSpeedRotate);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  Serial.println("Left");
}

void right(){
  analogWrite(ENA,carSpeedRotate);
  analogWrite(ENB,carSpeedRotate);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Right");
}

void stop(){
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);
  Serial.println("Stop!");
}

void stateChange(){
  state = !state;
  digitalWrite(LED, state);
  Serial.println("Light");  
}

void setup() { 
  Serial.begin(9600);
  pinMode(LED, OUTPUT); 
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  stop();
}

void loop() { 
  if(Serial.available())
  {
    char getstr = Serial.read();
    switch(getstr){
      case 'f': forward(); break;
      case 'b': back();   break;
      case 'l': left();   break;
      case 'r': right();  break;
      case 's': stop();   break;
      case 'a': stateChange(); break;
      default:  break;
    }
  }
     
  duration = sonar.ping_median(iterations);
  
  // Determine distance from duration
  // Use 343 metres per second as speed of sound
  
  distance = (duration / 2) * 0.0343;
  
  // Send results to Serial Monitor
  Serial.print("Distance = ");
  if (distance >= 400 || distance <= 2) {
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    delay(500);
  }
  delay(500);
}

(deleted)

Hey,

I just have com4

well yeah so i have com3 when i plug in the starter kit arduino uno and com4 when i plug in the elegoo smart car unro r3

thanks,