I have made a setup as per following diagram to visualize the problems that you are facing. My comments are given below:


Figure-1: Connection diagram among UNO, HC12-1, NANO, and HC12-2
1. Yes! Both K1 and K2 are to be closed (pressed down) to activate the signals at DPin-12 and DPin-13 of the Receiver (the NANO).
It is due to a mistake in the placement of } in the wrong position; as a result, close condition of K2 demands that some signal should be available from UNO via HC12 Radio. The corrected receiver codes are given below. Compare it with the original codes to spot the wrong position of the }. I have also marked by commented texts.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int Solenoid = 13; // the number of the LED pin
int Spark = 12;
int buttonpin = 7;
//int delaytime = 100;
void setup()
{
mySerial.begin(9600);
pinMode(Solenoid, OUTPUT);
pinMode(Spark, OUTPUT);
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
pinMode(buttonpin, INPUT_PULLUP);
}
void loop()
{
if (mySerial.available() > 0)
{
int input = mySerial.parseInt(); //read serial input and convert to integer (-32,768 to 32,767)
if (input == 1111)
{ //if on code is received
//delay(50);
mySerial.flush();//clear the serial buffer for unwanted inputs
delay(20);//delay little for better serial communication
digitalWrite(Spark, LOW);
//delay(delaytime);
digitalWrite(Solenoid, LOW);
}
else
{
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
}
} //this closing brace should be here
//-----------------------------------------------------
if (digitalRead(buttonpin) == LOW)
{
digitalWrite(Spark, LOW);
//delay(delaytime);
digitalWrite(Solenoid, LOW);
}
else
{
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
}
//} //comment it out
}
2. You keep K2 closed, both signals at DPin-12 and DPin-13 remain active. You release K2, the signals become inactive. This is the program logic that you have included in your program. Is this correct?
3. I have some problem to deal with the parseInt() function. I have gone to atoi() function to extract integer value from the incoming ASCII codes. Now, we can activate signals at DPin-12 and DPin-13 using the local button K2 and the Radio button K1 independently. However, there are serious problems with the bouncing of K1 which prevents to accept that the closed condition of K1 has been relayed to receiver. Therefore, I have limited the receiver codes just to accept only one closure of K1; this nicely activates signals at DPin-12 and DPin-13.
4. The Final Modified (slightly) Codes:
Transmitter Codes:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
int buttonPin = 8;
void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
int buttonState = HIGH;
mySerial.begin(9600);
}
void loop()
{
int buttonState = digitalRead(buttonPin);//read button state
if (buttonState == LOW)
{ //if button is down
mySerial.print(1111);//send unique code to the receiver to turn on. In this case 1111
delay(50);
mySerial.flush();//clear the serial buffer for unwanted inputs
delay(50);//delay little for better serial communication
//mySerial.end();
}
}
Receiver Codes:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int Solenoid = 13; // the number of the LED pin
int Spark = 12;
int buttonpin = 7;
//int delaytime = 100;
int i = 0;
int input;
char dataArray[5];
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
pinMode(Solenoid, OUTPUT);
pinMode(Spark, OUTPUT);
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
pinMode(buttonpin, INPUT_PULLUP);
}
void loop()
{
if (mySerial.available() > 0)
{
{
dataArray[i] = mySerial.read();
i++;
}
if (i == 4)
{
dataArray[4] = 0x00;
input = atoi(dataArray);//mySerial.parseInt(); //read serial input and convert to integer (-32,768 to 32,767)
i=0;
Serial.println(input, DEC);
if (input == 1111)
{ //if on code is received
//delay(50);
Serial.print("OK");
//mySerial.flush();//clear the serial buffer for unwanted inputs
delay(20);//delay little for better serial communication
digitalWrite(Spark, LOW);
//delay(delaytime);
digitalWrite(Solenoid, LOW);
while(1);
}
else
{
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
}
} //this closing brace should be here
}
//-----------------------------------------------------
if (digitalRead(buttonpin) == LOW)
{
digitalWrite(Spark, LOW);
//delay(delaytime);
digitalWrite(Solenoid, LOW);
}
else
{
digitalWrite(Solenoid, HIGH);
digitalWrite(Spark, HIGH);
}
//} //comment it out
}
5. Testing Procedures
(a) Make hardware setup as per Fig-1
(b) Upload codes into UNO (the Transmitter).
(c) Upload codes into NANO (the Receiver).
(d) Bring in the Serial Monitor of NANO.
(e) Press down K2. Check that LED12 and L (built-in LED of NANO) have gone OFF, and they remain OFF as long as K2 remains closed. (This is in the program logic of OP.)
(f) Release K2. Check that LED12 and L have come ON.
(g) Press down K1. Check that LED12 and L have gone OFF.
(h) Reset both UNO and NANO. Repeat the process.