Go Down

Topic: Problem in analogwrite (Read 349 times) previous topic - next topic

kostas90210

May 16, 2017, 10:45 am Last Edit: May 16, 2017, 10:57 am by kostas90210
Hello!!

I have create a construction with ardouino mega for the control of some relays with some sensors as bace .. I use 1 lcd 20x4 and one keybad 4x4. When i use the pins 3 and 13 in analogwrite the mesures that it does for the control of volt are unstable with diffrence as 1 volt .. i give you the code that has the problem ....



septillion

1) On a standard Arduino Uno pin 13 isn't capable of analogWrite. (Still unclear to me why on earth they used 13 for the onboard LED...)

2) You do know analogWrite() does NOT output a voltage? It outputs a PWM waveform with the duty cycle set with the analogWrite() value.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

sterretje

#2
May 16, 2017, 01:37 pm Last Edit: May 16, 2017, 01:39 pm by sterretje
You are aware that after executing the below

Code: [Select]
    if (hour() == 00 )

      analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);


    if (hour() == 1 )
      analogWrite(ledR, 10);
    analogWrite(ledG, 0);
    analogWrite(ledB, 100);

    ...
    ...

    if (hour() == 23 )

      analogWrite(ledR, 70);
    analogWrite(ledG, 40);
    analogWrite(ledB, 100);

ledG will always be set to 40 and ledB will always be set to 100; it's not affected by the value of hour. The only thing that the above does is set ledR to a specific value depending on the hour variable.

The duty cycle on ledG and ledB will therefore be all over the show while executing the above.

Note that the above comment does not take into account whether the pins are actually PWM pins or not.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

kostas90210

Sorry i dint write it right because my engilh are not so good ...
I have ardouino mega 2560 and in the pins 3 and 13 i control some leds with PWM .. The reading on the volts are done in  A,A1, A2, ... When i give command in 3 and 13 pins to open the leds then every mesourment in analog (A0,A1,A2) its not correct  and unstable , it goes up and down all the time ... For example : The mesourments on the volts may began from 12 to 13 .. When i shoutdown  the 3 and 13 pins then all the mesourments are back to normal ...

septillion

You can't read the output of a PWM with the analog pins ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

kostas90210

#5
May 16, 2017, 03:12 pm Last Edit: May 16, 2017, 03:20 pm by kostas90210
i dont want to read the output of PWM . In the analog pins i have connect 2 counters volts 2 sencors PIR 2 temp sencors ...
In the LCD monitor i have the numbers from analog input their are not steady when i use pins 3 and 13 with exit PWM .

TomGeorge

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

septillion

You connected what? Link to it please because "2 counters volts 2 sencors PIR 2 temp sencors" doesn't make sense...

Also, fix the problem pointed out by sterretje and repost the code again. Correct this time.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

kostas90210

In a few hours i will send them to see them because now i am on my job .... thanks a lot ...

kostas90210

#9
May 16, 2017, 06:38 pm Last Edit: May 16, 2017, 06:43 pm by kostas90210
As it shows in the picture  in pins 3 and 13 is the leds. In pins A11 and A12 is the sensors for the mesurments of the volts from some batteries i have .

https://drive.google.com/file/d/0B5kE1bR2TEdcUW40OFkzUnkwaTA/view?usp=sharing

When the leds are not working the mesurment is steady . See the video i have sent ...

https://www.youtube.com/watch?v=bFr6cWX-v14


When i add this code .... for the leds to open then the mesurments i get are not steady ... This is making me much problems for the cause i need that program .


Code: [Select]

int ledR = 3;   
int ledB = 13;


void setup()
  pinMode(ledR, OUTPUT);

  pinMode(ledB, OUTPUT);



void loop()

 {
    if (hour() == 00 )

      analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);


    if (hour() == 1 )
      analogWrite(ledR, 10);
    analogWrite(ledG, 0);
    analogWrite(ledB, 100);

    if (hour() == 2 )
      analogWrite(ledR, 0);
    analogWrite(ledG, 0);
    analogWrite(ledB, 120);

    if (hour() == 3 )
      analogWrite(ledR, 0);
    analogWrite(ledG, 20);
    analogWrite(ledB, 120);


    if (hour() == 4 )
      analogWrite(ledR, 0);
    analogWrite(ledG, 50);
    analogWrite(ledB, 110);




    if (hour() == 5 )
      analogWrite(ledR, 0);
    analogWrite(ledG, 80);
    analogWrite(ledB, 100);


    if (hour() == 6 )
      analogWrite(ledR, 0);
    analogWrite(ledG, 100);
    analogWrite(ledB, 70);







    if (hour() == 16 )

      analogWrite(ledR, 150);
    analogWrite(ledG, 20);
    analogWrite(ledB, 40);



    if (hour() == 17 )

      analogWrite(ledR, 160);
    analogWrite(ledG, 0);
    analogWrite(ledB, 0);

    if (hour() == 18 )

    analogWrite(ledR, 150);
    analogWrite(ledG, 50);
    analogWrite(ledB, 20);


    if (hour() == 21 )

      analogWrite(ledR, 120);
    analogWrite(ledG, 40);
    analogWrite(ledB, 50);

    if (hour() == 22 )

      analogWrite(ledR, 90);
    analogWrite(ledG, 50);
    analogWrite(ledB, 80);

    if (hour() == 23 )

      analogWrite(ledR, 70);
    analogWrite(ledG, 40);
    analogWrite(ledB, 100);

  }



video 2


larryd

#10
May 16, 2017, 06:47 pm Last Edit: May 16, 2017, 06:49 pm by larryd
Did you want this?
    if (hour() == 00 )
    analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);

Or did you want:
    if (hour() == 00 )
{
    analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);
}
No technical PMs.
The last thing you did is where you should start looking.

kostas90210

Did you want this?
    if (hour() == 00 )
    analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);

Or did you want:
    if (hour() == 00 )
{
    analogWrite(ledR, 30);
    analogWrite(ledG, 20);
    analogWrite(ledB, 100);
}
Whatever I try to do the same. Now I have tried it and the prices are not fixed.

larryd

How are the LEDs wired?

.
No technical PMs.
The last thing you did is where you should start looking.

kostas90210

How are the LEDs wired?

.
It's a led strip (RGB). The green is on pin 44

int ledG = 44;


If only I put this code

If (hour () == 7) {

    AnalogWrite (ledG, 130); // pin 44
 }

it works right.
The problem is at 3 and 13 pins.
Of course, they instruct TIP 120 before the led

sterretje

#14
May 16, 2017, 07:28 pm Last Edit: May 16, 2017, 07:31 pm by sterretje
What ledstrips? Please post a link.

Please post a complete diagram including how everything is powered. If your ledstrips have roughly more than 10 leds per colour and you drive them directly from the arduino, that is more than likely your problem.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up