spirit - thanks for the pointers, but I'm not sure what you're suggesting... I tried updating my code a little but it hasn't really fixed the issue of cycling through the modes automatically.
UKHeliBob - yeah, maybe that's my hangup... but how do I write that in the code? Where did I go wrong?
/*
This sketch will control a fan circuit with an IR "CarMP3" remote control.
Fan Modes: (controlled with EQ button)
fanMode=0 - OFF
fanMode=1 - MANUAL
fanMode=2 - AUTO
Fan Speeds: (controlled with Vol- and Vol+ buttons)
fanSpeed=0 - OFF
fanSpeed=1 - LOW
fanSpeed=2 - MEDIUM
fanSpeed=3 - HIGH
-Manual mode allows you to select fan speed yourself with Vol- and Vol+ buttons.
-Auto mode adjusts the fan speed based on temperature reading from DHT11 sensor.
The 2 outputs muxA and muxB trigger inputs for a demultiplexer to select 4 outputs,
which are connected to relays that apply power to one line of the fan.
*/
#include <IRremote.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#define DHTPIN 3
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
const int remote = 2;
const int muxA = 4;
const int muxB = 5;
int fanMode = 0;
int fanSpeed = 0;
int modeStatus = 0;
int speedStatus = 0;
int prevInput = 0;
LiquidCrystal lcd(8,9,10,11,12,13);
IRrecv irrecv(remote);
decode_results results;
void setup() {
lcd.begin(16,2);
dht.begin();
irrecv.enableIRIn();
pinMode(muxA, OUTPUT);
pinMode(muxB, OUTPUT);
}
void loop() {
float t = dht.readTemperature(); //take temp reading from sensor
float tf = (t*1.8)+32; //convert Celcius to Farenheit
lcd.clear();
if (isnan(t)){ //error display for bad temp sensor read
lcd.setCursor(0,0);
lcd.print("Failed DHT read");
}
else{ //display temps
lcd.setCursor(0,0);
lcd.print(t);
lcd.print("C - ");
lcd.print(tf);
lcd.print("F");
}
if (irrecv.decode(&results)){
irrecv.resume(); // Receive the next value
}
if(prevInput != results.value){
switch(results.value){
case 16748655: // EQ button is pressed
if(fanMode == 2)
modeStatus=0;
else
modeStatus = fanMode+1;
break;
case 16769055: // Vol- button is pressed
if(fanMode == 1 && fanSpeed>0)
speedStatus=fanSpeed-1;
break;
case 16754775: //Vol+ button is pressed
if(fanMode == 1 && fanSpeed<3)
speedStatus=fanSpeed+1;
break;
/*
case default:
lcd.setCursor(0,1);
lcd.print("Invalid input!");
delay(3000);
*/
}
}
prevInput = results.value;
fanSpeed=speedStatus;
fanMode=modeStatus;
if(fanMode==2){
if(t>=29){
fanSpeed=3;
lcd.setCursor(0,1);
lcd.print("AUTO - HIGH");
}
else if(t>=26 && t<=28){
fanSpeed=2;
lcd.setCursor(0,1);
lcd.print("AUTO - MEDIUM");
}
else if(t>=23 && t<=25){
fanSpeed=1;
lcd.setCursor(0,1);
lcd.print("AUTO - LOW");
}
else{
fanSpeed=0;
lcd.setCursor(0,1);
lcd.print("AUTO - OFF");
}
}
else if(fanMode==1){
if(fanSpeed==3){
lcd.setCursor(0,1);
lcd.print("MANUAL - HIGH");
}
else if(fanSpeed==2){
lcd.setCursor(0,1);
lcd.print("MANUAL - MEDIUM");
}
else if(fanSpeed==1){
lcd.setCursor(0,1);
lcd.print("MANUAL - LOW");
}
else if(fanSpeed==0){
lcd.setCursor(0,1);
lcd.print("MANUAL - OFF");
}
}
else if(fanMode==0){
fanSpeed=0;
lcd.setCursor(0,1);
lcd.print("FAN MODE - OFF");
}
/*
if(fanSpeed==3){
muxA=1;
muxB=1;
}
else if(fanSpeed==2){
muxA=0;
muxB=1;
}
else if(fanSpeed==1){
muxA=1;
muxB=0;
}
else{
muxA=0;
muxB=0;
}
*/
delay(1000);
}