So I have code written that works perfectly when hooked up via USB cable to my computer but whenever I took up a 9v battery or YwRobot to the Arduino my code doesn't work. I have a HC-12 radio signal that is communicating between the two Arduino's. I've already tried putting a resistor in the RX-TX pins on the board but no luck. I've also test a blink code via power source and that works perfectly fine. So I don't why it wont work with an external power source. Here is my code please help.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
const int SignalPin = 4; // the number of the LED pin
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
pinMode(SignalPin, OUTPUT);
}
void loop() {
if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)
Serial.println(input); // prints out the whatever is being sent to it
if ( input == 1)
{
digitalWrite(SignalPin, HIGH);
}
else if ( input == 2)
{
digitalWrite(SignalPin, LOW);
}
}
mySerial.flush();//clear the serial buffer for unwanted inputs
delay(10);//delay little for better serial communication
}