i need help about motors and lcd shield..

#include <LiquidCrystal.h>

#include <SoftwareSerial.h>

SoftwareSerial mySerial(A3, A4);

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


byte serialA;
int tempPin = A1;
int motorPin1 = 3; // pin 2 on L293D IC
int motorPin2 = 4; // pin 7 on L293D IC
int enablePin = 5; // pin 1 on L293D IC
int temp;
int tempMin = 18;
int tempMax = 40;
int fanSpeed;
int fanLCD;

void setup() {
    // sets the pins as outputs:
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // sets enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
    // sets motorPin2 always low:
    digitalWrite(motorPin2, LOW);
    pinMode(tempPin, INPUT);
    lcd.begin(16,2);
    // initialize serial communication at 9600 bits per second:
    Serial.begin(57600);
    mySerial.begin(9600);
}

void loop() {
   
if (mySerial.available() > 0) {
serialA = mySerial.read();
mySerial.println(serialA);}

temp = readTemp();     // get the temperature
   if(temp < tempMin) {   // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(motorPin1, LOW);
  
   }
   
      switch (serialA) {
    case 1:
      if((temp >= tempMin) && (temp <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD = map(temp, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(motorPin1, fanSpeed);  // spin the fan at the fanSpeed speed
       digitalWrite(motorPin2, LOW);
      break;
      }
    case 2:
        digitalWrite(motorPin1, LOW);
      break;
      }
   lcd.print("TEMP: ");
   lcd.print(temp);      // display the temperature
   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;
}

im on our arduino project but there is something wrong on it and i don’t know what’s the problem…our arduino project is a fan system. a fan controlled via bluetooth and its fan speed is controlled by a temperature sensor that has lcd shield to display temperature and fanspeed…

the problem is, i cant have the fan to spin when the lcd shield is attached to arduino :frowning:
hope you guys can help us…

im using 5v fan
lcd shield dfrobot
lm35
hc-05 bluetooth module
and l293d IC

I wonder if the liquidCrystal library is interfering with analogWrite. Read up about the timers that provide PWM on pairs of pins. You may get an improvement if you move the LCD to other pins - but I know very little about that library.

...R

how to move LCD pins?? can you please help me.. im a newbie in arduino :(

Robin2: I wonder if the liquidCrystal library is interfering with analogWrite. Read up about the timers that provide PWM on pairs of pins. You may get an improvement if you move the LCD to other pins - but I know very little about that library.

...R

can you please help me with my project?? what sould i do?

makerz241: how to move LCD pins?? can you please help me.. im a newbie in arduino :(

I'm not sure what you mean.

Are you asking about physically connecting the LCD to different Arduino pins? If so you need to provide a link to the datasheet for your LCD so we can see why there is a problem. The LCD that I have can be plugged into any Arduino pin.

OR

Are you asking how to change the software so that it reflects changes in the physical pin arrangement?

...R

According to your program;

LCD uses pins 4,5,6,7,8,9 and watch out for pin 10 (Back light short problems)

You have the motor set up on pins 3,4 and 5... so pins 4 and 5 are in conflict.

Choose some other pins for the motor like 11,12,13

Good Luck

problem solved!!! :D :D :D :D :sunglasses: :sunglasses: :sunglasses:

Hi, Tell us how you solved it, that way someone else can learn from your experience.

Tom.... :)