Confused about servo

I am developing a smart lock which can be controlled remotely via web. I am using the servo to direct the lock to rotate . This works well till I am using the application to direct my lock but how will I be notified if someone else opens the lock.,…In other words how can I use the spark core to send values from the servo as soon as it deviates from a specific angle…??

Hi @diljit

If your servo is mechanically linked to your lock with no possible slippage, then any time the servo is powered and commanded to specific position, it will resist being moved from that spot. You can power down the servo and then most can be turned by hand or create a better mechanical system with a clutch or other mechanism to avoid this.

To detect the servo position you could use a special servo like this one:

which brings out a voltage that is proportional the position of the servo. Or you could use other sensors to detect the state of the lock (which might be better from a fail-safe perspective).

@bko Thats a good fix.How about using the servo as an analogRead? By anyway can I publish a event to my web app as soon as the servo moves from a specified position?

You can only use analogRead() with that special type of servo–it won’t work on a regular servo. You will still be “fighting” the servo to move it by hand if it is powered.

Sure, you can use Spark.publish() to send out an event when your servo moves.

@bko That Helps…You are doing a great favour in this forum…

1 Like

Interesting project @diljit is the servo you use a dedicated lock controller or a standard servo commonly used in RC contolled toys?
If you use a standard servo than the following ‘solution’ might work…
The servo output on microcontrollers like the spark and others are a one way pulse width modulated signal.
Standard analog servo’s utilize a potentiometer to determine the servo position. This pot is internal and only accessible when you open the case and put the slider contact to an AD converter. This method is far from ideal, the signal on the slider is most likely a voltage that hopefully fits in to the range of the spark’s analog input.
This approach has many options for failure, but if you are a handyman, and we all are, are we not :wink: it is doable.
The algorithm to control the lock look something like this:

#define OPEN 1
#define CLOSE 0
void Setlock(boolean pos){
     if (pos == OPEN){
       analogWrite(SERVO_PIN,255);
    }else{
       analogWrite(SERVO_PIN,0);
   }
 }
boolean readLock(){
  if (analogRead(READ_SERVO_PIN)>128)
    return OPEN;
  else
    return CLOSED;
} 

Enjoy,
@marcus

@marcus We are using the standard servos.will they work if just use an analogRead ?

Hi @diljit

@marcus is pointing out that might be able to modify a standard servo to be like the one I linked to above.

So you can buy a servo with the extra connection for the position potentiometer or you can modify a standard servo the bring that wire out.