I am creating something like a key finder on my arduino. I plan to push a button turning on the transmitter. The receiver will connect to a second arduino which will have a if x >y statement. When the transmitter is on this statement should turn on a buzzer. I feel as though this code makes logical sense however all the research I've done on RF transmitting with arduinos always are very complex and include the TX and RX slots. I am new to this and only roughly understand their function so would prefer to stay away from them. Can anyone tell me if a normal analog imput will work for just telling an arduino if the transmitter is on? And if so does the rest of the code sound alright?
TRANSMITTER
const int switchPin = 2
const int rftransPin = 8
int switchState = 0
void setup() {
// put your setup code here, to run once:
pinMode(switchPin, INPUT);
pinMode(rftransPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
switchState = digitalRead(SwitchPin);
if (switchState == HIGH) {
digitalWrite(rftransPin, HIGH);
}
else {
digitalWrite(rftransPin, LOW);
Reciver
const int buzzerPin = 2
const int rfrecPin = A1
int rfrecState = 0
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
rfrecValue = analogRead(rfrecPin);
if(rfrecValue > 150)
digitalWrite(buzzerPin, HIGH);
if(rfrecValue < 150)
digitalWrite(buzzerPin, LOW);