سلام دوستان
من دو تا برد آردینو نانو دارم و یکی رو میخوام به عنوان گیرنده و دیگری رو به عنوان فرستنده استفاده کنم.
دو تا هم ماژول HM_R ,HM-T سریال 433 MHZ دارم که به آردینو ها وصل هستن.
کدهای فرستنده این هست:
کدهای گیرنده هم اینا هستن:کد:// include the library code: #include <LiquidCrystal.h> #include <SoftwareSerial.h> SoftwareSerial mySerial(10,11); // RX, TX // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 6, 5, 4, 3, 2); int ledPin = 13; int i=0; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); Serial.begin(9600); pinMode(ledPin, OUTPUT); // Print a message to the LCD. } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 0); lcd.print("Hi User"); delay(2000); lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print("Loading"); delay(1000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Sender Board"); delay(1000); lcd.setCursor(0, 1); lcd.print("Scorpine.HJ"); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("sucsess!"); delay(2000); lcd.setCursor(0, 1); lcd.print("Start"); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Send"); delay(200); while(1){ i++; Serial.println(i); // send a byte with the value 45 delay(1000); // int bytesSent = Serial.write("hello"); //send the string “hello†and return the length of the string. digitalWrite(ledPin, HIGH); // sets the LED on delay(10); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(10); } }
الان روی فرستنده چراغ tx در هنگام ارسال سریال روشن میشه .کد:#include <SoftwareSerial.h> SoftwareSerial mySerial(10, 11); // RX, TX int ledPin = 13; char incomingByte = 0; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() // اجرای پی در پی { incomingByte = Serial.read(); if(incomingByte<=9){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); } }
روی گیرنده هم چراغ rx *روشن میشه وقتی سیگنال میگیره.
پین های مورد استفاده هم txd , rxd هستن.


1 لایک
LinkBack URL
About LinkBacks



پاسخ با نقل قول
