0

I am programming an Arduino to turn a LED on when it receives something in the serial port. I have done this and it has received the data but after the LED should have been turned off it keeps going. Here is my current code:

int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available() > 0) {
    Serial.print("RECEIVED_CALL");
    digitalWrite(ledPin, HIGH);
    delay(4500);
    digitalWrite(ledPin, LOW);
    Serial.clear();
  }
}

Please leave any suggestions.

cheese5505
  • 962
  • 5
  • 14
  • 30
  • Is there a reason why you have a 4500 ms i.e. 4.5 second delay? Also if you still have data available it will be turned right back on. Try adding a delay after you set the pin low – Mark Hall Jul 04 '12 at 05:19
  • 1. I need it on for 4.5 seconds 2. I'll try that – cheese5505 Jul 04 '12 at 06:37

1 Answers1

0

Add some debugging statements (like Serial.print("LED_OFF")) to be sure that your Arduino is not restarting upon receiving serial data as described in my post here.

This may account for the light staying on. It may be restarting over and over again if you are sending enough serial data.

Community
  • 1
  • 1
ZnArK
  • 1,533
  • 1
  • 12
  • 23