Help me fix this Arduino code ?
Help me fix this Arduino code ?
Over the past few months I've been working on a hot air station using a OneWire YouTube tutorial. I built my own PCB and streamlined the assembly. However, the Arduino code still has issues—bugs and errors remain. I resolved some sleep and reed switch problems; now the display alternates between the main screen and the cooling panel. This affects fan speed and heater control. The original code managed both controls smoothly, but the reed switch logic was flipped. When detached from the holder, the code malfunctions, causing the heater to overheat and the screen to freeze. Could anyone assist me in fixing this?
Thank you.
👍 Fair enough.
I referred to the term "hovering"; "hunting" conveys a similar meaning.
The flickering might stem from a fluctuating value.
It’s comparable to how a solar light dims and brightens as the sun sets, until ambient light drops low enough to maintain illumination in darkness.
You might reduce or halt the flicker by adding delay functions to digitalWrites.
This would depend on the underlying reason for the flickering.
It seems straightforward to test.
I am not very sure about the physical connections we have established.
The hot air station project is essentially just a project, but if there are any issues with connectivity then the intermittent flickering and other problems might stem from faulty connections rather than the code itself.
It could be a mix of both factors.
For instance, I notice what look like several heat shrink splices on the left connector, and the mini display seems misaligned—this suggests the cosmetic appearance isn’t the main issue, but a tilt in the screen might point to a misfit and thus weak or incorrect connections. I can’t see inside the station.
Regarding the code—was it originally available?
I managed to download the .zip file named "hot airstation by one wire. zip" and opened it with Notepad. I’m not certain it contains all the required code sections.
Could you please share specific references to the problematic code parts? For example, describe what happens when the station operates in main vs cooling mode, or note any changes like a reed switch being reversed.
While the station is active, please look closely at the code and add comments about its expected behavior and actual performance.
I suspect potential bugs such as incorrect logic (e.g., a false condition) or mismatched IF/ELSE statements.
A direct link to the code should be provided so it can be viewed easily without needing downloads.
To clarify, I’m not an Arduino user, but I follow the principle that “code is code,” and I’m open to questions based on what I read here.
Other members familiar with Arduino might spot any missing or incorrect parts quickly—please make it as simple as possible.
For Arduino IDE libraries, the alternative is for custom font. I'm quite sure. I'm employing jumper cables to facilitate disassembly in case of any issues. For both AC and DC power, KF301 terminal blocks are used.
I resolved the reed switch problem by adjusting the HIGH/LOW settings on the sleep switch and modifying the sleep switch and sleep driver code lines. The flickering issue reappeared after these changes.
My concern is that in the two code sections,
after updating to "if (digitalRead(sleepsw) == HIGH)
" and " if ( digitalRead(sleepsw) == LOW
&& swtrig == false)" it causes flickering.
When handling the sleep switch, turning it OFF: activating the reed switch when I reinsert the blower back into its holder.
SLEEP DRIVE: The cooling and sleep mode after I reinstalled the blower.
Code:
//WHEN HANDLE SLEEP SWITCH OFF//
if (digitalRead(sleepsw) == HIGH) {
updateMenu();
swtrig = false;
//SLEEP DRIVE//
if ( digitalRead(sleepsw) == LOW && swtrig == false) {
if (teplotaC < 100) {
drawsleep();
buzzertone3();
analogWrite(airflowreg, 0);
digitalWrite(heaterreg, LOW);
analogWrite(LED1, 5);
swtrig = true;
} else {
display.clearDisplay();
display.drawBitmap(95, 15, fan, 25, 25, WHITE);
display.fillRect(0, 0, (teplotaC * 91) / AppSettings.maxTemp , 13 , WHITE);
display.setFont(&URW_Gothic_L_Demi_16);
display.setCursor(5, 33);
display.setTextColor(WHITE);
display.print("COOLING");
display.setCursor(33, 58);
display.print(teplotaC, 0);
display.print("*C");
display.display();
analogWrite(airflowreg, 225);
digitalWrite(heaterreg, LOW);
}
}
The question concerns the behavior of swtrig during toggling: it seems initialized as false, then flipped inside a nested IF. Is it essential for swtrig to remain false in the ELSE branch? Additionally, the use of a buzzer tone "buzzertone3" to confirm the wand is docked appears accurate. Would using two distinct tones—one for docking and one for undocking—be more appropriate? This would align better with swtrig values. The flickering might stem from certain AND/OR conditions affecting display updates as temperatures stabilize. It’s possible that temperature readings fluctuate around a stable point, causing the display to appear to flicker. The intermittent value changes in digital inputs can sometimes be seen as "hovering" near a threshold. Modifying the text color for each displayed value could aid in identifying the cause. The flickering color might offer clues. Including relevant code lines would assist in troubleshooting effectively.
👍 Fair enough.
I referred to the term "hovering"; "hunting" conveys a similar meaning.
The flickering might stem from a fluctuating value.
It’s comparable to how a solar light dims and brightens as the sun sets, until ambient light drops low enough to maintain illumination in darkness.
You might reduce or halt the flicker by adding delay functions to digitalWrites.
This would depend on the underlying reason for the flickering.
It seems straightforward to test.
Sorry for only letting you know now. I’m starting to give up on fixing the code. At least the hot air station is now functioning properly. I need to take out the internal reed switch and solder the two cables directly. From a technical standpoint, when the reed switch makes contact with the magnet, I can manage the temperature and airflow as usual, so why not connect the reed switch cable together? I did, and it’s working. Of course, this automatically disabled the sleep mode, but that’s fine for me. Thank you for all your efforts. I really appreciated it.