Controlling multiple servo motors with an IR reciever

Hello everyone!

I am building a maze with sliding doors for mice (behavior tests). We are having the doors slide open and close by a rack and a gear, and the gear is attached to a servo motor.

I am trying to figure out how to control multiple servo motors with an R3 and a receiver (with a bread board too to connect all of the servo motors). There are going to bars that act as sensors that will sense when the mouse passes a certain point to open the door. So the conditon would be the bar is not broken (0) or broken (1), and when it's broken, the door opens.

We will have 6 doors in different places within the maze, so 6 servo motors.

I know the code to get the servo motor to spin back and forth. But how do I get it to where whenever the output of the reciever is 1 (whenever the bar is broken) that it runs the loop code for the gear to spin the door open for a particular servo? Like, open the door for servo 3, or open the door for servo 5 and so on...

I appreciate any help!

Hint: You can easily choose between dozens TV programs with a singly remote using the individual codes for each channel....

Servo MOTORS, or SERVOS?

servo motors

ok, that’s a start, because you want to reverse them (open & close), you’ll need hi-bridges or relay switching to control the drive and direction.

You’ll probably need limit switches and/or encoders to determine the motor position at any given time.

P.S. I don’t think you really want to use servo motors, but I’ll let you figure that out.

Not common servos, which go to a point between 0 and 180 degrees, typically, following the width of a control signal, a positive pulse between 1 and 2 milliseconds coming along every 20 milliseconds.

In the Arduino, use the servo library, see examples in the IDE.

If it is a rack and pinion, you can use continuous rotation servo, or modify a standard servo, still controlled by a pulse at a width issues regularly, the same signal as a normal servo.

A regular servo could raise and lower a door directly as it swept through its range.

@tomatocave16 how does the mouse sensor bar connect to the Arduino, how does it sense a mouse?

a7

@alto777
That’s why I asked if OP meant servo motors OR servos (aka R/C servos).

A servo motor is often just a DC motor, while an RC Servo contains a motor AND feedback / control circuitry - hence it’s called a ‘servo’… a closed loop control system.

I see, a distinction with a difference.

A regular r/c servo with 180 degree range could just be enough to run a door up and down on a rack if a large-ish gear was mounted on the servo shaft. If doing it like raising a gate at a railroad crossing directly won't do.

A big gear would reduce the leverage but maybe little mouse doors don't present that much load.

@tomatocave, could you describe your doors and mechanical system?

The logic seems straight head while we focus on the door… use state change detection to react when a mouse sensor has gone from not seeing (or whatever) to seeing a mouse, and do another thing when the mouse leaves the sensor. And you'd have knowledge of the state, whether a mouse is in the sense area or not.

Using a servo r/c type puts quite a bit of "solution" into the mechanics that, as mentioned, you'd otherwise do sorta by hand - like limit switches, and avoids more external electronics for power switching and reversing.

@tomatocave16 it seems like there might be a time requirement. Open the door when sense a mouse, close it some time later. Maybe just a plain story about how it is supposed to work, code might write itself from a good description.

Also I dare hope these doors can't damage the mice. :expressionless:

a7

So a mouse walks into a bar, and says--

OK, I assume the "bars" are light beams. If there's any doubt about how high or low the voltage would be on the sensor's output, you could send each one into an A/D input to the chip. And when a "blocked" condition is sensed, you open the door and start a timer, which could easily be a count triggered by the 1msec interrupt. After a certain number of msecs elapses, close the door again. This all seems pretty easy.

Hello tomatocave16

Show a picture.

Yes, that is correct.
And there are 6 doors in different places in the maze. What am figuring out is : so the code will be controlling 6 servo motors. Do I need to define a variable for each servo motor so that the loop code will know which servo motor to activate?

Hello tomatocave16

Keep it simple and stupid.
Run some tutorials to the hardware selected.
If you are happy with the results of the tutorials you can merge these to the project by using control structures.

Have a nice day and enjoy coding in C++.

So is that a "no" or...?

Wait nevermind

Can you please post link to spec/data and pics of how you have them connected to the sliding door.

How are you driving the "servo motors", a link to driver specs/data would also help.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

If you literally mean using the interrupt capability of the microprocessor, that is totally unnecessary and would be best left off the table, at least what I think @tomatocave16 has on the table so far.

Each servo needs its own timer, certainly if mice are fast or numerous enough that there might be more than one door up at a given moment.

Straight-ahead coding with millis() for timing, using idiomatic patterns will do.

See "blink without delay" for a start at how that is done.

If you do have N of anything, it might be a good idea to use array variables so one function could handle all the servos one at a time real fast, and another function could handle all the light beams or whatever, really fast.

Slightly more advanced, yet still dark ages coding would use a struct to hold all the relevant data for a servo, then an array of those would be the relevant data for all servos.

Same same the light beams.

And yes, we all want to see the mechanical concept. I think you really are talking about r/c servos, which after all are "servo motors":

A servomotor (or servo motor ) is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration.


except way cheaper and not so utterly controllable beyond holding a desired position, close enough to ~~fly around the park~~ raie and lower a teeny mouse door.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.