Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // BT VCC to Arduino 5V out.
  2. // BT GND to GND
  3. // BT RX to Arduino pin 3 (through a voltage divider)
  4. // BT TX to Arduino pin 2 (no need voltage divider)
  5.  
  6. #include <SoftwareSerial.h>
  7. SoftwareSerial BTserial(2, 3); // RX | TX
  8. // Connect the HC-05 TX to Arduino pin 2 RX.
  9. // Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
  10.  
  11. char c = ' ';
  12.  
  13. void setup()
  14. {
  15. // start th serial communication with the host computer
  16. Serial.begin(9600);
  17. Serial.println("Arduino with HC-05 is ready");
  18.  
  19. // start communication with the HC-05 using 38400
  20. BTserial.begin(38400);
  21. Serial.println("BTserial started at 38400");
  22. }
  23.  
  24. void loop()
  25. {
  26.  
  27. // Keep reading from HC-05 and send to Arduino Serial Monitor
  28. if (BTserial.available())
  29. {
  30. c = BTserial.read();
  31. Serial.write(c);
  32. }
  33.  
  34. // Keep reading from Arduino Serial Monitor and send to HC-05
  35. if (Serial.available())
  36. {
  37. c = Serial.read();
  38.  
  39. // mirror the commands back to the serial monitor
  40. // makes it easy to follow the commands
  41. Serial.write(c);
  42. BTserial.write(c);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement