I have loaded an example sketch that came with the installation of the Arduino software onto my Uno.

void setup() {

void loop() {

  int sensorValue = analogRead(A0);

From this time TX light is continuously on. It's remaining on even after resetting it. How do I end void loop so that TX light goes off.

  • 3
    Stop outputting via the serial connection. Sep 5, 2014 at 21:32
  • I need to setup multitask in a loop, so I can take a snap shoot of data from the SD reader.
    – joe
    Oct 30, 2017 at 11:16
  • 2
    I'm voting to close this question because it shows a fundamental missunderstanding of how Arduino works. The setup and loop model is the very first thing you have to learn before writing your first sketch. It's explained in pag. 36 in the book that's come with Arduino Starter Kit.
    – user31481
    Oct 30, 2017 at 11:55
  • HIGHLY recommend you begin by loading the Blink example program and start there. Then modify it to suit. As for your little program, your delay is only 1 millisecond. You might as well not even have it there because the Serial.println takes longer than that. Change it to 5000 for 5 seconds, maybe. Also, you never set the A0 pin to be of type INPUT. But first go back to Blink and try to walk (digital) before you try to run (analog).
    – SDsolar
    Oct 31, 2017 at 0:52
  • I'm voting to close this question as off-topic because of the age of this one and the lack of useful description in the title.
    – SDsolar
    Oct 31, 2017 at 0:53

5 Answers 5


The implied question is how to turn off the Tx LED, which has already been answered and is probably the answer you're looking for. But the question you asked is how to end the loop() function. Not to be pedantic but to clarify the use of loop, the simple answer is, "you can't". loop() is called from a forever loop in the C/C++ main program, function main(), so returning from it, either with a return statement or by reaching the final close } causes loop() to be called again. This is intentional as the main() function in an embedded system is never supposed to return, thus it must keep re-running the application program.

Update (since this question just reappeared on the front page, I'll add the following to my answer):

loop() reads and prints continuously. If you had wanted that code to be executed only once, you could put in setup() and leave loop() empty. Then the sketch would initialize the serial output, read an analog value, print it - once - followed by entering the empty loop() and remaining there until power-down.

A way to execute the loop function once is to write an infinite loop at the end of it, so loop() would never return and thus never be re-executed:

void loop() {

  int sensorValue = analogRead(A0);


The TX LED is on, because this sketch is periodically printing the value of the analog pin 0 onto the serial port. The LED seems to be constantly on, because the delay between two Serial.println() calls is only approx. 1 ms.

If you replace the 1 with 1000 for example, the TX LED should flash once per second. Start the serial monitor in your Arduino IDE too see the transmitted analog values. Delete the Serial. calls to remove the serial port functionality altogether.

You might want to read the documentation of the loop() and the delay() functions.


Seeing as questions about turning off the LED, and the nature of exiting loop have been answered, I'll also answer the question they both seem to lead to:

If the overall intention is to "turn off" the MCU, outside of turning off the power supply, it can be put into sleep mode.

Depending on how you configure the MCU before entering sleep mode, it can even be allowed to wake up on further USART communication.


Don't write code in the loop() that should be executed only a few times. Or use a counter. Or an external button. For the permanent light, increase the delay between calls.

  • Could you elaborate on how to do the stuff you say to do in this answer? Sep 6, 2014 at 16:50

If your question is how to terminate the execution of your void loop code at some interval, I can mention 4 solutions:

1.If you want the Void loop() to execute only once (or a set number of times using for loop), you can use "exit(O);" at the end of the Void loop. i.e.

Void loop(){

Disclaimer: This one might not work for all Arduino boards, but it works fine with my Arduino UNO.

2.Another way would be to keep the "Void loop()" empty and put all of your code in the Void setup function.

  1. use a void loop at the end of the Void loop. E.g.

    void loop(){ //code while(1){ //infinite loop } }

The arduino will remain in the infinite loop and won't be able to rerun the Void loop.

  1. Create your own function and call it from the "Void Setup()" E.g.

     Void setup(){
      myfunc();   //calling your function
      Void myfunc(){
    //The code for the function you want to repeat only a set number of times
     Void loop(){

Hope someone finds it helpful.

  • Is there a good reason to warm up this old question? BTW: There's a difference between void and Void Sep 30, 2022 at 16:43
  • @DataFiddler - Yup, answer is NFG. The entire Q+A should be deleted, or at least closed as it's obvious the OP will never mark it as answered after 8 years.
    – VE7JRO
    Oct 1, 2022 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.