Advertisement
michalmonday

Serial communication

Feb 15th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial mySerial(9, 8); // RX, TX
  4.  
  5. void setup() {
  6.   // Open serial communications and wait for port to open:
  7.   Serial.begin(9600);
  8.   while (!Serial) {
  9.     ; // wait for serial port to connect. Needed for native USB port only
  10.   }
  11.  
  12.  
  13.   Serial.println("You can communicate between PC and arduino using serial"); // in this tutorial the communication will be used to set the name and pin of the bluetooth module
  14.  
  15.   // set the data rate for the SoftwareSerial port
  16.   mySerial.begin(9600);
  17. }
  18.  
  19. void loop() { // run over and over
  20.   if (mySerial.available()) {
  21.     Serial.write(mySerial.read());
  22.   }
  23.  
  24.   if (Serial.available()) {
  25.     mySerial.write(Serial.read());
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement