Hi All,
A bit of a strange one.
I have an arduino nano (with CH340G, bought on ebay ) running an rgb program controlling rgb led panels through mosfets.
I have had zero issues until today. Today was the first time I ran it for more than a few minutes. It was powered on the whole day with the red colour potentiometer on only, i.e. red leds on. Tonight I turned it off to do some experiments with the placement of the panels, and when I turned it back on, all leds were powered on. The three potentiometers had no effect whatsoever. Brilliant white light, but no control.
So, I connect via USB, re-upload the sketch, and turn it on again. All good, at least for a few minutes. A few restarts later (in the space of a couple minutes) and same problem.
Any ideas? Its not the sketch, because that runs just fine. Power isn't an issue either. I'm using the 5v line from an ATX psu.
Not very certain... you really don't know that yet. Sketches can have different short term and long term behaviour for a variety of reasons. You should probably post it in code tags.
Thanks for your quick reply. Its connected to Vin and Gnd.
int redPin = 9; //Pin for the red RGB led pin
int greenPin = 10; //Pin for the green RGB led pin
int bluePin = 11; //Pin for the blue RGB led pin
int potPin_red = A0; //declare pin for the potentiometer for the red LED
int potPin_green = A1; //declare pin for the potentiometer for the green LED
int potPin_blue = A2; //declare pin for the potentiometer for the blue LED
int readValue_red; //declare variable to store the read value from the potentiometer which controls the red LED
int readValue_green; //declare variable to store the read value from the potentiometer which controls the green LED
int readValue_blue; //declare variable to store the read value from the potentiometer which controls the blue LED
int writeValue_red; //declare variable to send to the red LED
int writeValue_green; //declare variable to send to the green LED
int writeValue_blue; //declare variable to send to the blue LED
void setup() {
pinMode(potPin_red, INPUT); //set potentiometer for red LED as input
pinMode(potPin_green, INPUT); //set potentiometer for green LED as input
pinMode(potPin_blue, INPUT); //set potentiometer for blue LED as input
pinMode(redPin,OUTPUT); //set pin for red LED as output
pinMode(bluePin,OUTPUT); //set pin for green LED as output
pinMode(greenPin, OUTPUT); //set pin for blue LED as output
}
void loop() {
readValue_red = analogRead(potPin_red); //Read voltage from potentiometer to control red LED
readValue_green = analogRead(potPin_green); //Read voltage from potentiometer to control green LED
readValue_blue = analogRead(potPin_blue); //Read voltage from potentiometer to control blue LED
writeValue_red = (255./1023.)*(1023.-readValue_red); //Calculate the value to write on the red LED (add point to change to float point)
writeValue_green = (255./1023.)*(1023.-readValue_green); //Calculate the value to write on the green LED
writeValue_blue = (255./1023.)*(1023-readValue_blue); ///Calculate the value to write on the blue LED
analogWrite(redPin,writeValue_red); //write value to set the brightness of the red LED
analogWrite(greenPin,writeValue_green); //write value to set the brightness of the green LED
analogWrite(bluePin,writeValue_blue); //write alue to set the brightness of the blue LED
Still the same problem. I moved the 5v supply to the +5V pin and uploaded the sketch again. It worked. As soon as I cycled power, all Leds came on full (white). Potentiometers have no effect. Repeatedly cycling power has no effect either.
V-in (raw) is the input of the 5volt regulator.
It needs at least 6volt for the regulator to make a stable 5volt for the board.
If you have a reliable 5volt, then connect it directly to the 5volt pin.
Mighty big chunk of code for a simple thing, and why use floats.
Compressed version attached. Only difference is that the pots now work normally (not reversed).
Leo..
Post a diagram/pictures, and links to the LED panels and mosfets.
How much current do the LEDs draw, and did the mosfets get hot (with ~4volt drive).
You might already have blown the mosfets.
Leo..
Thanks Leo,
I'll give that code a try.
Mosfets are IRL540. They don't even break a sweat. Each panel is diy and draws 0.6A with all colours fully on. Total draw is 1.8A for all three panels.
Mosfets don't even get warm.
I don't get it though. It was working beautifully until I restarted it today a couple of times in quick succession, and it works after I reupload the code. Until a few restarts later, that is.
nealieboyee:
I've run the updated code and it works.....backwards. Pots work the wrong way around.
My code increases brightness with a higher voltage on the pot, your code does the opposite.
That makes YOUR code backwards
Just swap the two outer wires on the pot.
Leo..
Oh I see. No, I didn't write the original code, but I modified it to reverse the pots direction (I added 1023- to the writeValue lines. It did the job.
Looking at the new code, I'm trying to understand how a shift right works with an analogue input. Baffling...
The problem seems to be gone, but I still don't understand what caused it. If it was working before, why suddenly act up on a few restarts? Doesn't make sense.
I'll add the blink without delay code to help me determine if code is running or not.
This is my circuit, but add in your pots on A0, A1, and A2. Wiper to analog inputs, and then one side each to +5V and Gnd.