Project....a power supply
Hardware...well regulated 14.4v DC to 12v regulator that feeds knock-off NANO and fan circuit, that 14.4v supply also goes to XL6019 to raise the volts to 30v to a LM317T circuit with a POT.
An INA260 monitors that output. I have 3 DS18B20's monitoring 3 points. all is displayed on an OLED.
Problem...when the 18B20's (1 or more) reach threshold and turn on the fan circuit, the display and fan pulses to the speed of the loop or delay if I have that set.
I have documented the attached sketch well.
I think I may have made a mistake in the order of execution or I need to somehow isolate the "if" statement.
I would like some help understanding my mistake and fixing it with the members help.
Thanks, Ben.
```cpp
/////////////////////Library's for wire communication///////////////////////////
#include <Wire.h> //I2C libray
#include <OneWire.h> //One Wire library
////////////////////////////////////////////////////////////////////////////////
/////////////////////Library for Dallas DS18B20 temp sensor//////////////////////
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS); // Create instance of oneWire class
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to DallasTemperature library
uint8_t LM317T[8] = { 0x28, 0x2C, 0x23, 0x58, 0x00, 0x00, 0x00, 0xA7 };
uint8_t XL6019[8] = { 0x28, 0xB4, 0x66, 0x59, 0x00, 0x00, 0x00, 0x03 };
uint8_t MOSFET[8] = { 0x28, 0xBB, 0x3D, 0x56, 0x00, 0x00, 0x00, 0x58 }; // maybe not use a MOSFET to break the circuit on "everythingOff" ISR or temp threshold.
////////////////////////////////////////////////////////////////////////////////
//////////////////////Library's for OLED 128 x 64 display///////////////////////
#include <Adafruit_GFX.h> // Graphics library
#include <Adafruit_SSD1306.h> // Text library
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
////////////////////////////////////////////////////////////////////////////////
///////////////////////Library for INA260///////////////////////////////////////
#include <Adafruit_INA260.h>
Adafruit_INA260 ina260 = Adafruit_INA260();
////////////////////////////////////////////////////////////////////////////////
//////////////////////////INPUT/OUTPUT PINS/////////////////////////////////////
#define OFF_BTN 3 // Give it an interupt pin
#define BUZZER 4 // not used yet
#define FAN_PIN 5
#define PANIC 6 // still figuring it out
////////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(OFF_BTN, INPUT); // not used yet
pinMode(BUZZER, OUTPUT); // not used yet
pinMode(FAN_PIN, OUTPUT);
pinMode(PANIC, OUTPUT); // not used yet. Will probably need a pull-up resistor if it stays high.?
attachInterrupt(digitalPinToInterrupt(OFF_BTN), everythingOff, RISING); // not used yet
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
Wire.begin();
sensors.begin();
ina260.begin();
}
void loop() {
sensors.setResolution(12);
sensors.requestTemperatures();
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("OUTPUT:");
display.setCursor(54, 0);
display.print("SENSOR/TEMP:");
display.setCursor(0, 20);
display.print(ina260.readBusVoltage() / 1000, 3);
display.print("V");
display.setCursor(48, 20);
display.print(" REG ");
printTemperature(LM317T);
display.setCursor(0, 30);
display.print(ina260.readCurrent() / 1000, 3);
display.print("A");
display.setCursor(48, 30);
display.print(" CNV ");
printTemperature(XL6019);
display.setCursor(0, 40);
display.print(ina260.readPower() / 1000);
display.print("W");
display.setCursor(48, 40);
display.print(" FET ");
printTemperature(MOSFET);
display.display();
}
void everythingOff() { // not used yet
digitalWrite(PANIC, LOW);
}
void printTemperature(DeviceAddress deviceAddress) {
float tempC = sensors.getTempC(deviceAddress);
display.print(tempC);
display.print((char)247);
display.print("C");
if (tempC >= 18) { //////////////////////Start of the issue?/////////////////////////////////////
digitalWrite(FAN_PIN, HIGH); // it seems to my "new at this" thinking, I missed a fundamental concept to isolate this "if" statement
display.setCursor(0, 50); // or something so the fan will just be actuated without effecting or be affected by the rest of the code loop
display.print("COOLING FAN ON!");
display.display(); // the pulsing is also affected by how many DS18B20's are above threshold as how many lines on display are blinking
} // PS: obviously the threshold is set low for testing
if (tempC < 18) {
digitalWrite(FAN_PIN, LOW); ///////////////////////End of the issue?///////////////////////////////////////
delay(500); // fan and display pulses with the execution speed of the loop, or with delay(500), whichever is longer
}
}