double flash?? Arduino not working without serial monitor

I am not a programmer, but I am very excited about learning about my new Arduino!

I really want to have my linux server turn on my crock pot. The circuit is relatively simple and that is no problem. Right now I am trouble shooting the programing with just an LED instead of the relay circuit. Right now my code (Thanks mostly to Jeremy Blum youtube tutorials) looks like this:

int ledPin = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  while (Serial.available() == 0);
  int val = Serial.read() - '0';
  
  if (val == 1) 
  {
    Serial.println("Led is on");
    digitalWrite(ledPin, HIGH);
  }
  else if (val ==0)
  {
    Serial.println("Led is off");
    digitalWrite(ledPin, LOW);
  }
  
  else
  {
    Serial.println("invalid");
  }
 
}

I was hoping that I could just have the terminal send a character to the Arduino so that i can SSH into the box from work, send the one character, then start my crock pot. Or if I was a better man have CRON run a simple shell script to turn the pot on without my input.

Since my server is headless, I connected the Arduino, ran the Arduino IDE with an X-forwarded SSH session, and programed it up. It is working great with the serial monitor. When I have the serial monitor open and I use a seperate SSH window to send this command:

echo -n "1" > /dev/ttyACM0 9600

everything works fine. When the serial monitor is closed I only get 2 quick flashes from the led then nothing.

Any ideas?

Yes.

When you open the serial port to the Arduino the chip gets rebooted. This is so that the IDE can program the chip without any manual intervention.

What you need to do is disable the auto-reset functionality.

There are a number of ways of doing this - some permanent, and some temporary.

The easiest way is to connect a 10uF (or similar) capacitor between the RESET pin and GND. This will stop you being able to program the Arduino without either pressing the RESET button or removing the capacitor, but it is easy to undo at a later date.

The more permanent way is to break the "RESET-EN" connection on the board with a sharp knife. Hard to undo later, and I wouldn't recommend it.

THANK YOU

I tried google first but nothing beats an experienced user!

There are supposed to be ways of configuring your serial port at the linux end to stop the reboot, but I haven't investigated those yet - it's just easier to pop in that cap and have done with it.

did a quick catalog search at my supplier ( i dont own any capacitors)

would 10uF 16V Radial Electrolytic Capacitor be an ok choice? i can't cant any 10uf capacitors that are 5v

Perfect choice. You don't want to go below 6.3v, and going higher is good.

The capacitance isn't critical. 10uF is about minimum. You might get away with smaller. If you have any larger ones to hand, they will do just as well. I keep a stock of 22uF capacitors on hand as they are useful for so many things - this included. You could even use a 3300uF one if you wanted, but that would be kind of overkill. You're basically just smoothing out the dip in the reset line the serial hardware causes, so the actual value isn't that important.

You may want to have a look at this page:
http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

Super-Nathan:
would 10uF 16V Radial Electrolytic Capacitor be an ok choice? i can't cant any 10uf capacitors that are 5v

Voltage rating on a capacitor is simply the maximum voltage you can put across the leads before it breaks down and becomes unusable, so the higher the better. General rule of thumb is to get at least twice the maximum voltage needed. Assuming your Arduino is running at 5v, 16v should be fine.

Well, I never use my Arduino this way.

I have a habit of building my projects on a breadboard including an extra ATMEGA328-PU and just using the R3 to code.

This eliminates a lot of issues like this!!

ronpbaker:
Well, I never use my Arduino this way.

I have a habit of building my projects on a breadboard including an extra ATMEGA328-PU and just using the R3 to code.

This eliminates a lot of issues like this!!

Heh... I tend to shy away from the Atmel controllers altogether :wink: 99% of my projects use PIC, and those that don't are for other people that use Arduinos. I find Atmel under-powered and over-priced. For not much more than a 328P I get a 32-bit core, 128KB RAM, 512KB flash, 100-pin TQFP... And with a proper USB bootloader there's no need for any external programming boards / dongles. I have never run into a problem with unwanted resets (other than my shoddy code)...