i want to change my tempMin value via blutooth..

#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.

thx! hoping for a solution...

you can download the apps here https://drive.google.com/file/d/0B8NzmsrxgBNUd2VRdEhlYXVhc0U/view?usp=sharing

Have a look at the examples in serial input basics. One of them should probably meet your needs.

If you provide more information about what your existing code does and what it should do we may be able to help more.

...R

hi Robin!

thx for your response

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...

now my problem is how can i change the value of my "tempMin" thru my apps

Solving that problem means breaking it down into manageable steps.

First, you make the phone send some data. You have not proved that that is happening.

Second, you make the Arduino read the incoming data. HOW to do that is what Robin2 was showing.

Third, you make the Arduino parse the data that it got. How to do THAT depends on how you store the data and what the stored data looks like.

Just wishing does not make code appear. It doesn't make it work, either. You ACTUALLY have to try stuff.

i really don't know what to do... sorry im a newbie in this stuff...

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"..

i really have to finish this project of ours.. we need finish this til aug 8 :frowning:
this is our IT capstone project..

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! :slight_smile: so, they were like amazed..heheh

you must be pretty awesome! doing your project easy :slight_smile:

PaulS:
No problem. You have (part of) 4 days.

i only have 3days left..im from philippines by the way :slight_smile:

i used app inventor 2 you can see it here..
https://drive.google.com/file/d/0B8NzmsrxgBNUWVNJS2ZZZnFGZ3c/view?usp=sharing

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:
Oops. I'd suggest you quit wasting it,

yeah that's what im doing right now :slight_smile:

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 :frowning:

int serialA;

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.

PaulS:

int serialA;

Change the type to char, send some data to the Arduino, explain what you sent, and show us the output from the Serial Monitor.

ok working on it...

should i also do this

int tempMin = 18;

change to

char tempMin;

and what should i input so i can modify the value of my "tempMin"

in this code:

if (mySerial.available()>0) {
    serialA = mySerial.read();
    Serial.write(serialA);
    Serial.println(mySerial);
  }

see attached file

should i also do this

No. tempMin is appropriate as int.

and what should i input so i can modify the value of my "tempMin"

One step at a time. This is step 8, and step 1 doesn't work yet.

done...now it only shows "a" and "b"

see attached file

Please don't post pictures of text. Copy and paste the text.

I can't see your code.

here is the app looks like!

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.

it's working well...

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.

  if (serialA == 'b') {
    fanLCD = map(temp, tempMin, tempMax, 0, 0);
    SoftPWMSet(fan, 0); //        digitalWrite(fan, LOW);
}

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

If the phone is sending a binary value:

if(serialA != 'a' && serialA != 'b')
{
   tempMin = serialA;
}