Wiring Arduino and transistor with ground as switch

12v DC power supply


  • |_________| — 12vdc

12vdc LED

  • |____| -

IR540N
Moffset


| | |
G D S

Arduino


| |
| |


I have the above components. I’m trying to figure out
how to wire them up using a switch wired to the arduino
that will break across ground. So when this switch opens or closes
it sends a signal to the transistor to open or close.
The switch is external to the arduino.

I’ve looked at the various diagrams on arduino and switches
but haven’t found one that talks about using a ground as the
switch when powering an LED with a different power source.

I would like to hook up the arduino to the Moffset and send
a signal to the Moffset to open the current to the LED.
My arduino routine and switch would tell the Moffset when to allow the power
through the Moffset so the LED would light. The arduino routine
would handle the on and off sequence.

Can anyone help?

You may not have used the proper search terms. It can be difficult to find things in the forum. I often give up and just redraw a design while trying to locate a post I know I made.

Thanks very much for the quick response. Yes things are sometimes difficult to find. If I needed to put a switch connected to the arduino, would I follow the diagrams in some of the examples.

Assuming pin 7 is input and pin 13 is output.

Connect 5+ --> | switch | <--------pin 7, then pin7 with a resistor to ground. Would this control the output to say pin 13 (my output to the transistor). Hope this makes sense.

MountainGuy:
Connect 5+ --> | switch | <--------pin 7, then pin7 with a resistor to ground.

You don't have to use an external pull-down resistor: the Arduino has internal pull-up resistors. Just connect your switch between pin 7 and ground, and add the line

pinMode(7, INPUT_PULLUP);

to your setup.

Note: when the button is pressed, digitalRead(7) will return 0, and when the button is not pressed, it will read 1.

Pieter

P.S: It's MOSFET, not Moffset :wink: it stands for Metal Oxide Semiconductor Field Effect Transistor. MOS is just the materials it's made of (Metal for the Gate, then an insulating Oxide, and finally the actual Semiconductor), and FET is the type of transistor (current flow depends on the applied electric field.)

An IRF540n (not IR540n) is not a logic level mosfet.

An Arduino pin can't provide enough drive voltage to turn this mosfet fully on.
Leo..