Hi , thank you for the quick response.
I tried to use a switch table as follow :
void loop
(value) serial read:
switch = value
{
case 1 = 'a' - this one is for auto
case 2 = 'b' - togle relay 1 on
case 3 = 'c' -togle relay 1 off
case 4 = 'b' - togle relay 2 on
case 5 = 'c' -togle relay 2 off
case 6 = 'b' - servo open
case 7 = 'c' -servo closed
}
But i can't get case 1 to run in a loop .
i am just starting to code so my code is made from what i found here and there also at the end there are some cases missing
code :
#include "Servo.h"
char value;
int sensorH_pin = A1;
int Humidity ;
int sensor_pin = 8;
int ThermistorPin = A0;
int Vo;
float R1 = 4580;
float logR2, R2, T, Tc;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
Servo servo1; //creat servo obj
#include "Servo.h"
char value;
int sensorH_pin = A1;
int Humidity ;
int sensor_pin = 8;
int ThermistorPin = A0;
int Vo;
float R1 = 4580;
float logR2, R2, T, Tc;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
Servo servo1; //creat servo obj
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(sensor_pin, INPUT);
servo1.attach(6);
servo1.write(20);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
}
int getTemp ()
{
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Tc = T - 273.15;
return Tc;
// Serial.print("Temperature: ");
// Serial.print(Tc);
// Serial.println(" C");
}
int getHumidity ()
{
Humidity = analogRead(sensorH_pin);
Humidity = map(Humidity, 550, 0, 0, 100);
return Humidity;
}
void loop()
{
getTemp();
getHumidity ();
Serial.print("Temperature: ");
Serial.print(Tc);
Serial.println(" C");
Serial.print("Umiditate: ");
Serial.print(Humidity);
Serial.println(" %");
delay (1000);
if (Serial.available())
value = Serial.read ();
switch (value)
{
case 'a':
Serial.println("a");
if (Tc >= 30)
{
digitalWrite ( 3 , LOW); //fan condition turnon if temp>30 C
servo1.write(90);
}
else
{
digitalWrite ( 3 , HIGH); //fan condition turnon if temp<30 C
servo1.write(20);//window
}
case 'b':
digitalWrite ( 3 , HIGH); //fan off
break;
case 'c':
digitalWrite ( 3 , LOW); //fan off
break;
}
}