Keypad controlled servo

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

#define Password_Length 4;


static const int spy = 0;
static const int analyst = 0;
static const int director = 0;

int sensor = 11;              
int sensorState = LOW; 
Servo myservo;
int servoPin = 10;
int position = 0;

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

char hexaKeys[ROWS][COLS] = {  //define the symbols on the buttons of the keypads

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'*','0','#','D'}

};

byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad

byte value = 0;  // Will not go above 255 using byte identifier - use int for higher

char customKey = 0;

                   
void setup() {
  myservo.attach(10);
  pinMode(sensor, INPUT);     
  Serial.begin(9600);
} 


void loop(){
  sensorState = digitalRead(sensor);
  while (digitalRead(sensor)==HIGH){ 
  Serial.println("welcome");
  delay(10);
  }
  while(digitalRead(sensor)==LOW){
  Serial.println("");
  }
  
  
  customKey = customKeypad.getKey(); 
    
  if (customKey != NO_KEY) {
    if ((customKey >= '0') && (customKey<='9')) {  
      value = value*10;  
      value = value + customKey - '0'; 
    }
   
    if(customKey =='#') {
      Serial.println(value);
      value = 0;
    }
   }
 }

My servo doesn’t respond to this program.

“My servo doesn’t respond to this program.”

Where do you generate a servo command and then send the command to the servo?

Something like 'myservo.write(value)' added in the right place might help.

Steve

Some basic servo test code that has some essentials that you can use to test your servo.

// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
}

void loop() {

  while (Serial.available()) {

    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
      delay(3);
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);
    int n = readString.toInt();
    Serial.println(n);
    myservo.writeMicroseconds(n);
    //myservo.write(n);
    readString="";
  } 
}