(SOLVED) Mosfet gate does not work 100 percent due to code

Hello,

i have tried every combination for a few days but gate voltage does not reach 100% in this code
in the blink example, it reaches maximum voltage

where is the mistake in this code? could you help?

#include <LEDFader.h>
#include <Curve.h>

#define PIRPIN A2
LEDFader led = LEDFader(9);

int ledState = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
const long interval = 10000;  //amount of time the leds will stay up in millis

void setup() {
  pinMode(PIRPIN, INPUT);
}

void loop() {

  currentMillis = millis();

  if (digitalRead(PIRPIN) == 1) {
    previousMillis = currentMillis;
    led.fade(255, 10000);
    ledState = 1;
  }

  if (ledState == 1) {
    if (currentMillis - previousMillis >= interval) {
      led.fade(0, 100000);
      ledState = 0;
    }
  } led.update();
}

Hi,
Missed saying which "arduino" you are using.

1 Like

Hi,
the LED lights up at 100%, but only for a fraction of a second.
See that you tell the LED to light up to a maximum, for 1 second, but when completing 1 second through the "interval" value, which is also 1 sec., you tell the LED to start turning off.

Try changing the interval value to for example 5 seconds and watch its LED.

1 Like

Voltage is related to hardware. Please provide a circuit diagram.

1 Like

Hi,
Have you tried the example code that comes with the library?

If not then try it to prove your hardware.

Some Serial.print statements would help to monitor your variables.

Thanks.. Tom.. :smiley: :coffee: :+1: :australia:

1 Like

I sure would like to help you but My eyes do not see so well and I do not have a clue as to what the hardware looks like. For all intense purposes it is a hardware problem. So why not help me help you by posting an annotated schematic, not a useless frizzy picture. Also post links to "Technical Information" on the hardware items, links to sales outlets such as azon are normally useless. For example there are over 100,000 different MOSFETs, no clue to what you are using.

1 Like

hello,

i am using arduino uno and IRL540N without any resistors.

Thank you @ruilviana

playing with interval value solved the problem (Y)

if your problem was solved, do a kindness to everyone on the forum, especially to those who helped you.

Write [Solved] before your topic title, so if someone searches and finds your topic, they'll know what the solution looks like.

1 Like

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