Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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

void setup() {
   Serial.begin(9600);
}


void loop() {

  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(1);       
}

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.

share|improve this question
1  
Stop outputting via the serial connection. –  Ignacio Vazquez-Abrams 2 days ago

4 Answers 4

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
Could you elaborate on how to do the stuff you say to do in this answer? –  The Guy with The Hat yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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