HC12 not working

1. Build the following connection diagram (Fig-1) between HC12 and UNO for both Sender (UNO-1) and Receiver (UNO-2). ( The diagram is taken from a working experiment).


Figure-1:

2. Upload the following sketch in UNO-1 (Sender).

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX = DPin-10, STX = DPin-11

void setup() 
{
  Serial.begin(9600);
  SUART.begin(9600);  //activate Software Serial Port (SUART)
}

void loop() 
{
  byte y = Serial.available();//check if a charcater has come from Serial Monitor
  if(y != 0)  //a charcater has arrived
  {
    char x = Serial.read(); //read the charcater
    SUART.print(x); //send the charcater to NANO-2
  }
}

3. Upload the following sketch in UNO-2 (Receiver)

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);  //SRX = DPin-10, STX = DPin-11

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);  //activate Software Serial Port (SUART)
  pinMode(13, OUTPUT); //DPin-13 works as output line
  digitalWrite(13, LOW);  //built-in Led-L is OFF
}

void loop()
{
  byte y = SUART.available();//check if a charcater has come from NANO-1 via SUART Port
  if (y != 0) //a charcater has arrived
  {
    char x = SUART.read(); //read the charcater
    if (x == 'L')
    {
      digitalWrite(13, HIGH); //L has arrived; turn ON Led-L
    }
    if (x == 'R')
    {
      digitalWrite(13, LOW); //R has arrived; turn OFF Led-L
    }
  }
}

4. Open Serial Monitor at UNO-1 with "No line ending" option for "Line ending tab" (Fig-2).


Figure-2:

5. Enter L in the inputBox of the Serial Monitor and then click on the Send Button.
6. Check that the built-in Led-L of UNO-2 (Receiver) has turned ON.
7. Enter R in the inputBox of the Serial Monitor and then click on the Send Button.
8. Check that the built-in Led-L of UNO-2 (Receiver) has turned OFF.
9. If Step-5 to 8 work, then add codes with Sender/Receiver sketches to control Led-L of UNO-1 from UNO-2.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.