Running a Brushed motor via Simple Rf Receiver

Hey All,

I am a new arduino user and am looking to make my arduino run a brushed motor one way after the simple rf receiver gets a signal from the push button. I currently have a circuit running my motor and a separate circuit for my RF receiver that lights up an LED when the button is pressed. I am looking for help on how to write code so that when I press the button on my key fab it runs the motor for a small period of time so that the motor does one revolution. I would greatly appreciate your help. Thanks for your time and consideration.

I have already created the following code. I will be working on combining both circuits after I get a sense of direction for my code. Again, thanks for the help.

Motor Code:

int motorPin = 22;
pinMode(motorPin, OUTPUT);
int duty_cycle = 1;    //must pick a value between 0 and 255
analogWrite( motorPin, duty_cycle);
delay(1000);

Receiver Code:

//This portion of code will allow a key fab button to be pushed and will result in an LED lighting up. 

//Lets declare some constants that won't change. These will set the pin numbers:
const int buttonPin = 26;
const int rfPin = 28;

//Now lets declare some variables that will change:
int buttonState = 0;


void setup() {
//We can then initialize the LED pin as an output:
pinMode(rfPin, OUTPUT);
//We also want the pushbutton pin as an Input:
pinMode(buttonPin, INPUT);
}

void loop() {
  //Identify the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  
  //Check to see if the pushbutton has been pressed.
  //If the button was pressed, then it is HIGH:
if (buttonState == HIGH) {
  //Now turn LED on:
  digitalWrite(rfPin, HIGH);
}
//If pushbotton was not pressed, then it is LOW.
else {
  //Turn the LED off:
digitalWrite(rfPin, LOW);
}

Surely you just combine the two working bits of code but with 1 definite proviso, which is that you can't guarantee that the motor will move 1 revolution if it is a brushed motor.

Have a look at the Thread planning and implementing a program which shows how to put the different activities in different functions and get them to work together

...R