hello
Through the last question, i decided not to use raspberry pi pico.
instead, i get a arduino promicro board from my friend and used it.
promicro board has one more serial port(Serial1, hardware serial mode),
so my hc-06 is installed on it.
but it didnt work!
simple example on forum is actived when i uploaded it,
but my code completely doesnt work.(no any response)
//-----------------------------------------------------
#include <DHT11.h> //activate dht library
int relay1 = 4; //PTC Heat-6A
int relay2 = 5; //PTC Heat-6A
int relay3 = 6; //LED
int relay4 = 7; //water pump
float temp; //var named 'temp' to save temperarture data from dht11
float humi; //var named 'humi' to save humidity data from dht11
float g_humid; //var named 'g_humid' to save soil humidity data from pin A1
char cmd; //var named 'cmd' to save command from my smartphone through HC-06
DHT11 dht11(A0); //install DHT on pin A0
//---setup---
void setup() {
Serial.begin(9600); //usb serial begin(to use serial monitor on PC)
Serial1.begin(9600); //hc-06 serial begin
pinMode(relay1, OUTPUT); //PTC6A relay switch
pinMode(relay2, OUTPUT); //PTC6A relay switch
pinMode(relay3, OUTPUT); //LED relay switch
pinMode(relay4, OUTPUT); //water pump realy switch
}
//---loop---
void loop() {
int ht_result = dht11.read(humi, temp);
g_humid = analogRead(A1); //save soil humidity data from pin A1
Serial1.print("Humid: ");
Serial1.print(humi);
Serial1.println("% ");
Serial1.print("Temp: ");
Serial1.print(temp);
Serial1.println("C ");
Serial1.print("Soil humid: ");
Serial1.print(g_humid);
Serial1.println("% ");
Serial1.println("");
delay(1000); //send data each 1 sec
//send humid, temp, g_humid through hc-06
if (Serial1.available()) {
cmd = Serial1.read();
Serial.print(cmd);
if (cmd == '1') { //PTC on
digitalWrite(relay1, HIGH); //PTC Active
digitalWrite(relay2, HIGH); //PTC Active
Serial1.print("Heat mode Activated!");
}
if (cmd == '2') { //LED on
digitalWrite(relay3, HIGH);
Serial1.print("LED turned on!");
}
if (cmd == '3') { //Water pump active
digitalWrite(relay4, HIGH);
Serial1.print("Water injection!");
delay(5000); //Water pump active during 5 sec
}
if (cmd == '4') { //PTC off
digitalWrite(relay1, LOW); //PTC Active
digitalWrite(relay2, LOW); //PTC Active
Serial1.print("Heat mode Deactivated!");
}
if (cmd == '5') { //LED off
digitalWrite(relay3, LOW);
Serial1.print("LED turned off!");
}
//PTC Heater, LED, WP Control through hc-06
}
}
EDIT: Ok so are you saying that the sketch in post #3 worked? What did you send and what did you get back? Can you show the serial monitor output please
communication between promicro and serial montor is well (I got the baud rate right)
but the problem that the letters are broken is appeared again.(it appear sometimes.......)
i have to fix it
do you know solution about letter broken?
send: 1 or w, receive: broken letters
(Please refer to the picture)
"Connecting to HC-06..." is from andriod app terminal message.(You don't have to worry about that)
i just tested everything
type "AT" command through ide serial monitor and program called 'hercules'
it prints out "¿¿¿¿¿¿" continuously. (i know that if it works well, output is "OK" and if it doesnt work well, output is nothing)
maybe my hc-06 is defective product.
i don't know exactly what it is, so i think i should ask a new question
starting a new thread with asking on the same project / same problem is seen as crossposting
You are quick with a lot of assumptions and you are short on information.
If you really want help you have to provide much more details.
You wrote that you successfully tested some code
post the working code in a new posting and also poste the output you get from this code in the serial monitor in a code-section too
post the not working code in a second code-section posting and also poste the output you get from the not working code in the serial monitor in a code-section too.
This sentence does not help at all. It is based on assumptions which could be wrong.
The info itself is unprecise
You should start over from a sketch that is only slightly modificated compared to the working sketch
This sketch sends once per second some charactera over bluetooth and prints the exact same characters to the serial monitor to make visible what is really sended
char myCharArray1[] = "Hello";
char myCharArray2[] = " world";
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
unsigned long myTimer;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
myTimer = millis(); // initialise Timer-variable with actual timestamp
}
void loop() {
if ( TimePeriodIsOver(myTimer,1000) ) { // check if more than 1000 milliseocnds of time have passed by
// if 1000 milliseconds time HAVE passed by
Serial1.println(myCharArray1);
Serial.println(myCharArray1);
//Serial1.println(myCharArray2);
//Serial.println(myCharArray2);
}
}