0

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...

3
  • 1
    Showing us your simplified sketch code would be useful here. For now, try to protect 'fanspeed1' from changing when serial communication is not active.
    – smajli
    Nov 13, 2017 at 10:40
  • 2
    Disable the auto-reset functionality of the board?
    – Majenko
    Nov 13, 2017 at 11:07
  • It's 0~255, not 256.
    – dda
    Dec 14, 2017 at 5:39

1 Answer 1

2

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)

Your Answer

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

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