Hi @cattledog
Yes, I am able to load simple code (like the blink example) to the board and change the blink rate of the LED, which works perfectly. However, when I try to load a more complex code, it fails to upload and gives the error message.
I am using the same USB cable for both the simple code upload and the complex one. The simple code uploads fine, but when I try the other one, the error appears.
There is the complex code:
#include <Servo.h>
#define Trigger_Pin 5
#define Echo_Pin 4
#define LeftMotorPin1 D1
#define LeftMotorPin2 D2
#define RightMotorPin1 D3
#define RightMotorPin2 D4
#define IR_Pin A0
#define LeftPhotoCell A1
#define RightPhotoCell A2
#define BluetoothPin 6
Servo myservo;
int servoPosition = 0;
long duration;
long distance;
void setup() {
pinMode(LeftMotorPin1, OUTPUT);
pinMode(LeftMotorPin2, OUTPUT);
pinMode(RightMotorPin1, OUTPUT);
pinMode(RightMotorPin2, OUTPUT);
pinMode(Trigger_Pin, OUTPUT);
pinMode(Echo_Pin, INPUT);
pinMode(IR_Pin, INPUT);
pinMode(LeftPhotoCell, INPUT);
pinMode(RightPhotoCell, INPUT);
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
digitalWrite(Trigger_Pin, LOW);
delayMicroseconds(2);
digitalWrite(Trigger_Pin, HIGH);
delayMicroseconds(10);
digitalWrite(Trigger_Pin, LOW);
duration = pulseIn(Echo_Pin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" cm");
if (distance < 10) {
myservo.write(90);
} else {
myservo.write(0);
}
int leftPhotoValue = analogRead(LeftPhotoCell);
int rightPhotoValue = analogRead(RightPhotoCell);
if (leftPhotoValue > 512) {
digitalWrite(LeftMotorPin1, HIGH);
digitalWrite(LeftMotorPin2, LOW);
} else {
digitalWrite (LeftMotorPin1, LOW);
digitalWrite (LeftMotorPin2, HIGH);
}
if (rightPhotoValue > 512) {
digitalWrite (RightMotorPin1, HIGH);
digitalWrite (RightMotorPin2, LOW);
} else {
digitalWrite (RightMotorPin1, LOW);
digitalWrite (RightMotorPin2, HIGH);
}
int irValue = analogRead(IR_Pin);
if (irValue == HIGH) {
digitalWrite(LeftMotorPin1, LOW);
digitalWrite(LeftMotorPin2, LOW);
digitalWrite(RightMotorPin1, LOW);
digitalWrite(RightMotorPin2, LOW);
}
if (Serial.available()) {
char command = Serial.read();
if (command == 'F') {
digitalWrite(LeftMotorPin1, HIGH);
digitalWrite(LeftMotorPin2, LOW);
digitalWrite(RightMotorPin1, HIGH);
digitalWrite(RightMotorPin2, LOW);
}
else if (command == 'B') {
digitalWrite(LeftMotorPin1, LOW);
digitalWrite(LeftMotorPin2, HIGH);
digitalWrite(RightMotorPin1, LOW);
digitalWrite(RightMotorPin2, HIGH);
}
}
delay(100);
}
Let me know if you need any more information or the exact error message.
Thanks!