Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Electronic Position Sensor

Status
Not open for further replies.

tom_pay

Member
Hi

I want to build an electronic location sensor for my garage door. I didn't want just an open/closed display, I wanted a 0% to 100% open readout.

I decided I would glue a metal strip with evenly spaced 'teeth' on the sliding door and use a photo interrupter to count the teeth that went by. (see picture)

I have got the counting part sorted out. However the direction of travel has stumped me. How do I know when to add the teeth going by, or deduct them.

Does anyone have any ideas on how to do this?

Thanks

Tom
 

Attachments

  • untitled.JPG
    untitled.JPG
    13.3 KB · Views: 137
Read up on "quadrature encoder". Hint: it takes two patterns; two photo-interrupters.
 
Ok,

Thanks so much, I had no idea where to start!!!

Would this MCU code be acceptable to use?

Code:
:OPEN
if (PIA == 1)
{
    while (PIB == 0)
    {
        if (PIA == 0)
        { 
        goto  CLOSED
        }
}
openness = openness + 1
}

:CLOSED
if (PIB == 1)
{
    while (PIA == 0)
    {
    if (PIB == 0)
        { 
        goto  CLOSED
        }
}
openness = openness - 1
}

PIA - Photo Interrupter A
PIB - Photo Interrupter B


Thanks so much

Tom
 
Last edited:
You need only one interrupt...
Code:
OPEN = 1;
CLOSE = -1;

if ( PIA )          // if a pulse
    {
    if ( PIB )       //  just test the other sensor
        direction = OPEN;
    else
        direction = CLOSE;
    }

openness +=direction;

Cheers Ian
 
Last edited:
hi tom,
If you have already fitted the toothed strip to the door and you have a photo interrupter in place, the easy solution would be to fit a second photo interrupter that is offset from the first one by a half of a tooth spacing
The count and direction would be by detecting which interrupter senses the tooth first.
 
If it's a common garage door opener, doesn't it have a chain driven gear? Why not just mount your photo interrupter beside the gear and rely on the teeth to count pulses?

I'd also put a limit switch at either end to force a "reset" of the count when the door is fully open/closed. Garage door openers aren't exactly built to high tolerances and continuous opening/closing could throw your counts (position) off over time.
 
Hi

Ian, thanks for that code. However the ifs would execute very quickly, and the door may be moving slowly. So the PIB pulse may be coming, but the else would have already taken it. Do you know how would this be rectified?

I have not yet built anything yet, still all theoretical so far.

The limiters are a good idea, I will use them. The door is totally manual.

Thanks Heaps

Tom
 
When I count ring gears on mobile cranes, I use a small pic12f675 as a state machine (quadrature encoder). I run it at 4mhz and just monitor state. I can then output direction and count straight to another pic for processing and display.

If you use an interrupt pin for PIA the interrupt will fire on an edge condition either low to high or visa versa. When the PIA fires the interrupt, PIB will be low in one direction or high in the other So there CAN'T be a situation where both will be read as it will only read when PIA has been triggered (The example shown above doesn't use interrupts)

If you use my quad code you may be able to do all thats needed in the small pic12f675, I have written an LCD controller using a shift register and three pins of the little micro.

Cheers Ian
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top