Search code examples
arduinoarduino-unoarduino-idearduino-esp8266

Arduino "An Error Occured While Uploading The Sketch" trying to control stepper motor with two buttons


#include <Servo.h>

int servoPin = 9;
int btnPin1 = 12;
int btnPin2 = 6;
int btnRead1;
int btnRead2;
int dt = 250;
int angle1 = 100;
int angle2 = 0;
Servo myServo;

void setup() {
  // put your setup code here, to run once:
  myServo.attach(servoPin);
  Serial.begin(9600);
  pinMode(servoPin, OUTPUT);
  pinMode(btnPin1, INPUT);
  pinMode(btnPin2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  btnRead1=digitalRead(btnPin1);
  btnRead2=digitalRead(btnPin2);
  Serial.println(btnRead1);
  Serial.print(" , ");
  Serial.print(btnRead2);
  if (btnRead1 == 1) {
    myServo.write(angle2);
  } else if (btnRead2 == 1) {
    myServo.write(angle2);
  } else {
    myServo.write(angle1);  
  }
  delay(dt);
}

Whenever I click "Copy Error Messages" it just gives me "An Error Occurred While Uploading The Sketch".

Any help would be super appreciated.


Solution

  • Make sure the right board is selected. Make sure the right com port is selected. Make sure the arduino is connected propperly. Maybe update the libraries. Try to upload it to another board.