Advertisement
Guest User

ssa

a guest
Jun 25th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. void setup() {
  2. Serial.begin(9600); // Initialize the serial monitor
  3. Serial1.begin(9600); // Initialize Serial1 for HC-12 module
  4. }
  5.  
  6. void loop() {
  7. if (Serial.available()) {
  8. String data = Serial.readString(); // Read a string from the serial monitor
  9. if (data.startsWith("AT")) {
  10. Serial1.print(data); // Send AT command to HC-12 module
  11. }
  12. }
  13.  
  14. if (Serial1.available()) {
  15. String data = Serial1.readString(); // Read a string from HC-12 module
  16. Serial.println(data); // Print received string to the serial monitor
  17. }
  18.  
  19. // Transmit a string every 5 seconds
  20. Serial1.print(69); // Replace this with your desired string
  21. delay(5000);
  22. Serial.println("Sent"); // Print "Sent" in the serial monitor
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement