Greetings to all of you brilliant people,
I am humbly asking for help with my Final Year Project. My IR LED transmitter does not want to send the signal to AC. I even turn on my phone's camera to see if there is any flickering light through my camera, but there is none. I have had to debug this problem for almost ten months now, and I am at a dead end. My coding has no problems because it can upload to my Arduino Mega.
Btw, I also using TSOP1738 for decoding a signal from AC's remote control and all the outputs seem working for me. Again, I need your help to get IR LED Transmitter to be working.
below is my sketch circuit:
And below is my coding part:
#include <IRremote.hpp>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#include <IRremote.h>
IRsend irsend;
#define OLED_MOSI 3
#define OLED_CLK 4
#define OLED_DC 5
#define OLED_CS 6
#define OLED_RESET 7
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SSD1306_LCDHEIGHT 64
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
//#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 48
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#define PIEZO 8
#define ALARM 1000
#define LED 40
int Sound[] = {ALARM, ALARM};
int SoundNoteDurations[] = {4, 4};
#define playSound() playMelody(Sound, SoundNoteDurations, 2)
char inChar;
String inString;
#define Desired_temperature 23
int AC_Temp;
char temp_error = 2;
int Pev_value;
boolean AC = false;
void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
dht.begin();
pinMode(LED, OUTPUT);
}
void loop() {
// Wait a few seconds between measurements.
//delay(2000);
// 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(F("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 (hic >= 40) {
displayOled();
playSound();
}
else {
displayOled();
sendACsignal(); /***********Calling Send Signal to A/C Class Module**********/
noTone(PIEZO);
}
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.print(F("°C | Humidity: "));
Serial.print(h);
Serial.print(F("% "));
Serial.print(F(" | Heat index: "));
Serial.print(hic);
Serial.print(F("°C | AC Temp: "));
Serial.println(AC_Temp);
delay(18000);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(50);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(50);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(18000);
}
/***********OLED Display Module**********/
void displayOled() {
// Read humidity
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);
// 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);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(0.5);
display.setCursor(0, 0);
display.print("Temparature:");
display.setCursor(77,0);
display.print(t);
display.print((char)247);
display.print("C");
display.setCursor(0, 10);
display.print("Humidity :");
display.setCursor(77, 10);
display.print(h);
display.print(" %"); // degree symbol
display.setCursor(0, 20);
display.print("Heat Index :");
display.setCursor(77, 20);
display.print(hic);
display.print((char)247); // degree symbol
display.print("C");
display.display();
delay(18000);
}
/***********Send Signal to A/C Module**********/
void sendACsignal(){
float t = dht.readTemperature()+temp_error;
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int ACon[]={3200,1550, 450,400, 450,1100, 450,400, 450,350, 450,1150, 450,400, 450,1150, 450,350, 450,400, 450,1150, 450,1150, 450,1150, 450,350, 450,1150, 450,400, 400,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 450,1150, 450,350, 450,400, 450,1100, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 450,1100, 500,1100, 500,1150, 450,1100, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,400, 450,350, 450};
unsigned int ACoff[]={3200,1600, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,1150, 450,400, 400,1150, 450,400, 400,1200, 400,1200, 400,1200, 400,400, 450,350, 450,400, 450,400, 400,1200, 400,1200, 400,400, 450,1150, 400,1200, 400,450, 400,400, 400,1200, 400,400, 450,400, 400,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 400,1200, 400,1200, 400,1200, 400,1200, 400,1200, 400,1200, 400,1200, 400,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 450,400, 400,400, 450};
unsigned int Temp16[]={3150,1600, 450,350, 450,1200, 400,400, 450,350, 450,1150, 450,400, 400,1200, 400,400, 450,400, 400,1200, 400,1200, 400,1200, 400,400, 450,1150, 450,350, 450,1150, 450,1200, 400,1150, 450,400, 400,400, 450,400, 400,400, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,400, 450,350, 450,1150, 450,400, 400,450, 400,1150, 450,400, 400,400, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,1200, 400,1200, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 400,450, 400,400, 400};
unsigned int Temp17[]={3200,1600, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,1100, 500,350, 450,400, 450,1100, 450,1150, 450,1150, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1100, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 450,1150, 450,1150, 450,1150, 450,1100, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,400, 450,350, 450};
unsigned int Temp18[]={3200,1600, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,1150, 450,350, 450,400, 450,1150, 450,1150, 450,1100, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 450,1100, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1100, 450,1150, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,400, 450,350, 450};
unsigned int Temp19[]={3150,1600, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,350, 450,1150, 450,400, 450,400, 400,1200, 400,1200, 400,1200, 400,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,1150, 450,1150, 400,400, 450,1150, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,1200, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,350, 450,400, 450};
unsigned int Temp20[]={3200,1600, 450,350, 450,1150, 450,350, 450,400, 400,1200, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 400,1200, 450,350, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 400,400, 450,400, 450,1150, 400,1200, 400,400, 450,1150, 450,1150, 450,400, 400,400, 450,1150, 450,350, 500,350, 450,1150, 400,400, 450,400, 400,1200, 400,1200, 400,400, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 400,1200, 400,1200, 400,1200, 400,1200, 400,400, 450,400, 400,400, 450,400, 400,400, 450,400, 400};
unsigned int Temp21[]={3200,1550, 450,400, 450,1150, 450,350, 450,400, 400,1150, 500,350, 450,1150, 450,350, 450,400, 450,1150, 400,1200, 400,1200, 400,400, 450,1150, 450,400, 400,1200, 450,1100, 450,1200, 450,350, 450,350, 500,350, 450,350, 450,1150, 450,1150, 450,400, 450,1150, 400,1200, 450,350, 450,400, 400,1150, 450,400, 450,350, 450,1150, 500,350, 450,400, 400,1150, 450,1150, 450,400, 450,1150, 400,1200, 400,1200, 450,1100, 450,1150, 450,1200, 400,1150, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 400,400, 450,400, 400,400, 450};
unsigned int Temp22[]={3150,1650, 450,350, 450,1150, 450,350, 450,400, 450,1150, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 400,400, 450,400, 450,350, 450,400, 450};
unsigned int Temp23[]={3200,1600, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,350, 450,400, 450};
unsigned int Temp24[]={3200,1600, 400,400, 450,1150, 450,350, 450,400, 450,1150, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,1150, 450,400, 400,1200, 400,400, 450,1150, 450,1150, 450,1150, 400,400, 450,400, 400,450, 400,400, 400,1200, 400,1200, 400,400, 450,1150, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,350, 450,400, 450,1150, 400,1200, 400,450, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 400,1200, 400,400, 450,400, 400,400, 450,400, 400,400, 450,400, 400};
unsigned int Temp25[]={3200,1600, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,1150, 450,400, 400,400, 450,1150, 450,1150, 450,1150, 450,400, 400,1150, 450,400, 450,1150, 450,1150, 400,1200, 400,400, 450,400, 400,450, 400,400, 400,1200, 400,1200, 400,400, 450,1150, 450,1150, 450,350, 450,400, 450,1150, 450,350, 450,400, 450,1150, 400,450, 400,400, 400,1200, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 400,1200, 450,1150, 450,350, 450,400, 450,350, 450,400, 400,400, 450,400, 400};
unsigned int Temp26[]={3200,1600, 400,400, 450,1150, 400,450, 400,400, 400,1200, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,1150, 450,400, 400,1200, 400,400, 400,1200, 400,1200, 400,1200, 400,400, 450,400, 400,400, 450,400, 450,1150, 400,1200, 400,400, 450,1150, 450,1150, 400,450, 400,400, 400,1200, 400,400, 450,400, 450,1150, 400,400, 450,400, 400,1200, 400,1200, 400,400, 450,1150, 450,1150, 400,1200, 400,1200, 450,1150, 400,1150, 450,1200, 400,1200, 450,1150, 450,1150, 400,400, 450,400, 400,400, 450,400, 400,400, 450,400, 400};
unsigned int Temp27[]={3200,1600, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,1100, 500,350, 450,400, 450,1100, 500,1100, 500,1100, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 450,350, 450,400, 450,350, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,350, 450,400, 450};
unsigned int Temp28[]={3150,1600, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,1200, 400,400, 450,400, 400,1200, 400,1200, 400,1150, 450,400, 450,1150, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,400, 400,1200, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,400, 400,400, 450,350, 450,400, 450};
unsigned int Temp29[]={3150,1600, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,400, 400,1200, 400,400, 450,400, 400,1150, 450,1150, 450,1150, 450,400, 450,1150, 450,350, 450,1200, 400,1200, 400,1150, 450,400, 400,450, 400,400, 400,400, 450,1150, 450,1150, 450,400, 400,1200, 400,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,400, 400,1200, 400,1200, 400,1200, 400,1200, 400,1200, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 450,400, 400,400, 450};
unsigned int Temp30[]={3200,1600, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,350, 450,1150, 450,400, 450,350, 450,1150, 450,1150, 450,1150, 450,400, 400,1200, 400,400, 450,1150, 450,1150, 450,1150, 450,400, 400,400, 450,400, 400,400, 450,1150, 450,1150, 450,350, 450,1150, 450,1150, 450,400, 450,400, 400,1200, 400,400, 400,400, 450,1150, 450,400, 400,400, 450,1150, 450,1150, 450,400, 400,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,1150, 450,350, 450,400, 450,350, 450,400, 450,350, 450,400, 450};
if ((t <= (Desired_temperature-7)) && AC == true){ //20*=off If AC is turned on and temperature is less than 3 degree of Desired value #24 turn off
irsend.sendRaw(ACoff, sizeof(ACoff) / sizeof(ACoff[0]), khz);
delay(3000);//Send signal to Turn Off the AC
AC_Temp = 0; AC=false;
}
if ((t >= Desired_temperature+5) && AC == false){ //27*=on If AC is off and measured Temp is greater than Desired Temp
irsend.sendRaw(ACon, sizeof(ACon) / sizeof(ACon[0]), khz);
delay(2000); //Send Signal to Turn On the AC
delay(3000);
irsend.sendRaw(Temp23, sizeof(Temp23) / sizeof(Temp23[0]), khz); //Send signal to set 23*C
AC_Temp = 23; AC=true;
}
if ( t != Pev_value){ //Change the temperature only if the measured voltage value changes
if (t == Desired_temperature+3){ //26*==23 If AC is ON and measured temp is very high than desired
irsend.sendRaw(Temp23, sizeof(Temp23) / sizeof(Temp23[0]), khz);
delay(3000);//Send signal to set 25*C
AC_Temp = 23;
}
if (t == Desired_temperature+2){ //25*==24 If AC is ON and measured temp is very high than desired
irsend.sendRaw(Temp24, sizeof(Temp24) / sizeof(Temp24[0]), khz); delay(2000);//Send signal to set 26*C
AC_Temp = 24;
}
if (t == 23 ){ //23*==23 If AC is ON and measured temp is desired value
irsend.sendRaw(Temp23, sizeof(Temp23) / sizeof(Temp23[0]), khz); //Send signal to set 27*C
AC_Temp = 23;
}
if (t == Desired_temperature-6){ //16*=+26 If AC is ON and measured temp is low than desired value
irsend.sendRaw(Temp26, sizeof(Temp26) / sizeof(Temp26[0]), khz); delay(2000);//Send signal to set 28*C
AC_Temp = 26;
}
if (t == Desired_temperature-3){ //20*=+25 If AC is ON and measured temp is low than desired value
irsend.sendRaw(Temp25, sizeof(Temp25) / sizeof(Temp25[0]), khz); delay(2000);//Send signal to set 28*C
AC_Temp = 25;
}
}
Pev_value = t;
}
/***********Buzzer Module**********/
void playMelody(int *melody, int *noteDurations, int notesLength)
{
pinMode(PIEZO, OUTPUT);
for (int thisNote = 0; thisNote < notesLength; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIEZO, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(PIEZO);
}
}