Hi guy i am using a spark fun n type mosfet hooked up to 12 volt power source suing pwm to switch on and off the gate however the mosfet is not switching completely off simply just dropping the current by a volt. can any one help

circuit maybe?

How about "which n-channel mosfet @ SF"?

N-Channel MOSFET 60V 30A

and i have hooked it just like this

:) and the code....

(and what are you driving?)

driving 100 LED this circuit is repeated 9 times over however. the code is

const int N_LEDS = 2;
int sensorVal[N_LEDS];

//// Set up which sensor controls what led - first in each are associated…
int sensorPin = {1, 5};
int ledPin = {12, 13};

int minDistance = 30; // Your distance from sensor to your ‘MIN led’ value
int maxDistance = 155; // Your distance from sensor to your ‘MAX led’ value

//// Setup average variables

const int amountBy = 2;

int avgThisSensor[amountBy];
int theTotals[N_LEDS];
int eachAvgValue[N_LEDS];


void setup() {

void loop() {

for (int i = 0; i < N_LEDS; i++ ) {

// read the analog input mappoing statement.
int analogValue = analogRead(sensorPin );

  • analogValue = constrain(analogValue, minDistance, maxDistance); // limits range of sensor values to between your two distances *

  • int outputValue = map(analogValue, minDistance, maxDistance, 255, 0);// this staement need to be changer in order re inturpit the new sensor input //*

  • // print the result to the serial monitor*

  • Serial.print("Pin : “);*
    _ Serial.print(sensorPin*);_
    Serial.print(” Value = ");_
    _ analogWrite(ledPin, outputValue);

If you post your code properly, using the # (code) icon on the editor's toolbar, you'll find we'll be able the read it without having to infer subscripts from the presence of italics.

just dropping the current by a volt

That is a good trick, Current is measured in amps and voltage is measured in volts.

You don't appear to have set your pins to outputs in the setup() part of the code.