user39770: I have a problem with my homemade fan speed controller powered by an Arduino Nano, which reads a value from Serial (Arduino serial monitor, or Processing sketch) and uses the 0~255 value to set a variable fanspeed1 to set a PWM pin to control the fan speed.
The problem is when I close the Processing sketch, or the Arduino serial monitor, fanspeed1 is changed to max value (the fan speeds up to full speed).
I would like to send serial to set the value and then close the serial monitor, or Processing sketch and the value of fanspeed1 should not change.
If I need to post some code I can simplify my sketch down to a send serial, receive serial, make pin pwm = serial(0~255), but I am guessing there is a simple solution to this unfindable with my googling.
Help please, these fans need controlling...

user39110: You could consider writing/reading the value to/from the EEPROM.
http://arduino.cc/en/Reference/EEPROM
This allows the board to be reset, or even turned off, and retain the value previously set.  What you would be doing is saving the value to the internal memory of the Arduino.  This is resettable and persistent over a "reboot".
Granted, there is a limited number of writes you can do, but that number is high enough (~100k) that you will probably wear out the fan before the EEPROM sector dies.

Syntax
EEPROM.write(address, value)
EEPROM.read(address)
EEPROM.update(address, value)

For objects:

EEPROM.put(address, data)
EEPROM.get(address, data)


39770: <p>I have a problem with my homemade fan speed controller powered by an Arduino Nano, which reads a value from Serial (Arduino serial monitor, or Processing sketch) and uses the 0~255 value to set a variable <code>fanspeed1</code> to set a PWM pin to control the fan speed.</p>

<p>The problem is when I close the Processing sketch, or the Arduino serial monitor, <code>fanspeed1</code> is changed to max value (the fan speeds up to full speed).</p>

<p>I would like to send serial to set the value and then close the serial monitor, or Processing sketch and the value of <code>fanspeed1</code> should not change.</p>

<p>If I need to post some code I can simplify my sketch down to a send serial, receive serial, make pin pwm = serial(0~255), but I am guessing there is a simple solution to this unfindable with my googling.</p>

<p>Help please, these fans need controlling...</p>
 39110: <p>You could consider writing/reading the value to/from the EEPROM.</p>
<p><a href="http://arduino.cc/en/Reference/EEPROM" rel="nofollow noreferrer">http://arduino.cc/en/Reference/EEPROM</a></p>
<p>This allows the board to be reset, or even turned off, and retain the value previously set.  What you would be doing is saving the value to the internal memory of the Arduino.  This is resettable and persistent over a &quot;reboot&quot;.</p>
<p>Granted, there is a limited number of writes you can do, but that number is high enough (~100k) that you will probably wear out the fan before the EEPROM sector dies.</p>
<blockquote>
<p>Syntax</p>
<p>EEPROM.write(address, value)</p>
<p>EEPROM.read(address)</p>
<p>EEPROM.update(address, value)</p>
</blockquote>
<p>For objects:</p>
<blockquote>
<p>EEPROM.put(address, data)</p>
<p>EEPROM.get(address, data)</p>
</blockquote>
