I am currently working with 2 arduinos where each of them is connected to a HC-05 module. I configured the HC-05 such that both of them have the baudrate of 9600. I double checked that one is a master and one is a slave. However when I am sending an integer conditionally from the sender and I print out those values on the serial monitor connected to the receiver arduino, it is outputting different values.. why is this?
Sender Code
#include <SoftwareSerial.h>
#define tx 10
#define rx 11
SoftwareSerial BT(tx, rx);
int weather;
//btn//
#define btn1 2
#define btn2 3
#define btn3 4
#define btn4 5
#define btn5 6
void setup() {
pinMode(tx, INPUT);
pinMode(rx, OUTPUT);
pinMode(btn1, INPUT);
pinMode(btn2, INPUT);
pinMode(btn3, INPUT);
pinMode(btn4, INPUT);
pinMode(btn5, INPUT);
delay(40);
Serial.begin(9600);
BT.begin(9600);
}
void loop() {
BT.listen();
if (digitalRead(btn1) == HIGH) {
int weather = 500;
BT.write(weather);
Serial.println("btn1 pressed");
delay(50);
}
if (digitalRead(btn2) == HIGH) {
int weather = 600;
BT.write(weather);
Serial.println("btn2 pressed");
delay(100);
}
if (digitalRead(btn3) == HIGH) {
int weather = 700;
BT.write(weather);
Serial.println("btn3 pressed");
delay(100);
}
if (digitalRead(btn4) == HIGH) {
int weather = 800;
BT.write(weather);
Serial.println("btn4 pressed");
delay(100);
}
if (digitalRead(btn5) == HIGH) {
int weather = 900;
BT.write(weather);
Serial.println("btn5 pressed");
delay(100);
}
}
receiver code
#include <SoftwareSerial.h>
#include <FastLED.h>
#define tx 10
#define rx 11
SoftwareSerial BT(tx, rx); // tx rx of bt
int c ;
void setup()
{
pinMode(tx, INPUT);
pinMode(rx, OUTPUT);
delay(40);
Serial.begin(9600);
BT.begin(9600);
}
void loop()
{
BT.listen();
c = BT.read();
Serial.println(c);
delay(50);
}
as seen in the code, im supposed to receive integer 500,600,700,800,and 900 respectively. But when I print out the value received from the receiver HC-05, it prints out insted 32, 188, 88, and 244...
I tried changing BT.write()
to BT.println()
and also tried changing datatype from integer to uint8_t
and none of these work.