Controlling a relay via PD1 port?

I’m trying to control a fan motor thru a 5VDC SPST relay using PD1. I can see that almost 5VDC is going to the relay when I use the red_led() function with an arg of one, and it turns off just like I want when I use the red_led() function with a zero arg. Is the power going to PD1 not enough to cause a small relay to activate?

If that can’t be made to work, is there a better way to control a fan motor on a 3pi? I need it to run for about five seconds when the bot navigates to a candle. Worst case, I can just hot-wire the fan motor to it’s battery and make it run the entire time but it is cooler to switch the fan motor on and off.

Thanks for any ideas!

Hello.

The microcontroller pin most likely cannot supply enough current to activate your relay. I suggest you use it to control a MOSFET or transistor, which in turn can control your relay (or your motor directly, if the MOSFET is beefy enough).

- Ben

Thanks for the prompt reply, and thanks for bringing out such a cool little robot kit! This will be the 2nd time that I’ve been able to use mine in a competition where line following was just one part of the challenge (but not the whole challenge).

I’m glad to hear that you’re getting such good use out of your 3pi. Good luck with your competition. Please let us know how it turns out (and I’d love to see any video or pictures you might have).

- Ben

Hello,

One thing that occurred to me while reading this is that you would want the ground of the relay connected to the 3pi ground. In general, you should look at the spec for your relay, see how much current it draws to trip, and then look at how much current can be sourced by your microcontroller.

- Ryan

Here is the latest test of my entry in the fire fighting competition, it is weighed down by a fan and a battery so it had to be slowed down quite a bit. At a slower speed it manages to follow the line very well, then I made it drive straight over the “pad” at the end of the line and spin back and forth to blow the candle out. It then spins 180 degrees & returns to the starting point.

Update: My 3pi had the fastest time at our club’s October mini-competiton, finishing in under thirty seconds.

Hello,

Cool video! I looks like your line following code might have room for improvement with careful tuning of the PID constants.

- Ryan

The Pololu supplied linefollowing code has been modified so the robot speeds up in the straight sections then slows down again in the turns, that gives it more of a speed advantage than PID tuning would.