@groundFungus , hi! thank you for your help... means a lot...as it is my firs project
The sketch that you've corrected works great.
It is a part of a project. I suppose to write a program that will read data from an LDR and a thermistor( don't know the actual types as it came in a kit, the most basic ones I suppose).
The sketch should contain two main functions:
- Automatic Dawn to Dusk Light with manual override.
- Room temperature controller with manual override and high temperature alarm.
The sketch should work out data and display it in the app:
LDR ->light levels in Lux
Thermistor -> temperature in Centigrade
It should work in auto mode but allow switching it to manual mode
I've created functions for every operation and separately each works fine, but all together...
Al functions send data via serial ports ...
sprintf(Str, "D%d\n", lux);
Serial.write(Str);
Now that I've "piled" up all in one prgram..it doesn't work again....phhh... NUB, what can i say...
Here is the sketch:
#include <math.h>
#include <SoftwareSerial.h>
//Variables:
int whiteLED = 13;
int blueLED = 7;
int greenLED = 6;
int redLED = 5;
int buzzer = 4;
int thermistor_Data = A1;
int LDR_Data = A0;
char BLData; //Variable to receive data
char Str[20];//Variable to send data
SoftwareSerial bt(9, 8); // pin 9 (RX) to HC05 TX,
// pin 8 (TX) to HC05 RX through voltage divider
//LDR functions
double light_LUX();
void light_manual();
int light_auto();
//Thermistor functions
float tempC();
int tempC_auto();
void tempC_manual();
void setup(){
pinMode(whiteLED, OUTPUT);// pin 13 as output
pinMode(blueLED, OUTPUT);// pin 7 as output
pinMode(greenLED, OUTPUT);// pin 6 as output
pinMode(redLED, OUTPUT);// pin 5 as an output
pinMode(buzzer, OUTPUT);//pin 4 as an output
pinMode(thermistor_Data, INPUT);
pinMode(LDR_Data, INPUT);
Serial.begin(9600);//Start serial communication
Serial.println("beginning...");
bt.begin(9600); // HC05 serial communication default baud rate
}
void loop(){
int lux = light_LUX();
int temp = tempC();
char reading;
char lastreading;
bool state = 0; // variable for first status
sprintf(Str, "D%d\n", lux); //the block that displays light measurement and temperature
Serial.write(Str); //inthe app
sprintf(Str, "G%d\n", temp);
Serial.write(Str);
delay(1000);
if (bt.available())//the block that allow to toggle modes auto/manual
{
if (reading != lastreading)
{
if (lastreading == 'Y')
{
state = !state;
if (state)
{
tempC_manual();
light_manual();
// bt.print("Auto Mode "); bt.println(state);
}
else
{
tempC_auto();
light_auto();
// bt.print("Manual Mode "); bt.println(!state);
}
}
lastreading = reading;
}
}
}