I am trying to make a thermostat for an airconditioning. I already figured out how to make the arduino connect with the temperature sensor and use relay’s to control the airconditioner. Now I’m trying to connect it to thingspeak via wifi by the ESP. I already managed to connect it but now I’m stuck. I would like to combine these two sketches in to one. Till now unsuccessfull. thanks for the help.
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2, 3);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println(“Started”);
// set the data rate for the SoftwareSerial port
esp8266.begin(115200);
esp8266.write(“AT\r\n”);
esp8266.write(“AT+CIPMUX=1\r\n”);
}
void loop() {
if (esp8266.available()) {
Serial.write(esp8266.read());
}
if (Serial.available()) {
esp8266.write(Serial.read());
}}
by filling in these codes in the serial monitor I’m able to connect with the arduino and esp to thingspeak
AT+CIPMUX=1
AT+CIPSTART=4,“TCP”,“184.106.153.149”,80
AT+CIPSEND=4,44
GET /update?key=PYE3H33PNRWA1LD0&field1=70
AT+CIPCLOSE=4
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include “DHT.h”
#define DHTPIN 2 // Temperature sensor
#define CH1compressor 7 //relais with compressor
#define CH2fan 8 //relais with fan
#define DHTTYPE DHT11 // DHT 11
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
delay (2000);
Serial.begin(9600);
Serial.println(“DHTxx test!”);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (13, OUTPUT);
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
if (f>78) {
digitalWrite (7, HIGH);
digitalWrite (8, HIGH);
delay (300000);
}
else
{
digitalWrite (7, LOW);
digitalWrite (8, HIGH);
}
digitalWrite (13, LOW);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}