Keypad 3x4 Analog out

Project tutorial by roger_marin

  • 30 views
  • 0 comments
  • 0 respects

My Daughter's Laptop

Project tutorial by roger_marin

  • 4,702 views
  • 4 comments
  • 23 respects

Tutorial for ILI9341 TFT LCD SD and Arduino MEGA (part 4)

Project tutorial by roger_marin

  • 227 views
  • 0 comments
  • 1 respect

Toolbox 2


Respected projects 2

1D-Pong

Project showcase by flyingangel

  • 2,824 views
  • 4 comments
  • 13 respects

Create Custom Animations on 16x2 LCD Displays

Project tutorial by tusindfryd

  • 8,549 views
  • 24 comments
  • 57 respects

Comments 2

  • Fuction Controls speed on servo 3 months ago

    Full code for a 4 servo robotic arm with a pre-programmed sequence in case you punch 501# on the keypad.

    Using the function (slow) to control the speed of the servos :

    #include <Servo.h>
    #include <Keypad.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x27,16,2);

    Servo servoA; //Hand (open/close)
    Servo servoB; // forward Backward
    Servo servoC; //up down
    Servo servoD; // Rotate (left-right)

    // The kepad
    const byte ROWS = 4;
    const byte COLS = 4;
    char keys[ROWS][COLS] = {

    {'1','2','3','A'}, 
    {'4','5','6','B'}, 
    {'7','8','9','C'},
    {'*','0','#','D'}};
    

    byte rowPins[ROWS] = { 7, 4, 3, 2 };
    byte colPins[COLS] = { 13, 12, 9, 8 };
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    String command;

    char leter ='A'; // (Leter) servo to perform the command
    int angle = 0; // (angle) Initial command
    int s = 10;

    int x_key = A2;

    int y_key = A1;

    int x_pos;
    int y_pos;

    void slow (char leter, int i){

    // For SERVO A
                              if(leter == 'A') {
                                                if (i < 50){ i = 50;}// 50 is the lower limit for the servo 
                                                if (i > 120){ i = 120;} // 120 is the upper limit for the servo 
                                                angle =servoA.read();
                                                if ( i >= angle) {
                                                              for (angle = angle; angle <= i; angle=angle +1)
                                                               {servoA.write(angle);                             
                                                               delay(s);                                                                              
                                                                }
                                                                }
                                                else 
                                                              { for (angle = angle; angle >= i; angle=angle- 1)
                                                               {servoA.write(angle);
                                                               delay(s);                                                                                                                                                     
                                                                }              
                                                                }
    
                                           }
                               //For  SERVO B
                              if(leter == 'B') {
                                                if (i < 10){ i = 10;}// 10 is the lower limit for the servo 
                                                if (i > 110){ i = 110;} // 110 is the upper limit for the servo 
                                                angle =servoA.read();
                                                angle =servoB.read();
                                                if ( i >= angle) {
                                                              for (angle = angle; angle <= i; angle=angle +1)
                                                               {servoB.write(angle);
                                                               delay(s);                                                                              
                                                                }
                                                                }
                                                else 
                                                              { for (angle = angle; angle >= i; angle=angle- 1)
                                                               {servoB.write(angle);
                                                               delay(s);                                                                                                                                                    
                                                                }              
                                                                }                                                                
                                           }
    
                               // For  SERVO C
                              if(leter == 'C') {
                                                if (i < 50){ i = 50;}// 50 is the lower limit for the servo 
                                                if (i > 180){ i = 180;} // 180 is the upper limit for the servo 
                                                angle =servoA.read();
                                                if ( i >= angle) {
                                                              for (angle = angle; angle <= i; angle=angle +1)
                                                               {servoC.write(angle);
                                                               delay(s);
    
                                                                }
                                                                }
                                                else 
                                                              { for (angle = angle; angle >= i; angle=angle- 1)
                                                               {servoC.write(angle);
                                                                delay(s);                                                                                                                                               
                                                                }              
                                                                }
    
                                           }
                               // For  SERVO D
                              if(leter == 'D'){
                                                if (i < 1){ i = 1;}// 1 is the lower limit for the servo 
                                                if (i > 180){ i = 180;} // 180 is the upper limit for the servo 
                                                angle =servoA.read();
                                                if ( i >= angle) {
                                                              for (angle = angle; angle <= i; angle=angle +1)
                                                               {servoD.write(angle);
                                                               delay(s+10);
    
                                                                }
                                                                }
                                                else 
                                                              { for (angle = angle; angle >= i; angle=angle- 1)
                                                               {servoD.write(angle);
                                                                delay(s+10);                                                                                                                                                       
                                                                }                                                                              }
    
                                           }                                               
    
                              }
    

    void setup()
    {

    Serial.begin (9600) ;
    pinMode (x_key, INPUT) ;

    pinMode (y_key, INPUT) ;

    // initialize the lcd

    lcd.init();

    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("Enter command");
    // Pins for the servos
    servoA.attach(5);
    servoB.attach(6);
    servoC.attach(10);
    servoD.attach(11);

    //neutral
    slow('C',120);
    slow('A',80);
    slow('D',90);
    slow('B',30);

    }

    void loop(){

    char key = keypad.getKey();

    if (key){
    lcd.init();
    lcd.setCursor(0,0);
    lcd.print(String("Servo ") + String(leter));
    lcd.setCursor(0,1);
    lcd.print(String("Command ")+String(command + key));

    // * on the keyapd will reset the command
    if(key == '*') {
    command = "";
    lcd.init();
    lcd.setCursor(0,0);
    lcd.print(String("Servo ") + String(leter));
    lcd.setCursor(0,1);
    lcd.print("Command ");
    }
    //# on the keypad will execute the command on the chosen servo defined by (leter)

    else if(key == '#')
    {
    int i = command.toInt(); // capture on (i) the integer of the command (only numbers)

                      if (i==501){
                                        lcd.init();                      // initialize the lcd
                                        lcd.setCursor(0,0);
                                        lcd.print("A to B");
    
                            //Pick up at A
                            slow('D',30);
                            slow('A',120);
                            slow('B',10);
                            slow('C',50);
                            slow('B',60);
                            slow('A',60);
    
                            //move to B
                            slow('C',100);
                            slow('D',100);
                            slow('B',100);
                            slow('A',120);
    
                            //neutral
                            slow('A',80); 
                            slow('B',30);
                            slow('C',120);
                            //slow('D',90);
                                        lcd.init();                      // initialize the lcd
                                        lcd.setCursor(0,0);
                                        lcd.print("B to A");
    
                            //move to B
                            slow('A',120);
                            slow('C',100);
                            //slow('D',100);
                            slow('B',100);
                            slow('A',50);
    
                            //Move A                         
                            slow('C',120);
                            slow('D',30);
                            slow('B',50);                                                  
                            slow('C',50);
                            slow('A',120); 
                            slow('B',20);  
    
                            //neutral
                            slow('C',120);
                            slow('A',80); 
                            slow('D',90);
                            slow('B',30);                           
    
                      }
    
    
                      else {
    
                                        lcd.init();                      // initialize the lcd
                                        lcd.setCursor(0,0);
                                        lcd.print(String("Servo ")  + String(leter)); // show on the LCD the servo that is chosen
                                        lcd.setCursor(0,1);
                                        lcd.print(String("Execute ")+String(command));  // show on the LCD the servo the comand is performing
    
                                        slow( leter ,i);
    
                                        lcd.init(); 
                                        lcd.setCursor(0,0);
                                        lcd.print(String("Servo ")  + String(leter)); //write on the screen the servo chosen
                                        command = "";// empty command 
                              }
                    }      
              // Chosing the servo        
              else if(key == 'A' or key == 'B' or key == 'C' or key == 'D') 
                               {
                                  leter = key;
                                  lcd.init(); 
                                  lcd.setCursor(0,0);
                                  lcd.print(String("Servo ")  + String(leter));//print the name of the servo chosen  
                               if(leter == 'A') {
    
                                                lcd.println(servoA.read());    //print the value from the servo chosen           
                                                }
                               //  SERVO A
                              if(leter == 'B') {
                                                lcd.println(servoB.read());    //print the value from the servo chosen  
                                               }
    
                               //  SERVO C
                              if(leter == 'C') {                                       
                                                lcd.println(servoC.read());   //print the value from the servo chosen
                                                }
                               //  SERVO D
                              if(leter == 'D') {
                                                lcd.println(servoD.read());   //print the value of the servo chosen
                                               }
                                  lcd.setCursor(0,1); 
                                  lcd.print(String("Command  ")+String(command)); //print the value of the command                 
                                  }
    
    
               else {
                command += key; //Add a digit to the command  
    
              }
    

    }}

  • Robotic arm 4 servos 3 months ago

    To avoid problems with the servos I set up an upper and lower limit to each servo, so they don try to go further than fiscally possible

    if (i < 50){ i = 50;}// 50 is the lower limit for the servo
    if (i > 120){ i = 120;} // 120 is the upper limit for the servo

    This is the code for servoA

    // For SERVO A
    if(leter == 'A') {
    if (i < 50){ i = 50;}// 50 is the lower limit for the servo
    if (i > 120){ i = 120;} // 120 is the upper limit for the servo
    angle =servoA.read();
    if ( i >= angle) {
    for (angle = angle; angle <= i; angle=angle +1)
    {servoA.write(angle);

    delay(10);

    }
    }
    else
    { for (angle = angle; angle >= i; angle=angle- 1)
    {servoA.write(angle);
    delay(10);

    }

    }

                                           }
    
Add projectSign up / Login