Hello guys. So I'm working on this project which is a bluetooth controlled car that has a temperature and humidity sensor and the information gathered by the sensor will be displayed on an LCD. My problem is that I can't figure out how to combine the code of the temperature and humidity sensor with LCD to the code of the bluetooth controlled car.
This is the code of temperature and humidty sensor:
#include <DHT.h>;
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int h;
int t;
void setup(){
Serial.begin(9600);
Serial.println("Temperature and Humidity Sensor Test");
dht.begin();
lcd.init();
lcd.backlight();
}
void loop(){
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %, Temp: ");
Serial.print(t);
Serial.println(" ° Celsius");
lcd.setCursor(0, 0);
lcd.println(" Now Temperature ");
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.print(t);
lcd.print("C");
lcd.setCursor(6, 1);
lcd.println("2020 ");
lcd.setCursor(11, 1);
lcd.print("H:");
lcd.print(h);
lcd.print("%");
delay(1000);
}
code of the bluetooth car:
#include <AFMotor.h>
AF_DCMotor motor4(1, MOTOR12_1KHZ);
AF_DCMotor motor3(2, MOTOR12_1KHZ);
AF_DCMotor motor2(3, MOTOR34_1KHZ);
AF_DCMotor motor1(4, MOTOR34_1KHZ);
char command;
void setup() {
Serial.begin(9600);
}
void loop(){
if(Serial.available() > 0){
command = Serial.read();
Stop();
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}