I'm working on a project where I'm using a voltage that is higher than what most microcontrollers can handle. I'm looking for a kind of switch that will connect a power source to an electromagnet and all of this controlled by my microcontroller. I also thought about using a potentiometer to control the speed of two high voltage DC motors via my microcontroller so please tell me if this is a good idea aswell.
Thanks for your time

  • $\begingroup$ What you are describing is called a "transistor". That might help in your search. $\endgroup$ – Shahbaz Jun 26 '16 at 5:20

You can use a relay for the switch. Relays typically have 4 pins: 2 are the switch, and the other 2 control the switch. For reed relays, the switch is a small metal reed (normally closed) that makes contact when an internal electromagnetic coil is powered.

You have to pick the right relay so that your microcontroller can supply sufficient current to controlling pins of the relay. You also need to make sure that the switch of the relay can handle the current flowing from your power source to the electromagnet.

For the motors, consider getting a separate motor control board, which will isolate your microcontroller from the motors and allow you to control their velocity with PWM--you can then use the potentiometer to set the specific PWM duty cycle to control the motors.

  • $\begingroup$ Thank you so much this is exactly what I was looking for! I thought I would have to use a third electromagnet to open and close the switch so this should save me some time. $\endgroup$ – ZakFS Jun 26 '16 at 16:10
  • 1
    $\begingroup$ @ZakFS - I'll add/reiterate Shahbaz's comment that an NPN transistor can assist or do the job entirely. It depends on your application; if you have very high currents then using a relay would be the solution, but you could use a transistor to drive the relay. On an NPN transistor, connect the Emitter to ground, the Base to the I/O pin on the microcontroller, and the Collector to the "low" side of the relay coil. Connect the high side of the relay coil to battery positive. The I/O pin triggers the transistor, which in turn triggers the relay. $\endgroup$ – Chuck Jun 28 '16 at 12:35

You can connect your switch to a comparator, such as the LM339, and wire its output to the microprocessor input pin. It has open collector outputs, so you can pull the outputs up to whatever voltage level your micro can handle.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.