• Welcome to Photrio!
    Registration is fast and free. Join today to unlock search, see fewer ads, and access all forum features.
    Click here to sign up

A project with Arduino- Help

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm
Hi everyone, Michael from Italy here,
first of all happy New Year to all forum friends,
As per the title, I’m developing a small project to (hopefully) improve my experience during the development process. I’ll briefly explain:
A brain box containing: 6 buttons, a rotary encoder, a 20x04 display, a buzzer, a relay, and a temperature probe.
The code allows setting the various steps with development times, washing, etc., using the encoder. With one button (reset) all values are cleared; with the up and down buttons you can move between the steps (I set 8 steps). When the start button is pressed, the program starts the cycle, always from the first step, and it can be stopped and restarted by pressing the same Start/Pause button.
During the program, two buttons manage the following functions:
  1. Temperature probe: connected to a T pipe after a thermostatic valve to regulate the temperature of the water coming out of a heater. While the button is pressed, the temperature appears on the display.
  2. Water button: while it is held down, it opens a solenoid valve to let thermostated water flow and fill tanks or chemical containers, and the word “water” appears on the display.
Now, I developed the code with the help of ChatGPT (I admit it—otherwise I wouldn’t be honest), I designed the PCB, ran some tests, and everything seems to be working. Would anyone be willing to review the code and the electronic part (components, traces, resistors, and capacitors)?
Obviously, if you’re interested, the project is open to everyone, and I can also send you the files to print the adhesive skin that I designed using InDesign.
The code is here:
pastebin.com/gYnG1PpC

If needed, I can also share the PCB file.
Thanks in advance to anyone who replies,
Michael
 

koraks

Moderator
Moderator
Joined
Nov 29, 2018
Messages
26,664
Location
Europe
Format
Multi Format
Welcome aboard @michelerubino96 !

For reviewing your project, it would help if you described a little more clearly what the device is suppose to do before going into the specific functions of buttons, valves etc. A photo or two might help clarifying things as well. It sounds like it's a kind of combined timer/valve control box, but perhaps I'm overlooking some things.

If the code works, it works. I've only had a very brief look at it and noted several things I would have done differently. Nothing wrong with using AI to help in producing code, btw. However, it's not always a good substitute for a clear, human-made software architecture. As such, the structure of the code is not great as it is and I expect you will run into trouble as you expand this program.

There's also a considerable amount of redundancy in the code, making it prone to errors when trying to change or add things. I would avoid hard-coding magic numbers all over the code (such as buzzer timings etc.) and instead store them as clearly described constants or #defines instead.

Comments on the code are kind of sparse and for an internationally-oriented project, I'd stick with comments in English.

The routine for reading the rotary encoder doesn't look right too me; maybe it works under very specific conditions, but it's not the way I'd solve the issue. There are plenty of rotary encoder libraries for Arduino available. The best ones (IME) use a very simple state machine logic to determine the direction of the rotation.

If you could share the schematic and the PCB design, we could have a look at this as well.

I think what you may have to distinguish between is a project that will get the job done with minimal effort just for you and in your specific situation, and a project that is robust enough to be made available to the general public. So far, your project would in my view fit in category #1.
 
