I am working on trying to make a LED strip respond to natural Light levels for a sculpture. I have reached a problem in trying to get the code to work when sending PWM to the light strip. Thank you for any suggestions!

const int analogInPin = A0;  
const int analogOutPin = 9; 

int sensorValue = 0;        
int outputValue = 0;

void setup() {

void loop() {
  sensorValue = analogRead(analogInPin);
  outputValue = map(sensorValue, 0, 1023, 0, 500);
  analogWrite(analogOutPin, outputValue);
  Serial.print("sensor = ");
  Serial.print("\t output = ");

I am using an NTE 2908 N-channel.

NTE 2908 N-channel Mosfet, Arduino Uno

closed as unclear what you're asking by Chris Stratton, jfpoilpret, MatsK, gre_gor, per1234 Feb 24 '18 at 1:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    You have to explain what your problem is. – user31481 Sep 14 '17 at 21:36
  • The LED strip won't respond to the Photocell, I apologize for being unclear haha. – David Sep 14 '17 at 21:38
  • 4
    Narrow it down: Print the values read from the LDR to serial. Is that the problem? Make the LED strip blink: is that the problem? If you can do each individually then the problem is joining it together in code. If one fails by itself then there is something wrong with that bit, obviously. BTW, analogWrite() takes values from 0-255 not 0-500. – Majenko Sep 14 '17 at 21:43
  • 3
    A problem in your code: outputValue = map(sensorValue, 0, 1023, 0, 500); analogWrite(analogOutPin, outputValue); The range for outputValue is from 0 to 500, but analogWrite only takes from 0 to 255. – user31481 Sep 14 '17 at 21:48
  • 1
    I'm voting to close this question as off-topic because it has been abandoned for months without ever stating a specific answerable question. – Chris Stratton Feb 23 '18 at 17:41

You'd better post also the schematic, but I'm pretty sure you just messed up the circuit.

I think you just put the ground connection for the LED strip in the wrong pin (AREF). If you look, the top-most blue wire goes to the third pin from above in the right connector (which is AREF) instead of the fourth one (which is GND). Move this and it should work

Otherwise, put the schematic on the question


How about pinMode (analogOutPin, OUTPUT); ?

  • It isn't needed if you're going to use analogWrite. If you'll look at the first few lines for the source for analogWrite you'll see exactly why that is true (analogWrite sets the pinMode itself.) – Delta_G Sep 26 '17 at 1:24
  • @Delta_G It's safer that way. When you work in multiple platforms you can't depend on details like this. Other platforms may follow other defaults. May be it's an undefined behaviour and will change tomorrow. Omitting pinMode gain you nothing and makes your sketch less clear. – user31481 Sep 26 '17 at 7:06
  • 1
    That still doesn't make it relate in any way to the OP's problem. And I could turn that argument the other way, there's just as likely to be a hypothetical change where pinMode would break an analogWrite. I would think that more likely even since the documentation says you don't need it they wouldn't worry about breaking code that did. Point being, you need to know details about your platform before writing code. Don't assume this might happen or that might happen. Don't assume anything in this game. Assumption is the mother of all screw ups. Always read instead of assuming. – Delta_G Sep 27 '17 at 2:17

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