Moving servos based on sensor input

Hi everyone,

I am a newcomer in the field of robotics/automation. I have a few simple projects I would like to realise which may very well lead to more complex and fun challenges. To begin with I thought I would create an automatic railroad crossing where a couple of servos would lower the gates when the train approaches. I’m guessing some sort of a IR sensor with a reflector could detect the train.

Specifically, I’m thinking about the USB servo controller (Micro Maestro 6-channel USB Servo Controller (Assembled))combined with the IR transceiver qtr-1a. Could you please let me know if this is sufficient to realise what I want, or point me in the direction of what would make the job easier(either with this or other systems). It should preferably be possible to have this interoperate with more complex systems at a later stage.

Looking forward to your helpful replies,
Frank Olaf Sem-Jacobsen

Hello,

Yes, the QTR-1A should work fine with the Micro Maestro. The first thing you should work out is what you are going to use to power everything - do you have 5-7V available somewhere in your setup already? Make sure you can get that to the Maestro and the servos, wire the Maestro for self power according to the documentation, and then connect the QTR as follows:

Vin -> +5V
Gnd -> Gnd
Out -> some servo channel, configured as an input

The 5V regulator should be able to provide enough current to drive a QTR-1A, but if you need several sensors, you should look for a higher-current regulated 5V source so that you can avoid putting more than 5V on the Maestro’s inputs.

You can use the Maestro Control Center to play around with the setup, see how close your sensor needs to be to detect the train (it will have to be quite close - about 0.25"), and so on, then write a little script to put it all together. If you need help with any of that, you can post again here!

-Paul

The short range of the QTR-1A sensor might make it hard to get it working well in your system. If that’s the case, you could consider the 10cm Sharp digital distance sensor.

- Ben

I was thinking that it could work if the QTR-1A was located in the center of the track looking up at the underside of the train, or next to a rail looking sideways at the wheels. Either way, you will definitely have to experiment to get it right. The distance sensor that Ben mentioned would make this much, much easier, and it uses less current!

-Paul

Thanks!

So I guess that this distance sensor could be connected to an analog input of the servo controller, and then the script could simply detect whether the input/output is low/high?

I have an additional question about scripting language. Does it support variables in some manner other than the stack? For a typical state machine implementation it is necessary to know what the current state is, e.g. whether the gates are open or closed, or opening or closing. I think the scripting language can support this for simple systems, but for more complex systems is it possible to perhaps write something in C or similar?

Thanks,
Frank Olaf

Hello,

The scripting language is designed for really simple programs and sequences, and it does not have any storage outside of the stack. What I would probably do for you application is to have different sections of the code for different states, and jump around with GOTO commands as needed. If you want to do something more advanced using C, the Baby Orangutan is quite capable of reading a few sensors and controlling a few servos, but it is not nearly as user-friendly and does not have its own USB port.

-Paul

If you end up wanting to do something more complex later, you can always add a C-programmable microcontroller to your project and use it to send serial commands to the Micro Maestro, which would save you from having to generate the servo control singles with the MCU itself.

Also, we just started selling 5cm Sharp digital distance sensors, which might be even better for your application than the QTR-1A and 10cm Sharp digital distance sensor (depending on the size of your train).

- Ben

Frank,

How interesting you mention the exact project I’m working on for a friend. However, I’m going about it from a different angle. My project is based on an Arduino board and IR emitter/sensors.

The idea is to use 5 detection zones: 2 outer approach zones; 2 inner zones; and a zone at the grade crossing itself. The plan is to have the crossing lights (and maybe a bell, too) start when an approach zone is tripped. The gates would drop when the matching inner zone trips. The crossing zone should then trip. If the train does not change direction then the zones clear in the same order. To match prototype, the gates would raise once the crossing zone is clear and the lights and bell would stop once the gates are fully raised.

What I like about using the Arduino is the ability to set and change all sorts of variables such as:
Flashing rate of the lights
Soft on/off rate of the LEDs so they look like incandescent lamps
Gate speed
Gate positions
Bell rate

I’m working on the sketch for the Arduino but progress has been slow. Outdated Basic skills don’t translate well to C+ so learning the syntax has been somewhat of a struggle. I know what I want it to do but the specifics of the language has a learning curve.

Mike