I'm trying to communicate between 2 arduinos using HC-12 modules.

Discussion in 'Embedded Systems and Microcontrollers' started by ofir, Mar 18, 2018.

  1. ofir

    Thread Starter New Member

    Feb 20, 2018
    1
    0
    hello,
    im trying to communicate between 2 arduinos using HC-12 modules.
    i connected them well like the picture above with the diode and the capacitor, where my arduino is my power supply.
    upload_2018-3-19_0-0-37.png

    i have a simple code for message transmit and recieve. same code for both arduinos.
    messages wont send.
    this is the code:

    Code (C):
    1. #include <SoftwareSerial.h>
    2.  
    3. SoftwareSerial mySerial(2, 3); //RX, TX
    4.  
    5. void setup() {
    6.   Serial.begin(9600);
    7.   mySerial.begin(9600);
    8. }
    9.  
    10. void loop() {
    11.   if(Serial.available() > 0){//Read from serial monitor and send over HC-12
    12.     String input = Serial.readString();
    13.     mySerial.println(input);
    14.   }
    15.  
    16.   if(mySerial.available() > 1){//Read from HC-12 and send to serial monitor
    17.     String input = mySerial.readString();
    18.     Serial.println(input);
    19.   }
    20.   delay(20);
    21. }
    any suggestions what im doing wrong?


    Mod's note:
    Please don't hijack other member's thread.
    This thread was split from HC-12 Nothing showing up in Serial monitor.
     
    Last edited by a moderator: Mar 19, 2018
  2. FlyingCow

    Member

    Dec 30, 2017
    72
    9
    @ofir,
    What is your input method for the data you want to send? If you have the arduino board connected to your computer via USB and using the IDE to tell the HC-12 what you want it to send, there will be problems as they will share the serial bus. I am using a simplified explanation for this but never-the-less, it won't work if you have it connected that way. I used a pair of unos with the chip removed and that worked very well while connected to my computer and typing into the serial monitor in the IDE.
    CLARIFICATION: Actually, they won't share the serial bus, which is the problem, they will compete for it and nothing will get through. Someone else may come on here and explain it better, but you get the idea. Another method is to use an FTDI connector.
     
    Last edited: Mar 18, 2018
  3. FlyingCow

    Member

    Dec 30, 2017
    72
    9
    @ofir,
    Did I answer your question? I sometimes miss the point so I like to ask so you can redirect me if need be. Let me know if the above information helps.

    Mitch
     
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,632
    735
    Ok.
    From the top.
    Your picture shows that you use pins 4 and 5.
    Your code shows that you use pins 2 and 3.
    I am done.
     
Loading...