/*
* HVAC car control with Arduino
* Version 1.0
* Copyright (C) 2018 Hartmut Wendt www.hwhardsoft.de
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include <OneWire.h>
#include <TimerOne.h>
// Portkonfiguration
#define REL_VENT_FRONT 5 //relay output for ventilation front
#define REL_VENT_FOOT 6 //relay output for ventilation footwell area
#define REL_VENT_WINDOW 7 //relay output for ventilation window
#define REL_FAN_PWR 8 //relay output for fan power
#define PWM_FAN_PIN 9 //PWM output for fan power
#define REL_COMPRESSOR 11 //relay output for AC compressorr
#define REL_HEATING 12 //relay output for heating valve
#define REL_AIR_CIRCULATION 13 //relay output for air circulation
#define REL_FOG_LIGHT 14 //relay output for fog light
#define REL_HEATING_WINDOW_FRONT 15 //relay output for window heating front
#define REL_HEATING_WINDOW_REAR 16 //relay output for window heating rear
#define TEST_PIN 19 // output for sw tests
// OneWire DS18S20, DS18B20, DS1822 Temperature sensor
OneWire sens_out(2); // outside temperature sensor on D2
OneWire sens_in_right(3); // inside right side temperature sensor on D3
OneWire sens_in_left(4); // inside left side temperature sensor on D4
int temp_out = 20; // measured outside temperature
int temp_in_right = 20; // measured inside right side temperature
int temp_in_left = 20; // measured inside left side temperature
int set_in_right = 20; // setted inside right side temperature
int set_in_left = 20; // setted inside left side temperature
// Variables
int i1;
char *test;
String s1;
String inputString;
boolean AC_ENABLED = false;
int bscheduler = 0;
/** Wird beim Start einmal ausgeführt */
void setup()
{
// set port direction
pinMode(REL_VENT_FRONT, OUTPUT);
pinMode(REL_VENT_FOOT, OUTPUT);
pinMode(REL_VENT_WINDOW, OUTPUT);
pinMode(REL_FAN_PWR, OUTPUT);
pinMode(REL_COMPRESSOR, OUTPUT);
pinMode(REL_HEATING, OUTPUT);
pinMode(REL_AIR_CIRCULATION, OUTPUT);
pinMode(REL_FOG_LIGHT, OUTPUT);
pinMode(REL_HEATING_WINDOW_FRONT, OUTPUT);
pinMode(REL_HEATING_WINDOW_REAR, OUTPUT);
pinMode(TEST_PIN, OUTPUT);
// init serial port for nextion communication.
Serial.begin(9600);
delay(250);
// first read in of temperatures
temp_out = read_temperature(sens_out);
delay(100);
temp_in_right = read_temperature(sens_in_right);
delay(100);
temp_in_left = read_temperature(sens_in_left);
//pwm init
Timer1.initialize(1000); // 1.000 us = 1 kHz
Timer1.pwm (PWM_FAN_PIN, 0);
}
// ----- Main loop -----------------------------------------------------------------------------------
void loop()
{
// processing of incomming messages from nextion
Nextion_processing();
switch(bscheduler)
{
// measure outside temperature
case 0:
temp_out = read_temperature(sens_out);
// transmit outside temperature to nextion display
Serial.print("ID1.val=");
Serial.print(temp_out);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
break;
// measure inside right temperature
case 25:
temp_in_right = read_temperature(sens_in_right);
break;
// measure inside left temperature
case 50:
temp_in_left = read_temperature(sens_in_left);
break;
// HVAC control
case 75:
clima_control();
break;
}
bscheduler++;
if (bscheduler > 100) bscheduler = 0;
delay(10);
}
// read temperature from a connected 1wire temperature sensor
int read_temperature...
Read more »
Hello what Nextion screen model did you do this for?