HC-12 communication

Discussion in 'Wireless & RF Design' started by Dabu WhiteHacker, Sep 21, 2018.

  1. Dabu WhiteHacker

    Thread Starter Member

    Sep 5, 2017
    50
    0
    i just bought two new HC-12. I was trying to send potentiometer value to other arduino using this transmitter. but it only shows crap data(strange characters) on the other side.
    Here is the code:
    Transmitter:
    /* Arduino Long Range Wireless Communication using HC-12
    Example 01
    by Dejan Nedelkovski, www.HowToMechatronics.com
    */
    int pot = 0;
    int pot_value=0;
    #include <SoftwareSerial.h>
    SoftwareSerial HC12(12, 11); // HC-12 TX Pin, HC-12 RX Pin
    void setup() {
    pinMode(pot,INPUT);
    Serial.begin(9600); // Serial port to computer
    HC12.begin(9600); // Serial port to HC12
    }
    void loop() {
    pot_value=analogRead(pot);
    while (1) { // If Serial monitor has data
    HC12.write(pot_value);
    }
    }
    Receiver:
    /* Arduino Long Range Wireless Communication using HC-12
    Example 01
    by Dejan Nedelkovski, www.HowToMechatronics.com
    */
    #include <SoftwareSerial.h>
    SoftwareSerial HC12(10, 9); // HC-12 TX Pin, HC-12 RX Pin
    void setup() {
    Serial.begin(9600); // Serial port to computer
    HC12.begin(9600); // Serial port to HC12
    }
    void loop() {
    while (HC12.available()) { // If HC-12 has data
    Serial.write(HC12.read()); // Add each byte to ReadBuffer string variable
    }
    }
     
  2. Dabu WhiteHacker

    Thread Starter Member

    Sep 5, 2017
    50
    0
    i am just receiving question marks
     
  3. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,571
    1,833
    Do you have the HC-12s at least a couple of metres apart?
    You might need to put a delay in the transmit routine while loop.
     
  4. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,571
    1,833
    Instead of sending the pot value, for now just send a single letter and see if that arrives safely.
     
  5. Dabu WhiteHacker

    Thread Starter Member

    Sep 5, 2017
    50
    0
    thanks but i solved it
    problem was i was uploading code to one of the arduino pro mini and in board selection i had selected 5v 16 MHz but it was 3.3v 8Mhz
     
  6. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,571
    1,833
    Yeah, that would do it!
     
Loading...