0

I am trying to make a group of LED dim with PWM to a MOSFET. The code seems to work for this, but the trouble is that the IR receiver will only receive the signal to turn on the lights and then IR receivers onboard LED goes to a permanent dim state (which is suppose to be off completely). It then refuses to take input until a Arduino reset is preformed. I purchased another IR receiver and placed it in the same configuration and it work exactly as intended I could brighten the LEDS and I saw the PWM stretch on my oscilloscope with every click of my remote. The trouble is that the receiver quickly quit working at this point I think there is a problem with my circuit. I am attaching the circuit diagram in hopes that someone can help.

Thanks, Billa

#include <IRremote.h>

int led = 9;           
int led2 = 10;
int brightness = 0;    // how bright the LED is
const int RECV_PIN = 7; //IR Receiver Pin
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();

}

void loop() {

  analogWrite(led, brightness);
  analogWrite(led2, brightness);


  if(irrecv.decode(&results)) //this checks to see if a code has been received
{
    if(results.value == 0xFF906F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered U");
        brightness = brightness + 5;
    }

    if(results.value == 0xFFE01F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered D");
        brightness = brightness + 5;
    }

    irrecv.resume(); //receive the next value
}



  delay(100);
}

enter image description here

11
  • 1
    What is the receiver?
    – Majenko
    Jul 24, 2019 at 23:27
  • 4
    that sure is an ugly schematic
    – jsotola
    Jul 25, 2019 at 2:14
  • 1
    I don't think, that a resistor between Arduino and MOSFET is really necessary, since a MOSFET normally has only a very small capacitance. But a current limiting resistor for the LEDs would be good
    – chrisl
    Jul 25, 2019 at 6:50
  • 1
    @chrisl It is probably LED strips with built in resistors (since it's powered from 12V). Also the LEDs are backwards, but we'll overlook that ;)
    – Majenko
    Jul 25, 2019 at 8:51
  • 1
    @newbie A resistor is not strictly needed. I add a 100Ω resistor normally just to limit inrush current to the gate when switching, but then I usually use more powerful MCUs with a lower current rating on each pin than an 8-bit AVR.
    – Majenko
    Jul 25, 2019 at 8:52

1 Answer 1

0

The first error I see with the sketch is right under this line of code Serial.println("Triggered D");. You are incrementing the variable brightness when you probably meant to decrement it.

The second error is with your call to analogWrite(). This function accepts an integer between 0 and 255. You do not constrain the value to that range, and can see what I mean by adding this line of code Serial.println(brightness); right above this one irrecv.resume(); in your sketch. Going from 0 to -5 turns the LED from off to maximum brightness. Is this what you want it to do?

The errors with your MOSFET circuit is a "General Electronics" question, and should be asked on electronics.stackexchange.com. As I mentioned in one of my comments to your question, there is a recommended format for drawing schematics.

My other comment was regarding this Q+A at EE. You won't find a consensus on exactly how to use a MOSFET there either, but the image in this answer may be helpful to you.

1
  • 1
    Thank you for your help. I tried the ringing solution with no luck. I'll move my question to over the General Electronics and see. Jul 25, 2019 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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