OP
OP

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm
Hi, first of all thanks for your reply,
Quickly the project itself it's a combination of timers settings and temperature check/valve-water output.
I started thinking about this combination to have in just one device the multiple things that now i do with different ones to develop my film with a cpp2 jobo, for example: checking the water temperature for washing, opening the water, and start-stop the timers with the phone for every steps ( I usually do E6).
So inspired by jobo autolab system, I planned to do ( even if i don't use all of them ) 8 steps.

Talking about the program:
When you turn on the device, you press start button to begin, and start setting the timers with the encoder, with the up-down buttons you choose the step (moving from 1 to 8) in this fase you can use the reset button to set the timer to 0.00.
When you are ready to process, the button start-pause allows you to start, the program always start from 1 step and goes on. You are free to stop the countdown.

While the development process is going, you can check the output temperature, using a ds18b20 probe, while you press the button, on the display you read the value, when you release it, it disappear.
The same for the valve, while you push the button, the water goes out, immediately when you release the water stops to run.


Now, I know that using the AI is not the best, but being honest I'm not capable to write a code and even I wish to do that , until now, sadly I don't have time.
I need to create (or fix this) a code that works and doesn't have critical points.

I tried to draw a pcb, being quite new to the electronic world.
I put external resistance for buttons, encoder, probe, ceramic capacitors for 5v arduino input and capacitors for i2c display
I already made a pcb with 12v supply for the solenoid valve, a 5v step down for arduino with a electrolytic capacitor on the output.

This project is of course made for helping me in the dev. process, but is open to everyone who may need it or want to add or modify for personal purpose

Many thanks,
Michael
 

Attachments

  • pcb.jpg
    874 KB · Views: 31

peoplemerge

Subscriber
Allowing Ads
Joined
Jun 15, 2014
Messages
405
Location
Hollywood, CA
Format
Medium Format
If I understand, it is, or could be a timer. You do the process, it provides an interface to keep you on track.
 
OP
OP

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm
Exactly, it's a program based on steps and timers. when you run ( thinking about an industrial way) you can only start-pause, and along this you can use the two buttons for temperature check and water valve.
 

blee1996

Subscriber
Joined
Jul 25, 2008
Messages
1,466
Location
SF Bay Area, California
Format
Multi Format
If you have the time and interest, you might consider using github or gitlab for collaborating with other people to develop open source software (and to lesser extent, hardware). It is easier to track changes and contributions.
 

koraks

Moderator
Moderator
Joined
Nov 29, 2018
Messages
26,664
Location
Europe
Format
Multi Format

OK, so to clarify - presently, the valve really only toggles on/off on user input and it's not associated with process timing in any way?

I've not gone through your code in detail, but adding to the issues I mentioned above:
* Response of the rotary encoder is likely poor. I expect it easily misses clicks if it's turned too fast or too slow.
* The system won't respond to user input during execution of functions, including when e.g. the buzzer beeps, due to the locking nature of these functions.
* The state machine logic prevents the 'config' mode to be entered once the system as proceeded to another state; the project needs to be hardware reset to go back there.
There are numerous quirks and oddities in the code. As said before, it won't scale well and it's fundamentally flawed in various ways. Again, if it works for you, that's fine. Sometimes a solution doesn't have to be elegant to be effective. I'd personally find this timer unit to be awkward and irritating to use.

For the electronics - I wonder why you're not simply using the internal pullups on the microcontroller instead of pulling up all buttons externally. Your solution isn't wrong - it just involves a bunch of unnecessary components and makes routing unnecessarily complex. For each button you only really need a single signal line and GND; no external resistor, no VCC.
There's a mystery footprint J14 that doesn't seem to do anything. There appears to be two dangling nodes here as well:

I can't say much about the electronics otherwise lacking a proper schematic. A PCB layout only goes a limited way in giving insight into the switching logic. Overall, it's a fairly simple & straightforward project. The main question with projects like these is how the power supply is handled and whether there's proper handling of the discharge of a valve coil when it opens; this can result in spurious resets or even damaged components if it's not handled well. Problems in this area are very common.
I see no traces that I would find suitable to carry the supply power (and GND) for a typical water valve, so I assume only the switching logic is on this board and all power circuitry for the valve is handled externally. If this is not the case, the board is fundamentally flawed in its design, even though it may work.
Overall the routing is awkward, but may still work other than the oddities I indicated above.

Your project illustrates that it's feasible for someone without prior experience to build something that in principle functions as desired. That's a major leap from where we were 10-20 years ago and recent developments in AI have accelerated things massively. At the same time, it also demonstrates that a little help form AI is not a substitute from learning the basics of electronics and software engineering, and that doing a proper job still requires actual human learning and logic. Of course, this may (likely will) also change in years to come.

PS: as to the quality of the code of the software, in my experience Copilot (which AFAIK comes with a free-to-use plan if you have an MS Office license) produces code of much better quality than this.
 

RalphLambrecht

Subscriber
Allowing Ads
Joined
Sep 19, 2003
Messages
14,913
Location
K,Germany
Format
Medium Format

super idea,uch luck with the project, and don't feel bad about using ChatGPT for help. Every inventor through history has always made use of the best tools available to them. By being open about it, you are doing the right thing.
 
OP
OP

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm
Hi,
Answering your questions going to order:

1)Yes, the button valve open the water system just when you press it, I used this way thinking about my method of work while i develop ( for example I refill during the second developer and bleach-fix)
2) could you fix and explain me the logic of the encoder ?
3) I used to think about the code like an industrial machine, that you can only pause/restart during the process
4) I agree with you that until now, human is necessary to develop something, and I would like to know better what you think is strange in the code, what could be fixed or changed.
5) You said "I'd personally find this timer unit to be awkward and irritating to use", what you would change if you were me ?
6) Yes you are right to use the pull up and removing many wiring
7) The power comes from 5A 12v, from this I create a separate pcb with a step down 5v to power the main board with arduino. So yes, this pcb is only for buttons and encoder, buzzer and probe wiring.
 
