Serial communication is not established

hi, Where am I making mistakes? It does not work.

#include <SoftSerial.h>
#include <TinyPinChange.h>

SoftSerial mySerial(2, 3);

char data = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(1, OUTPUT);
}

void loop()
{
  if(Serial.available() > 0)
  {
    data = Serial.read();
    Serial.print(data);
    Serial.print("\n");
    if(data == '1')
      digitalWrite(1, HIGH);
    else if(data == '0')
      digitalWrite(1, LOW);
  }                          
 
}

I dont know English. Sorry if translation is faulty.

 if(Serial.available() > 0)

Are you wanting to read from the hardware serial line, Serial, or from the SoftSerial instance, mySerial, that you created?

You appear to be using, and intend to use, a software serial on pins 2,3, but the code in setup and loop addresses "Serial" i.e. hardware serial, rather than "mySerial".

Delta_G:

 if(Serial.available() > 0)

Are you wanting to read from the hardware serial line, Serial, or from the SoftSerial instance, mySerial, that you created?

Nick_Pyner:
You appear to be using, and intend to use, a software serial on pins 2,3, but the code in setup and loop addresses “Serial” i.e. hardware serial, rather than “mySerial”.

thank you

#include <SoftSerial.h>
#include <TinyPinChange.h>

SoftSerial mySerial(2, 3); // RX, TX

char data = 0;
void setup()
{
  mySerial.begin(9600);
  pinMode(1, OUTPUT);
}

void loop()
{
  if(mySerial.available() > 0)
  {
    data = mySerial.read();
    mySerial.print(data);
    mySerial.print("\n");
    if(data == '1')
      digitalWrite(1, HIGH);
    else if(data == '0')
      digitalWrite(1, LOW);
  }                          
 
}

It worked like this. Thanks for your help

      digitalWrite(1, HIGH);
    else if(data == '0')
      digitalWrite(1, LOW);

If you are not using the hardware serial pins for communication with the PC, get the device off of pins 2 and 3, and move the LED off of the hardware serial pin.