I am using Arduino Nano as a transmitter and Arduino Mega 2560 as a receiver, each has HC-12 connected. I am trying to send an output from a MPU6050 (connected to the nano) to the LCD (connected to the mega). LCD displays the output but also displays extra characters. Meanwhile, the output in the serial monitor of Mega accurately displayed the output. I can't find any solutions to the problem, an i am hoping someone can help me. Thanks a lot.
The code for nano:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <MPU6050.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
MPU6050 mpu;
float thresholdX = 0.5;
void setup() {
Serial.begin(9600);
HC12.begin(9600);
lcd.begin(20, 4);
lcd.backlight();
mpu.initialize();
}
void loop() {
accelerometer();
delay(1000);
}
void accelerometer() {
int16_t accelX, accelY, accelZ;
mpu.getAcceleration(&accelX, &accelY, &accelZ);
float accelX_g = accelX / 16384.0;
float accelY_g = accelY / 16384.0;
float accelZ_g = accelZ / 16384.0;
if (abs(accelX_g) > thresholdX) {
if (accelX_g > 0) {
HC12.println("water");
} else {
HC12.println("earth");
}
delay(2000);
}
}
and the code for the Mega:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#define BYTELENGTH 10
LiquidCrystal_I2C lcd(0x27, 20, 4);
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
void setup() {
Serial.begin(9600);
HC12.begin(9600);
lcd.begin(20, 4);
lcd.backlight();
}
void loop() {
if (HC12.available()) {
String dataString = HC12.readString();
lcd.setCursor(0, 0);
lcd.print(dataString);
delay(2000);
lcd.clear();
Serial.println(dataString);
}
}
this is the serial monitor in Mega
and this is the lcd