Problem in analogwrite

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 …

Άτιτλο 2.txt (28.6 KB)

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.

You are aware that after executing the below

    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.

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 ...

You can't read the output of a PWM with the analog pins ;)

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 .

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.. :)

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.

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

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 .

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

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); }

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); }

Whatever I try to do the same. Now I have tried it and the prices are not fixed.

How are the LEDs wired?

.

larryd: 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

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.

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.

post #2

I have 12 leds altogether

Focus in on and attach a good image of the actual Arduino/Transistor/strip wiring.

.

larryd: Focus in on and attach a good image of the actual Arduino/Transistor/strip wiring.

.

https://drive.google.com/drive/folders/0B5kE1bR2TEdcZHRQMldmcWx6c3c?usp=sharing

If you think the problem is at tip120, then change and try again.

What are the values of the base resistors.

.

larryd:
What are the values of the base resistors.

.

2.2 K