If Statement toggles Output

Why does the Circpump toggle the output pin when checked
`Preformatted text

`/*
 
 Use a 16x2 LCD display and a DS18B20.

 * DS18B20 to pin 8
 * Motor pin on pin 6
 * Heater on pin 7

 by John R Tucker
 modified 02 Feb 2022
 
*/

// include the library code:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 8
#define Heater 7
#define CircPump 6

// Setup a oneWire instance to communicate
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;


// initialize the library by associating any needed LCD pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int Pump = 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0, 0);
  lcd.print("  TEMP:");
  lcd.setCursor(0, 1);
  lcd.print("TARGET:");
  
  // Start up the library
  sensors.begin();
  sensors.setResolution(insideThermometer, 10);

  // Set up other stuff
  pinMode(CircPump, OUTPUT);
  digitalWrite(CircPump, LOW);
  pinMode(Heater, OUTPUT);
  digitalWrite(Heater, LOW);

}

void loop() {
  lcd.setCursor(8, 0);
  sensors.requestTemperatures();
  float tempF = sensors.getTempCByIndex(0) * 1.8 + 32;
  lcd.print(tempF);
  
  if (tempF < 80) {
     digitalWrite(Heater, HIGH);
     digitalWrite(CircPump, HIGH);
  }

  if (tempF >= 80) {
    digitalWrite(Heater, LOW);
    digitalWrite(CircPump, LOW);
    Pump = 0;
  }

  // Keep Circulation motor on for 15 sec extra
  if (Pump = 25) {
    digitalWrite(CircPump, LOW);
  }
  
// The Above If causes the output to toggle on/Off`Preformatted text`



  Pump++;
  
  lcd.setCursor(9, 1);
  lcd.print(Pump);
  delay(100);

}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

When you posted your code without code tags did you receive a warning message ?

  if (Pump = 25)

Here is one mistake
This sets Pump to 25 rather than comparing it with 25

1 Like

and if (Pump == 25) mean different things.

1 Like

00FC6A80-4619-4D5B-97BB-3FC420FFCB35_1_102_o

3 Likes

I think I have too many bad habits from other languages. == was my mistake.
Thanks for the point in the direction of:
STUDY THIS LANGUAGES REFERENCE SHEET!

In the IDE, you have a tool called Autoformat, that can help show up errors form missing or mismatched braces &c.

In the IDE Preferences, you can ask that the compiler issue not just error reports, but warnings about possible mistakes, the ‘=‘ doesn’t mean the same as ‘==‘ among them.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.