All:
Have been working on an Arduino project to control a pneumatic valve to supply CO2 to a planted freshwater tank or a reef calcium reactor. I have only benched tested on a breadboard while I await the arrival of the valve. So far has been working fine with the occasional glitch that I will outline below.
Would appreciate any comments or critiques on my project. First and foremost, I am no programmer and I am sure that my coding style may make a few shake their head . But hey it’s all about learning and appreciate the assistance these forum boards provide.
So basically, the project controls the on and off times and switches an output to control a pneumatic valve. The valve I am using is a 12v and draws about 70ma. The output pin on the Arduino will feed a 2N3904 transistor or perhaps a mosfet.
I am utilizing an 0.96” 128x64 OLED screen and rotary encoder with a pushbutton. I have managed to code it to fit nicely on a Arduino NANO.
In terms of functionality upon start-up a splash screen is shown with the version number for about 3 second and then the RUN menu is presented which displays to the user the OFF time in seconds and the ON time in milliseconds(ms). The code basically runs unimpeded and switches on and off a output pin.
Upon start-up it tests the eeprom if it has been used before (0xFF) and will save some SAFE default values. If values are saved it loads them from EEPOM into variables for the code.
To avoid wear on the OLED it switches off the display after approx. 10 minutes. Pushing the encoder button re-enables the screen. Only works while in RUN MODE.
Double-clicking the encoder pauses the output and displays a pause screen and a output to a LED to indicate the unit is paused. Double-clicking again puts it back in RUN MODE. PAUSE MODE only works when the display is in RUN MODE
Clicking the encoder button ONCE, moves the menu to the OFF time setting, and rotating the encoder CW/CCW increments/decrements the off time from 0.1s to 10s in 100ms increments,
Clicking the encoder again, advances to the ON Time setting and can be adjusted from 25 to 100ms in 1ms increments.
The ON time once set would rarely be adjusted, and at this point I am just taking a guess as to the timing to create 1 bubble of CO2 gas. The valve has a response time of around 15ms, so it’s probably somewhere around 50ms. It will likely depend on the tubing length, valve specs, altitude, secondary p.s.i. of regulator.
Clicking the encoder again displays how many bubbles have been recorded. More of a novelty, but it may give an indication as to how long a CO2 bottle will last. Rotating the encoder CW/CCW >5 detents will reset the value. ( to avoid a accidental reset)
In this menu the ON/OFF and bubble counter settings are saved to the EEPROM as you cycle through.
Once a day the timer fires to save the bubble counter savings in EEPROM. I didn’t think it was necessary to save any more frequently than a day.
Clicking the button again returns to the main menu RUN MODE.
Seems to be working ok on a breadboard, but occasionally when cycling through the menus the ON and OFF times are not displayed correctly, yet it works fine in terms of switching the output. Suspect some corruption in the OLED, or perhaps I am not calling the correct functions when updating/using the display.
I would like to add a watchdog timer to ensure that for some reason the output doesn’t stick HIGH and dump CO2 into a tank or reactor.
I have put some safety checks in the software, only allows a certain range, when cycling through the menus the output pin is pulled low.
I do have to add some code upon start-up to check the EEPROM for valid settings just in case something went wrong in the EEPROM saving. i.e. ON time below 25ms, etc.
Future versions I am looking at using a TTF touchscreen and perhaps an RTC module. Currently I have the aquarium controlled by a controller and the CO2 is switched off if the pH is too low or switched off depending on the light cycle.
If anyone sees any improvements or errors feel free to post.
CO2_Doser.ino (18.1 KB)