Arduino outputting extremely low voltage I/O

So I'm building a simple circuit with a NMOSFET and an LED as a load. The whole purpose of this circuit is that the mosfet regulates the current going into the LED, cutting off and opening up the power to the LED over and over again. After 36 hours of debugging, I have come to a conclusion that the arduino isn't outputting 0 - 5V on the pin but instead it's outputting 0 - .02 V is what my DMM is reading. As you guys know, MOSFETS require a good amount of voltage to change it's logic level. I have checked my wiring, tried different ports, tried multiple boards (Uno, Mega, and Nano) and all of them are outputting the same voltage, and I also doublechecked to make sure I set the pin mode to output.

Here's my wiring diagram:

And here's my code (Please ignore the getVoltage() function as its a work in progress):

int regulator = 2;
int iSensor = A1;
int vSensor = A0;

void setup() {
  pinMode(regulator, OUTPUT);
  pinMode(iSensor, INPUT);
  pinMode(vSensor, INPUT);
  Serial.begin(9600);
  digitalWrite(LOW, regulator);
}

void loop() {
  Serial.print("Current: ");
  Serial.println(getCurrent());
  Serial.print("Voltage: ");
  Serial.println(getVoltage());
  delay(250);
}

float getVoltage(){
  float voltageInitial = analogRead(vSensor)/204.8;
  float voltageFinal = (voltageInitial/.2);
  return voltageFinal;
}

float getCurrent(){
  float finalCurrent = 0.0, iValue = 0.0, adc = 0.0;
  int zeroValue;
  digitalWrite(regulator, HIGH);
  zeroValue = analogRead(iSensor);
  digitalWrite(regulator, LOW);
  iValue = analogRead(iSensor);
  iValue = zeroValue - iValue;
  Serial.println(zeroValue);
  adc = adc + iValue;
  adc = adc/100;
  finalCurrent = adc * 0.0732;
  return finalCurrent;
}

You're writing it HIGH for about 100us?

image

There needs to be a GND connection between the Arduino and the driver transistor.

1 Like

I tried with just writing High and Low to the pin with a 1 sec delay. Still the same thing. I also read the pin directly with the multimeter while it was set to high continously.

:face_with_open_eyes_and_hand_over_mouth:

Of course you need the delay in the right place, or you need two delays (on for high and one for low) but continuous high should work.

Is your multimeter directly-connected between the I/O pin and Arduino's ground?

Does this happen when you disconnect everything except the multimeter?

Does the Blink Example work? If so, what happens when you connect your LED driver circuit to Pin 13 (same pin as the built-in blinking LED)?

It's possible that your Arduino is fried or it's possible that you've still got mistakes in your code, or maybe your attached circuit is wrong and "shorting" the output-pin.

Its active low and actually thank you @LarryD that was my problem. Didn't realize there needed to be a ground connection between arduino and mosfet as the arduino was already grounded!

You might want to remove the concept of "ground" from your mind. Replace it with "common".
Every circuit has a common and the common for circuit 1 need not be the common for circuit 2 unless they are connected.

Consider the common of a circuit as a float in the water. You could easily push something off the float into the water. However if that object was on a different float you could not push it off the other float, the float would just move away.
Then you connect the two floats together, now you can push the other object off the other float.

The connection between the two floats is the connection you were missing in your original circuit.

I hope this helps you with the concept.

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.

It will help you get the best out of the forum in the future.

Your diagram shows no power connections to the Arduino.

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