1

I have connected a Bluetooth shield and LCD screen to an Arduino Uno. I have two active low push buttons to increase or decrease the variable desiredTemp. This value is meant to be displayed on the LCD screen, and on my smartphone over the Bluetooth serial connection.

This works as intended for my smartphone, however, when my transmission and receive pins are connected to the board the LCD screen is frozen until the pins are removed. Additionally, I'm not able to update the desiredTemp variable through the Bluetooth serial connection.

Attached is my code:

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

LiquidCrystal LCD(10,9,3,2,1,0);
double inIRPin = A0;
double inThermPin = A1; 

int LED = 4;
char recvChar;

int increaseTemp = 7;
int decreaseTemp = 6;
int increaseTempState = 0;
int decreaseTempState = 0;

#define RxD         13
#define TxD         12
SoftwareSerial BTSerial(RxD,TxD);

double valIR = 0;
double valTherm = 0;
double val = 0;
double temp = 0;
double const tempRatio = 0.125;
double desiredTemp = 40; //Degrees Celcius

void setup() {
 // put your setup code here, to run once:

 pinMode(increaseTemp,INPUT);
 pinMode(decreaseTemp,INPUT);

pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(LED, OUTPUT);
setupBlueToothConnection();

pinMode(inIRPin, INPUT);
pinMode(inThermPin, INPUT);
LCD.begin(16,2); 
LCD.setCursor(0,0);

}

void loop() {
  // put your main code here, to run repeatedly:
   valIR = analogRead(inIRPin); //IR Sensor Output
  valTherm = analogRead(inThermPin);

   increaseTempState = digitalRead(increaseTemp);
   decreaseTempState = digitalRead(decreaseTemp);

   if(increaseTempState == LOW){
    desiredTemp++;
  }
   if(decreaseTempState == LOW){
     desiredTemp--;
   }
   if(BTSerial.available()){
      recvChar = BTSerial.read();
      Serial.print(recvChar);
      BTSerial.println(desiredTemp);
      if(increaseTempState == LOW){
         desiredTemp++;
         updateLCD();
       }
       if(decreaseTempState == LOW){
         desiredTemp--;
         updateLCD();
       }
       if(recvChar == '1'){
         BTSerial.println("Increasing Temp");
         desiredTemp++;
       }
       if(recvChar == '0'){
         BTSerial.println("Decreasing Temp");
         desiredTemp--;
       }
   }
    updateLCD();
  }

 void setupBlueToothConnection()
 {  
    BTSerial.begin(9600);  

    BTSerial.print("AT");
    delay(400); 

    BTSerial.print("AT+DEFAULT");             // Restore all setup value to 
    factory setup
    delay(2000); 

    BTSerial.print("AT+NAMESmartCoaster");    // set the bluetooth name 
    delay(400);

    BTSerial.print("AT+PIN0000");             // set the pair code to connect 
    delay(400);

    BTSerial.print("AT+AUTH1");             //
    delay(400);    

    BTSerial.flush();

  }

 void updateLCD(){
      LCD.setCursor(0,0);
      LCD.print("Current Temp:");
      LCD.println(temp);
      LCD.setCursor(0,1);
      LCD.print("Desired Temp:");
      LCD.println(desiredTemp);
      delay(100);
  }
4
  • So you connected the LCD to RX and TX pins and wonder why the LCD fails when the serial sends something? – gre_gor Feb 21 '18 at 19:33
  • Nope the LCD screen is using pins 10,9,3,2,1,0. Rx is using pin 13 and Tx is using pin 12. – Neil Feb 21 '18 at 19:36
  • 1
    Serial.print(recvChar); sends to pins 0 and 1. – gre_gor Feb 21 '18 at 19:36
  • I need some help with Arduino serial communication, could you please tell me one thing, if I want to connect two serial communication with Arduino Uno pin 2,3 and normal hardware serial communication 0,1 and two devices are one is Bluetooth and another one is GPS, so my question is there is any problem will come during the time of receiving and transmitting data from Bluetooth? And the next question is what serial communication we can use for this type of project? – BUBAI NAYAK Nov 12 '18 at 10:09
3

You connected the LCD module to serial hardware pins 0 (RX) and 1 (TX).

When you receive the data from the Bluetooth module, through the software serial, you send it to the hardware serial.

if(BTSerial.available()){
      recvChar = BTSerial.read();
      Serial.print(recvChar);
...

This messes up the communication with the LCD module. Remove Serial.print(recvChar); and it should work.


A more sensible solution would be to use hardware serial for the Bluetooth module and the other pins for the LCD module.

Software serial should only be used, if you really can't use the hardware serial, e.g. you need the hardware serial to communicate with another device (a PC or some other module).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.