#include <LiquidCrystal.h>
#include <SoftPWM.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A1, A2); // RX, TX correct tested
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int serialA;
int tempPin = A4; // the output pin of LM35
int fan = A5; // the pin where fan is
int temp;
int tempMin = 18; // how can i set this to changeable value via android apps thru bluetooth?
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
SoftPWMBegin();
SoftPWMSet(fan, 0);
pinMode(fan, OUTPUT);
pinMode(tempPin, INPUT);
pinMode(remote, INPUT);
// digitalWrite(fan,HIGH);
// digitalWrite(remote,HIGH); //enable internal pull up
lcd.begin(16, 2);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (mySerial.available()>0) {
serialA = mySerial.read();
Serial.write(serialA);
Serial.println(mySerial);
}
temp = readTemp(); // get the temperature
if (temp < tempMin) { // if temp is lower than minimum temp
SoftPWMSet(fan, 0);
// digitalWrite(fan, LOW);
}
if (serialA == 'a') {
if ((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 101, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
// analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
SoftPWMSet(fan, fanSpeed);
// Serial.println(fanSpeed);
}
}
if (serialA == 'b') {
fanLCD = map(temp, tempMin, tempMax, 0, 0);
SoftPWMSet(fan, 0);
// digitalWrite(fan, LOW);
}
lcd.print("TEMP: ");
lcd.print(temp); // display the temperature
lcd.write(0b11011111);
lcd.print("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FANS: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125;
}
Hi good day everyone!
please help me..
i want my tempMin to be changeable via android app thru bluetooth..
my tempMin is = 18
how can i change it to other value thru bluetooth?
i already created an app..see attached file.
the code does is just to control the fan speed via temperature sensor and remoted thru android apps then the lcd shield display the current temperature and speed of the fan.
int tempMin = 18; >this is the condition for the fan to start.. if the temperature meet this condition the fan will start.
int tempMax = 40; > the maximum temperature for the fan to reach 100% speed.
now my problem is how can i change the value of my "tempMin" thru my apps
for example i want my fan to start my fan at 20 or lower than 40...
my phone sends data.. for example i send a value of 33, in serial monitor it show "!1" then i send 38, serial monitor shows "&1"..
So, you have at least some code that reads the data from the phone (possibly incorrectly) and writes to the serial port.
WHERE IS THAT CODE?
i really have to finish this project of ours.. we need finish this til aug 8
No problem. You have (part of) 4 days.
this is our IT capstone project..
That's hard to believe. My capstone project was far more complicated. On the other hand, I didn't leave mine to the last minute. I also did far more than was required AND completed the project two weeks early so I could go on vacation.
PaulS:
So, you have at least some code that reads the data from the phone (possibly incorrectly) and writes to the serial port.
WHERE IS THAT CODE?
i used app inventor 2 you can see it here..
PaulS:
That's hard to believe. My capstone project was far more complicated. On the other hand, I didn't leave mine to the last minute. I also did far more than was required AND completed the project two weeks early so I could go on vacation.
yes it is! bcoz i'm the only student who proposed an arduino project! so, they were like amazed..heheh
you must be pretty awesome! doing your project easy
I can't see that site, because it is blocked by the proxy server that I go through. However, I have some doubts that that code will work on an Arduino.
You have some Arduino code you want to share HERE?
you must be pretty awesome!
I never doubted it for a minute. 8)
i only have 3days left
Oops. I'd suggest you quit wasting it, and starting showing some Arduino code. Clearly, it is that code that isn't doing what you want.
PaulS:
it is that code that isn't doing what you want.
the code that i post was working...
#include <LiquidCrystal.h>
#include <SoftPWM.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A1, A2); // RX, TX correct tested
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int serialA;
int tempPin = A4; // the output pin of LM35
int fan = A5; // the pin where fan is
int temp;
int tempMin = 18; // how can i set this to changeable value via android apps thru bluetooth?
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
SoftPWMBegin();
SoftPWMSet(fan, 0);
pinMode(fan, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (mySerial.available()>0) {
serialA = mySerial.read();
Serial.write(serialA);
Serial.println(mySerial);
}
temp = readTemp(); // get the temperature
if (temp < tempMin) { // if temp is lower than minimum temp
SoftPWMSet(fan, 0);
}
if (serialA == 'a') {
if ((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 101, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
SoftPWMSet(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
}
if (serialA == 'b') {
fanLCD = map(temp, tempMin, tempMax, 0, 0);
SoftPWMSet(fan, 0);
}
lcd.print("TEMP: ");
lcd.print(temp); // display the temperature
lcd.write(0b11011111);
lcd.print("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FANS: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125;
}
my only problem is how to have my tempMin changeable... dunno what code to input.. im confused
Why? The read() method returns an int, so that it can return an error flag in the high order byte, if there is no data to read. Since you actually check, all the data will be in the low order byte. So, uint8_t, byte, boolean, or char are more appropriate.
Since the phone is probably sending ASCII data, using char makes more sense to me.
Change the type to char, send some data to the Arduino, explain what you sent, and show us the output from the Serial Monitor.
We need to assure that what you sent is what you get. If not, no amount of wishful thinking is going to make the incoming data useful.
We'll assume that the phone is working correctly. We can not correlate what you see in the Serial Monitor with the phone code, though, without knowing what you did with the phone.
I see a code block that sends "b" when a button is clicked.
I see a code block that sends "a" or "b" when you say off or on.
I see a code block that sends a 1 byte number when you click a button.
I don't know what you actually did, so I can't tell whether just seeing a or b is reasonable.
I don't know what the Send1ByteNumber() function is doing. You might want to just send the text in the box, though, instead of converting it to a number and sending the number. I suspect that the number is sent as a binary value.
If that is the case, printing it will not prove useful.
codeblock that sends "a" when a button is clicked.
if (serialA == 'a') {
if ((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 101, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
SoftPWMSet(fan, fanSpeed); // analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
codeblock that sends "a" when a button is clicked.
codeblock that send1 byte when clicked
-this is for the tempMin... and this is the problem.. dont know what code to input to arduino to receive the value
codeblock that send1 byte when clicked
-this is for the tempMin... and this is the problem.. dont know what code to input to arduino to receive the value