Critique my project.

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.

Bubble.jpg

On.jpg

Off.jpg

Run.jpg

CO2_Doser.ino (18.1 KB)

Bubble.jpg

On.jpg

Off.jpg

Run.jpg

Why re-invent the wheel?

If it works on the breadboard but not in the field, or not always, then write test programs for separate checks of each component. Come back and report if you identified a specific problem with a specific component. On a breadboard odds are good that it is a weak contact that causes failures.

TheMemberFormerlyKnownAsAWOL:
Why re-invent the wheel?

Maybe because he wants to.

windoze_killa:
Maybe because he wants to.

... is the dumb answer.

TheMemberFormerlyKnownAsAWOL:
Why re-invent the wheel?

This response wasn't exactly magical either. Just a bunch of functions.

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.

He still has to add some code as he stated to do something with the results.

Just a bunch of functions.

sp. "tested, debugged functions"

Could you add a schematic please? Advice on how to do that here

TheMemberFormerlyKnownAsAWOL:
Why re-invent the wheel?

Sorry not sure what you mean don't reinvent the wheel, you mean the EEPROM read/write functions. For the most part they are the Arduino functions but because I am saving unsigned long and int variables I had to use modified functions.

johnerrington:
Could you add a schematic please? Advice on how to do that here

I don't really have a schematic, is there anything particular you wanted to check out. Basically all it is at this point is the nano connected to the OLED along with a rotary encoder(resistors and caps) and a transistor and LED. Just benching it until the valve arrives.

because I am saving unsigned long and int variables I had to use modified functions.

Take a look at EEPROM.put() and EEPROM.get() in the page linked to in reply #1

UKHeliBob:
Take a look at EEPROM.put() and EEPROM.get() in the page linked to in reply #1

Ah, thanks, I didn't see the .get and .put before or I read them wrong. Will have another detailed look, can save on a few functions.

Bryanpl:
I don't really have a schematic, is there anything particular you wanted to check out. Basically all it is at this point is the nano connected to the OLED along with a rotary encoder(resistors and caps) and a transistor and LED. Just benching it until the valve arrives.

It helps immensely to visualize your project.
And for you, future trouble shooting.
Tom... :slight_smile:

There is so few components that I don't even think I would bother with a PCB. The nano on a perfboard with a transistor and a few other discrete components. Will see if I have KiCad still installed on the pc and play around with making one.