I have a probelm with an error named redefinition of void setup

I was testing a code for the ultrasonic sensor for the uno rev3 example and this is the third time but the past two worked What am I doing wrong?``

Arduino:1.8.19 (Windows Store 1.8.57.0) (Windows 10), Scheda:"Arduino Uno"

C:\Users\ironm\OneDrive\Desktop\coding\Elegoo\Italiano\code\Lesson 10 Ultrasonic Sensor Module\SR04_Example\SR04_Example.ino: In function 'void setup()':

SR04_Example:25:6: error: redefinition of 'void setup()'

void setup()

  ^~~~~

C:\Users\ironm\OneDrive\Desktop\coding\Elegoo\Italiano\code\Lesson 10 Ultrasonic Sensor Module\SR04_Example\SR04_Example.ino:8:6: note: 'void setup()' previously defined here

void setup() {

  ^~~~~

C:\Users\ironm\OneDrive\Desktop\coding\Elegoo\Italiano\code\Lesson 10 Ultrasonic Sensor Module\SR04_Example\SR04_Example.ino: In function 'void loop()':

SR04_Example:32:6: error: redefinition of 'void loop()'

void loop()

  ^~~~

C:\Users\ironm\OneDrive\Desktop\coding\Elegoo\Italiano\code\Lesson 10 Ultrasonic Sensor Module\SR04_Example\SR04_Example.ino:13:6: note: 'void loop()' previously defined here

void loop() {

  ^~~~

exit status 1

redefinition of 'void setup()'

Questo report potrebbe essere più ricco di informazioni abilitando l'opzione
"Mostra un output dettagliato durante la compilazione"
in "File -> Impostazioni"

The code you posted, in code tags, indicates the error is on line 1043523445487773.

1 Like

So you have a definition of the setup() function starting at line 25 of your sketch.

But that is not allowed because you also have a definition of that function starting at line 8:

You can only have one setup function in your sketch.


As for the fix, we will need to see your sketch in order to provide guidance. Please post your full sketch.

  1. Select Tools > Auto Format from the Arduino IDE's menus. This will make it easier for you to spot bugs and make it easier for us to read.
  2. Select Edit > Copy for Forum from the Arduino IDE's menus.
  3. In a forum reply here, click on the post composer field.
  4. Press Ctrl+V. This will paste the sketch to the post composer.
  5. Move the cursor outside of the code tags before you add any additional text to your reply.
  6. Repeat the above process if your sketch has multiple tabs.
  7. Click the Reply button to post your reply.

When your code requires a library that's not included with the Arduino IDE please post a link to where you downloaded that library from or if you installed it using Library Manager (Sketch > Include Library > Manage Libraries in the Arduino IDE) then say so and state the full name of the library.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.