arduino_char_terminator.ino 763 B

123456789101112131415161718192021222324252627
  1. //Connect TX pin of the HC-05 to RX pin of the Arduino
  2. //Connect RX pin of the HC-05 to TX pin of the Arduino
  3. //You can use SoftwareSerial Library, but i dont recommend it for fast and long data transmission
  4. //Otherwise you have to check Serial.available() > excepted number of bytes sent before reading the message
  5. //There's no problem with hardware serial that comes with the arduino. It's perfect
  6. //
  7. void setup()
  8. {
  9. Serial.begin(9600);
  10. }
  11. void loop()
  12. {
  13. if (Serial.available() > 0)
  14. {
  15. Serial.print("You Wrote : ");
  16. Serial.flush();
  17. while (Serial.available() > 0)
  18. {
  19. Serial.write((char)Serial.read());
  20. Serial.flush(); //this is a must for the arduino to wait untill Serial.write is done
  21. }
  22. }
  23. delay(100);
  24. Serial.println("Send here any text");
  25. }