Heya Guys Little guidance will be amazing

Ok Guys Ok im trying to combine two codes i have both codes working separately but when compiled then i have the display and Ir remote working but its like its gets jammed only when i press button on remote then temp on LCD changes but remains jammed until button is pressed again .

#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1  4  // Relay heating
#define RELAY2  6  // Relay cooling

int red = 8; // red LED heating
int blue = 2; // blue LED cooling

#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
  lcd.begin(20,4);
  lcd.backlight();

pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);

    }

void loop() {
lcd.setCursor(0,0);
  lcd.print("   TEMP CONTROL");
  
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 1);
  lcd.print("    ");
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print("\337C");
  
    if(temperature > 25)
    {
digitalWrite(red,LOW);
digitalWrite(blue,HIGH);
 
      lcd.setCursor(0, 3);
      lcd.print("      Cooling ");
 
digitalWrite(RELAY1,1); 
digitalWrite(RELAY2,0);   
           }
    else if(temperature < 25)
    {
digitalWrite(RELAY1,0);
digitalWrite(RELAY2,1); 
digitalWrite(red,LOW);
digitalWrite(blue,HIGH);

 lcd.setCursor(0, 4);
      lcd.print("      HEATING ");
      lcd.setCursor(0, 3);
      
}                 
}

I see no reference to the IR Remote in the code you posted. Please post your best attempt at combining the two sketches.

IR remote?

Kudos for code tags, but please use the IDE's auto format tool before posting

Also:

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

My apologies i see i only uploaded the code for the temp and LCD ok i have uploaded the correct code now and Yes its with a IR remote to turn relay on aswell for LED ,
Did look at IDE's format tool not sure where to use it and on web code i see its picking up (Positive was not declared in this scope )
Will get onto a schematic and pic of the wiring AND components are simple i have HW-490 IR receiver, Using a 2004/16 lcd ,ds18b20 waterproof Temp Sensor.

#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1  4  // Relay heating
#include <IRremote.h>

const int RECV_PIN = 11;
const int yellowPin = 8;
int togglestate = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

int red = 8; // red LED heating
int blue = 2; // blue LED cooling

#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  irrecv.enableIRIn();
  pinMode(yellowPin, OUTPUT);
  Serial.begin(9600);
  sensors.begin();
  lcd.begin(20, 4);
  lcd.backlight();

  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(RELAY1, OUTPUT);


}

void loop() {
  if (irrecv.decode(&results)) {

    switch (results.value) {

      case 0x5FA827D:
        if (togglestate == 0) {
          digitalWrite(yellowPin, LOW);
          togglestate = 1;
        }
        else {
          digitalWrite(yellowPin, HIGH);
          togglestate = 0;
        }
        break;

    }
    irrecv.resume(); {

    }
    lcd.setCursor(0, 0);
    lcd.print("TEMP CONTROL");

    sensors.requestTemperatures();
    float temperature = sensors.getTempCByIndex(0);
    lcd.setCursor(0, 1);
    lcd.print("");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print("\337C");

    if (temperature > 25)
    {
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);

      lcd.setCursor(0, 3);
      lcd.print("Cooling ");

      digitalWrite(RELAY1, 1);

    }
    else if (temperature < 25)
    {
      digitalWrite(RELAY1, 0);
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);

      lcd.setCursor(0, 4);
      lcd.print("HEATING ");
      lcd.setCursor(0, 3);
    }


  }
}

So, pin 8 is both red and yellow?

A couple of things.

You never do anything with the togglestate variable after you set it when you receive a button so it won't have any affect on your sketch

You read the temperature and store it in 'temperature' but then you read it again to display it????

You need a bit of hysteresis in your temperature check or your system will toggle on/off when it hovers around 25C. Better to turn cooling on above 25C and heading on below 23C or something.

You print "cooling" on line 3 and "heating" on line 4 but there is no line 4 (lines 0-3). They should be on the same line since only one can be on at any given time

#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1  4  // Relay heating
#include <IRremote.h>

const int RECV_PIN = 11;
const int yellowPin = 8;
int togglestate = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

int red = 8; // red LED heating
int blue = 2; // blue LED cooling

#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  irrecv.enableIRIn();
  pinMode(yellowPin, OUTPUT);
  Serial.begin(9600);
  sensors.begin();
  lcd.begin(20, 4);
  lcd.backlight();

  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(RELAY1, OUTPUT);

  lcd.setCursor(0, 0);
  lcd.print("TEMP CONTROL");

}

void loop() {
  if (irrecv.decode(&results)) {

    switch (results.value) {

      case 0x5FA827D:
        if (togglestate == 0) {
          digitalWrite(yellowPin, LOW);
          togglestate = 1;
        }
        else {
          digitalWrite(yellowPin, HIGH);
          togglestate = 0;
        }
        break;

    }
    irrecv.resume();
    
    //lcd.setCursor(0, 0);
    //lcd.print("TEMP CONTROL");

    sensors.requestTemperatures();
    float temperature = sensors.getTempCByIndex(0);
    lcd.setCursor(0, 1);
    //lcd.print("");
    //lcd.print(sensors.getTempCByIndex(0));
    lcd.print(temperature, 1);
    lcd.print("\337C");

    if (temperature > 25)
    {
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);

      lcd.setCursor(0, 3);
      lcd.print("Cooling ");
      digitalWrite(RELAY1, 1);
    }
    else if (temperature < 23)
    {
      digitalWrite(RELAY1, 0);
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);

      lcd.setCursor(0, 3);
      lcd.print("HEATING ");
    }
  }
}

Line up your braces and you'll notice you LCD code is "trapped" inside the if (irrecv.decode(&results)) if statement.

Also, do you really want to update the LCD hundreds or thousands of times a second, every single time loop() runs?

You've also got "yellowPin" and "red" assigned to the same pin.

Blackfin:
Also, do you really want to update the LCD hundreds or thousands of times a second, every single time loop() runs?

Doubtful. Most likely hyperbole. Thouseands of times equals milliseconds, hundreds of thousands equals 10s of nanoseconds.

blh64:
Doubtful. Most likely hyperbole. Thouseands of times equals milliseconds, hundreds of thousands equals 10s of nanoseconds.

Most likely dyslexia -

hundreds or thousands of times

(your quote, my emphasis)

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