Help please!!!

hi im having a serial problem…

my application is not responding with arduino even if it is connected…
something wrong with mySerial…

hope anyone could help me…

thx in advance!!

#include <SoftPWM.h>
#include <SoftPWM_timer.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(A1, A2); // RX, TX correct tested

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
String readString;
int tempPin = A4;   // the output pin of LM35
int fan = A5;       // the pin where fan is

int temp;
int tempMin = 20;   // the temperature to start the fan
int tempMax = 40;   // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;

 
void setup() {
  
  SoftPWMBegin();

  pinMode(fan, OUTPUT);
  pinMode(tempPin, INPUT);
  pinMode(remote, INPUT);
  
 // digitalWrite(fan,HIGH);
  
  lcd.begin(16,2);  
  Serial.begin(9600);
  mySerial.begin(9600);
}
 
void loop() {  


   temp = readTemp();     // get the temperature

     if (temp < tempMin) {   // if temp is lower than minimum temp
         SoftPWMSet(fan,0);
//         digitalWrite(fan, LOW);       
    }
      while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c;
  } 
      if (readString.length() >0) {
    Serial.println(readString);
    mySerial.println(readString);
    if (readString == "on") {
      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 (readString == "off") {
        fanLCD = map(temp, tempMin, tempMax, 0, 0);
        SoftPWMSet(fan,0); //        digitalWrite(fan, LOW);
        readString="";
   }
   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,
Can you please explain what you have connected to your arduino, and what model arduino are you using.

What is your sketch is supposed to do and what it is or is not doing.

Tom... :slight_smile:

TomGeorge:
Hi,
Can you please explain what you have connected to your arduino, and what model arduino are you using.

What is your sketch is supposed to do and what it is or is not doing.

Tom... :slight_smile:

hi Tom
i have arduino uno
the temperature sensor controls the fan speed of the fan and remoted via bluetooth thru android application

   if (readString == "on") {
[...]
      }
    }
      }
    if (readString == "off") {
 [...]
   }

I'm not into analyzing the whole thing, but normally those complimentary statements would be contained in the same block. They clearly are not.

Try using one of the examples in serial input basics. They are simple and reliable.

...R