RF UART code example
//This is the Code of Receiver and Transmitter RF (NANO transmit, UNO Receive) //Arduino NANO transmitter side //----------------------------------------------------------------------// // Pin 13 has an LED connected on most Arduino boards. int led = 13; int num = 0; String comdata = ""; void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); Serial.begin(9600); Serial.println("Hello, I am Arduino"); Serial.println("HI number 1"); } //Serial data transceiver void loop() { delay(1000); Serial.print("HI number "); Serial.println(num++); while (Serial.available() > 0) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) comdata += char(Serial.read()); delay(2); } if (comdata.length() > 0) { Serial.println(comdata); comdata = ""; } digitalWrite(led, LOW); // turn the LED off by making the voltage LOW } _____________________________________________________________________________________________________________ //UNO Receiver Side //----------------------------------------------------------------------// // Pin 13 has an LED connected on most Arduino boards. int led = 13; #include String readString; SoftwareSerial mySerial(10, 11); // RX, TX void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); Serial.begin(9600); //computer PORT mySerial.begin(9600); // RF PORT //Serial.println("Hello, I am Arduino"); } //Serial data transceiver void loop() { while (mySerial.available()) { delay(3); //delay to allow byte to arrive in input buffer char c = mySerial.read(); readString += c; } if (readString.length() > 0) { Serial.println(readString); readString = ""; } //digitalWrite(led, LOW); // turn the LED off by making the voltage LOW }
[adsenseyu6] |