OP
OP

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm
super idea,uch luck with the project, and don't feel bad about using ChatGPT for help. Every inventor through history has always made use of the best tools available to them. By being open about it, you are doing the right thing.

Thanks for your comment, I would like know understand more the field of coding, but until now I don't have time, so, I tried with the AI tool.
 

koraks

Moderator
Moderator
Joined
Nov 29, 2018
Messages
26,664
Location
Europe
Format
Multi Format
2) could you fix and explain me the logic of the encoder ?
Here's a good primer: https://arduinogetstarted.com/tutorials/arduino-rotary-encoder
Here's an Arduino library that you could use: https://github.com/sigmdel/mdRotaryEncoder I've not used this particular one, but in the past I used the one by Buxton that this one is based on. It's robust.
The list would be too long...
Really, it would take me longer to explain than to just re-do the whole thing.
7) The power comes from 5A 12v, from this I create a separate pcb with a step down 5v to power the main board with arduino. So yes, this pcb is only for buttons and encoder, buzzer and probe wiring.
How do you manage the kickback of the solenoid?
 
OP
OP

michelerubino96

Member
Allowing Ads
Joined
Jan 3, 2026
Messages
6
Location
Milan
Format
35mm

ok, i will try use the library you suggest.
I don't ask you to re-do it all
for the solenoid a use a Diode, do you think it's enough?
 

koraks

Moderator
Moderator
Joined
Nov 29, 2018
Messages
26,664
Location
Europe
Format
Multi Format
Yes, a suitable diode should work.
I wasn't intending to suggest I'd have to do it all over, just that discussing everything I would do differently, would take a lot of time. Also, how I'd approach this would depend largely on what my future plans for the system would be and if I'd be planning on upgrades and extensions of the current functionality.

One obvious change I'd make is to make the system responsive also to use input when it's running. Having to reset everything just because you mistakenly set the timer one minute too short and already hit 'start' accidentally is really crappy. Likewise, I wouldn't want to have a system in my home that controls a water valve and that locks up by design while executing other functions, which would mean in practice that the system has a way opening a valve and I would have no way as a user to shut it again.

I would also decouple as much as possible everything related to user input (buttons, rotary encoder), user-interface outputs (LCD, buzzer), the 'engine' of the program (i.e. the state machine) and real-world interactions (presently the valve control). Personally I like to stick for the most part to a modular design and on Arduino you can easily leverage object oriented programming, so I'd start by deciding what the meaningful objects and interfaces would be, and then implement those as classes. Especially if the functionality is likely to be modified or expanded in the future, this approach will make it easier to do so without running into all kinds of annoying and seemingly inexplicable bugs.

For displays I prefer to use some kind of buffered approach where all parts of the system can write to the display fairly freely and whenever they please, but the actual display hardware is controlled by a single entity. This ensures that the display always contains up-to-date information while avoiding things like annoying flicker etc.

Avoid in general hard-coded text and numbers within the code; if you want to change something on e.g. a display, you'll drive yourself crazy trying to find where it is. Especially if it's something that recurs a couple of times.

Etc. etc.

The main principle is that you can often invest up-front to save yourself a LOT of time and frustration later on, both in using and in maintaining/upgrading the system.

Btw, there's a forum for Arduino projects where plenty of people will quite readily comment on your project and answer specific questions you might have. I don't know how they presently perceive AI-heavy projects; a few years ago everyone would get their panties in a knot if someone admitted they used AI to generate code, but I expect/hope that even those guys have woken up to the reality that every self-respecting software engineer today uses AI to build code (it's that, or get fired due to lack of productivity - if not today, then soon).