Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Simple RF control with Arduino
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Simple RF control with Arduino

by J_Cummings on Tue Feb 04, 2020 9:59 pm

I have configured an arduino uno to use 4 momentary switches to control two servos. I need help with the configuration changes to the sketch and any addition components I may need to replace the switches with the adafruit p/n: 1096 ( simple RF M4 reciever) with p/n: 1095, (4 button RF remote). I am new to arduino and have very little experience with the changes I need to make to make this work. The current configuration has the servos moving when the momentary switches, witch take the associated pins low. The RF module when activated by the remote has 5 volts on the output pins.
Any help with this project will be greatly appreciated.

Thanks again for your time

John

Code: Select all | TOGGLE FULL SIZE
/*
 * Controlling two servos with push buttons. When the left button is press
 * the servo moves left in 10 degree increments. When the right button is
 * press the servo moves right in 10 degree increments.
 */

 #include <Servo.h>

 Servo servo1;  // create servo object servo 1
 Servo servo2;  // creates servo object servo 2

 int angle =90;  // inital angle for servos
 int angleStep =10;  // increment to move servos

 #define S1LEFT 12  // pin 12 connected to servo 1 left button
 #define S1RIGHT 2  // pin 2 connected to servo 1 right button
 #define S2LEFT 8  // pin 8 connected to servo 2 left button
 #define S2RIGHT 4  // pin 4 connected to servo 2 right button
 
void setup() {
  Serial.begin(9600);   // setup serial
  servo1.attach(9);  // attaches servo 1 to pin 9
  servo2.attach(10);  // attaches servo 2 to pin 10

  pinMode(S1LEFT,INPUT_PULLUP); // assigns pin 12 as input for servo 1 left button
  pinMode(S1RIGHT,INPUT_PULLUP);  // assigns pin 2 as input for servo 1 right button

  pinMode(S2LEFT,INPUT_PULLUP);  // assigns pin 8 as input for servo 2 left button
  pinMode(S2RIGHT,INPUT_PULLUP);  // assigns pin 4 as input for servo 2 right button

   servo1.write(angle);  // sends servo 1 to middle at 90 degress
   servo2.write(angle);  // semds servo 2 to middle at 90 degress
   Serial.println("Servo Button Test");

}

void loop() {
  while(digitalRead(S1RIGHT) == LOW){

    if (angle > 0 && angle <= 180) {
      angle = angle - angleStep;
      if(angle < 0){
        angle = 0;
      }else{
        servo1.write(angle);  // move servo 1 to desired angle
        Serial.print("Servo 1 move to: ");
        Serial.print(angle);  // print the angle
        Serial.println(" degree");
      }
    }

  delay(100);  // waits for servo to move to position 
  }// while

  while(digitalRead(S1LEFT) == LOW){

    if (angle >= 0 && angle + angle <= 180) {
      angle = angle + angleStep;
      if(angle >180){
        angle =180;
      }else{
        servo1.write(angle);  // move servo 1 to desired angle
        Serial.print("Servo 1 moved to: ");
        Serial.print(angle);  // print the angle
        Serial.println(" degree");
        }
    }
  delay(100);  // waits for servo to get to desired location 
  }//while

   while(digitalRead(S2RIGHT) == LOW){

    if (angle > 0 && angle <= 180) {
      angle = angle - angleStep;
      if(angle < 0){
        angle = 0;
      }else{
        servo2.write(angle);  // move servo 2 to desired angle
        Serial.print("Servo 2 move to: ");
        Serial.print(angle);  // print the angle
        Serial.println(" degree");
      }
    }

  delay(100);  // waits for servo to move to position 
  }// while

  while(digitalRead(S2LEFT) == LOW){

    if (angle >= 0 && angle + angle <= 180) {
      angle = angle + angleStep;
      if(angle >180){
        angle =180;
      }else{
        servo2.write(angle);  // move servo 2 to desired angle
        Serial.print("Servo 2 moved to: ");
        Serial.print(angle);  // print the angle
        Serial.println(" degree");
        }
    }
  delay(100);  // waits for servo to get to desired location
  }//

 
}
Attachments
Arduino2Servos.jpg
Arduino2Servos.jpg (136.86 KiB) Viewed 46 times
servo2v3.ino.ino
(3.07 KiB) Downloaded 3 times
Last edited by adafruit_support_bill on Wed Feb 05, 2020 6:50 am, edited 2 times in total.
Reason: Added code in-line

J_Cummings
 
Posts: 12
Joined: Sat Mar 10, 2018 5:14 pm

Re: Simple RF control with Arduino

by adafruit_support_bill on Wed Feb 05, 2020 6:51 am

code-wise, the only change will be that the outputs of the M4 RF module will go HIGH instead of LOW when the corresponding button on the remote is pressed.

adafruit_support_bill
 
Posts: 79031
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.