Hello! I have been attempting to fix this error for a couple hours now. I'm using an Elegoo Uno R3 to power an ultrasonic sensor, two servo motors, and an LED. I've checked the connections on the board and changed some code around. I also went through to make sure there weren't any errors, although it is possible I missed some.
My two servos are both connected to ground and share a pin. I used the male end of a jumper wire to go into the pin and soldered two female connectors to it. Both were working fine originally until the error came up.
The two servos and the ultrasonic sensor are connected to 5v using a similar method as the one above.
The servos are both connected to digital I/O pins with PWM.
The trig and echo pins of the ultrasonic sensor are also connected to digital I/O pins, and it is also connected to ground. The ultrasonic sensor was working for a time and eventually would only print out "1"s for the distance. I was attempting to fix this when the error happened.
I have an LED with its positive leg soldered to one end of a 325 ohm resistor. The negative leg of the LED is soldered to a jumper wire which is in the third ground pin. The other end of the resistor is also soldered to a jumper wire which is in a digital I/O pin. The LED was also blinking before the error occurred.
Here is my code:
#include "Arduino.h"
#include "Servo.h" // Add library
Servo leftServo; // Define any servo name
Servo rightServo;
// define ultrasonic pins
const int trigPin = 9;
const int echoPin = 11;
// define ultrasonic variables
long duration;
int distance;
//define LED pin
int led = 13;
//define servo pins
int servoLeftPin = 8;
int servoRightPin = 2;
void setup() {
//LED
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
//Servo Pins
leftServo.attach (servoLeftPin); // Define the servo signal pins (PWM 3-5-6-9-10-11)
rightServo.attach (servoRightPin);
//Ultrasonic Pins
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
/*
* LED
*/
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
/*
* Servos
*/
//Turn right servo to 90; left servo to 130
leftServo.write(180); //180
rightServo.write(45); //45
/*
* Ultrasonic Sensor
*/
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
And here is the error log:
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'
C:\Users\BEV-GE~1\AppData\Local\Temp\ccZs83Tt.ltrans0.ltrans.o: In function `handle_interrupts':
C:\Program Files (x86)\Arduino\libraries\Servo\src\avr/Servo.cpp:58: undefined reference to `digitalWrite'
C:\Program Files (x86)\Arduino\libraries\Servo\src\avr/Servo.cpp:65: undefined reference to `digitalWrite'
collect2.exe: error: ld returned 1 exit status
Using library Servo at version 1.1.2 in folder: C:\Program Files (x86)\Arduino\libraries\Servo
exit status 1
Error compiling for board Arduino/Genuino Uno.
I've tried going into the file at the very top but I've been unsuccessful.
This is for a project I have that's due on Friday and I still have more code to change. If someone could shed some light on this issue or give me a helping hand I'd very much appreciate it.