Attiny13a LM35 and pot 10K affect each other.

Hello!

Here is my schematics attached.

I have a fan controlled by LM35DZ and a pot for controlling a led dimmer.
Here is I have a code:

void setup()
{
 TCCR0A = 2<<COM0A0 |  3<<WGM00; // clear 0c0a at compare match //enable fast pwm
 TCCR0B =  1<<CS00; 
 
}

void loop() {
      
    analogWrite(0, map(analogRead(3), 0, 1023, 0, 72));  

    
    int t = analogRead(2)/2;
   
    if (t>80) {
      int value = (t-80)+55;  
      analogWrite( 1, value);
      delay(100); 
     
    }
   
    else {
      analogWrite( 1, 0); 
    }

    
}

LM35 works fine when the pot stays at the position 0 and the fan starts just when the temperature becomes the one when the fan has to start. As soon as I start rotating the pot the voltage on LM35 also changes and goes higher, and it starts the fan. How can I eliminate this interference? I've tried to add delay or dummies to give the Tiny's ADC time to recover, but it hasn't helped.

It sounds to me like a wiring issue. I would double (triple etc) check the wiring especially all the grounds.

+1 about wiring. 5A LED current, and associated volt drop in wiring/connectors, can upset measuring the small returned voltage of the analogue sensor. LM35 ground should connect directly to Attiny ground (not shared).

From the datasheet: "Like most micropower circuits, the LM35 device has a limited ability to drive heavy capacitive loads. Alone, the LM35 device is able to drive 50 pF" Means the 100n from out to ground has to go.

Try to read the LM35 twice after each other (no delays). If that doesn't help, then move to an easier to use digital DS18B20 sensor. Leo..

Wawa:
+1 about wiring.
5A LED current, and associated volt drop in wiring/connectors, can upset measuring the small returned voltage of the analogue sensor.
LM35 ground should connect directly to Attiny ground (not shared).

From the datasheet:
“Like most micropower circuits, the LM35 device has a limited ability to drive heavy capacitive loads. Alone, the LM35 device is able to drive 50 pF”
Means the 100n from out to ground has to go.

Try to read the LM35 twice after each other (no delays).
If that doesn’t help, then move to an easier to use digital DS18B20 sensor.
Leo…

Checked and rechecked with a multimeter so many times)

The LM 35 is connected to Attiny GND directly. The 100nF cap is already there if you have a look at the schematics.
I’ve tried reading the LM35 twice with a dummy and it hasn’t helped. It seems like the voltage raises proportionally to the pot at all analog pins. I’ve measured the LM35 out. It goes from 450mV to 1000mV. And it’s not the noise.

Tofer: The 100nF cap is already there if you have a look at the schematics.

Yes, and I said it shouldn't be there.

Returned value of the A/D depends on two things. input voltage and VCC. Did you measure VCC of the Attiny when turning the pot. Leo..

Tofer: LM35 works fine when the pot stays at the position 0 and the fan starts just when the temperature becomes the one when the fan has to start. As soon as I start rotating the pot the voltage on LM35 also changes and goes higher, and it starts the fan. How can I eliminate this interference? I've tried to add delay or dummies to give the Tiny's ADC time to recover, but it hasn't helped.

You should try them one by one. First of all, simply serial print your temperature sensor LM35 value and pot analog value on the serial monitor, and check if they are dependent on each other or not. Do some testings and you will find the issue. Share images of your hardware setup.

BTW the MOSFET used is NOT a logic level device. The Tiny should be barely able to turn it on - it does not get hot?

jackthom41: You should try them one by one. First of all, simply serial print your temperature sensor LM35 value and pot analog value on the serial monitor, and check if they are dependent on each other or not. Do some testings and you will find the issue. Share images of your hardware setup.

It's an Attiny chip - there is no way I can print it. I can just measure everything via multimeter. And they are depending.

Wawa: Yes, and I said it shouldn't be there.

Returned value of the A/D depends on two things. input voltage and VCC. Did you measure VCC of the Attiny when turning the pot. Leo..

Yes, I've measured. There is no change found on the Tiny's VCC.

Smajdalf: BTW the MOSFET used is NOT a logic level device. The Tiny should be barely able to turn it on - it does not get hot?

I would check it later cause this part of scheme is not connected yet. It's not a logic level, but according to the datasheet it could provide more than 10A at with 4.5V at the gate.

I would check it later cause this part of scheme is not connected yet

When you do, do not connect the LED the way you have shown it. 1) it is the wrong way round 2) there is no current limiting, with such a high powered LED you need a constant current supply to control it not a simple PWM signal.

It is best if you post a photograph of your wiring so we can check the ground arrangement. I would also add better capacitors to that regulator you need to look up the actual data sheet from the manufacturers you are using to find the minimum values.

I do agree with Smajdalf. Vgs and Qg of this fet are both too high for the Attiny. Make sure you got those protective glasses on when you power up the LED. Leo..

C7 should be 10nF to 100nF at most, you're crow-barring the supply everytime Q2 switches on. Perhaps you meant there to be a decoupling cap to ground for the motor?

R5 should be more like 150 ohms, your powering a motor from that transistor, so the base needs enough current.

Q1 needs a pull-down resistor from gate to source, 10k to 100k will do, value not critical, to keep it from switching on during reset/power cycling.

Any reason for the large value of R6? 150 ohms is fine, if you are using PWM you likely need a gate driver IC anyway.

Tofer: It's not a logic level, but according to the datasheet it could provide more than 10A at with 4.5V at the gate.

It may work for static switching. I did not make the calculations but I am quite sure the (relatively) week ATTiny's pin slowed down by the 550 Ohm resistor have no chance to keep the gate above 4.5V for considerable amount of time. OTOH the gate capacitance and the resistor will form a low pass filter - the transistor will be in its active region most of time, acting as a variable resistor. A way to drive the LED safely (maybe) but you will burn all the excess power in the transistor. It will need considerable cooling.

Wawa: Yes, and I said it shouldn't be there.

Returned value of the A/D depends on two things. input voltage and VCC. Did you measure VCC of the Attiny when turning the pot. Leo..

I've added the cap there because the voltage was a bit noisy without it. Someone has recommended to add a cap in another topic I've found about LM35.

I've measured VCC. The pot doesn't influence it.

Grumpy_Mike: When you do, do not connect the LED the way you have shown it. 1) it is the wrong way round 2) there is no current limiting, with such a high powered LED you need a constant current supply to control it not a simple PWM signal.

It is best if you post a photograph of your wiring so we can check the ground arrangement. I would also add better capacitors to that regulator you need to look up the actual data sheet from the manufacturers you are using to find the minimum values.

What is the write way?

MarkT: C7 should be 10nF to 100nF at most, you're crow-barring the supply everytime Q2 switches on. Perhaps you meant there to be a decoupling cap to ground for the motor?

R5 should be more like 150 ohms, your powering a motor from that transistor, so the base needs enough current.

Q1 needs a pull-down resistor from gate to source, 10k to 100k will do, value not critical, to keep it from switching on during reset/power cycling.

Any reason for the large value of R6? 150 ohms is fine, if you are using PWM you likely need a gate driver IC anyway.

Should I connect C7 to GND or the way it is now is ok?

R5 - will do it.

Q1 pull-down resistor from G to GND right?

R6 - will do it.

Wawa: I do agree with Smajdalf. Vgs and Qg of this fet are both too high for the Attiny. Make sure you got those protective glasses on when you power up the LED. Leo..

I can change it to IRL1404ZPBF.

What is the write way?

The right way is to do what I said in reply #8. If you don't understand what I said then ask about specifically what you don't understand.

As for posting a picture see image guide

Tofer: I've added the cap there because the voltage was a bit noisy without it. Someone has recommended to add a cap in another topic I've found about LM35.

Try to put some (Datasheet suggests 2k) resistor between the cap and LM35's output. If the LM35 is oscillating (you cannot see that on a DMM) due to heavy capacitive load it should fix it.

Sorry everybody. It was a flux problem. I've washed the contacts many times and finally it doesn't affect each other.

Now it is time to test the LED part. I will try it with IRL1404ZPBF. And I don't get why it's not good this circuit as Grumpy_Mike has said. Where should be a current limiting?

Where should be a current limiting?

For an LED of that power the whole idea of a FET providing a PWM to the power is wrong. You need a dimmable constant current supply, all together a different and more complex circuit. Something like this https://www.wholesaleledlights.co.uk/80w-dimmable-led-driver-4772.html

Tofer: Now it is time to test the LED part. I will try it with IRL1404ZPBF. And I don't get why it's not good this circuit as Grumpy_Mike has said. Where should be a current limiting?

In (very simplified) theory a LED (as any other diode) have a forward voltage Vf. If applied voltage is less, no current flows. If applied voltage is higher, any current may flow. If your voltage source were ideal and Vf of the LED is less than 12V, infinite current would flow through the LED.

In reality there is no single forward voltage for a LED. But when driving a LED with strong enough voltage source minor change of the voltage leads to HUGE change in the LED current. It may also considerably change due to temperature and ageing (both the LED and the source). You need something to limit the current (the LED may have something built in - we don't know what you are using).

OTOH if the diode does not have so sharp diode characteristic and the voltage source is weak (has internal resistance high enough) and the switching MOSFET has high enough resistance it MAY work as drawn (except for the LED is reversed). However until you test the system thoroughly you cannot say if it is not working close to a limit of a part causing premature failure.

Grumpy_Mike:
For an LED of that power the whole idea of a FET providing a PWM to the power is wrong. You need a dimmable constant current supply, all together a different and more complex circuit.
Something like this https://www.wholesaleledlights.co.uk/80w-dimmable-led-driver-4772.html

Sorry, but I don’t understand what you mean and why I need this power source, cause I’m not going to dim 230V I’m dimming 12V.

Smajdalf:
In (very simplified) theory a LED (as any other diode) have a forward voltage Vf. If applied voltage is less, no current flows. If applied voltage is higher, any current may flow. If your voltage source were ideal and Vf of the LED is less than 12V, infinite current would flow through the LED.

In reality there is no single forward voltage for a LED. But when driving a LED with strong enough voltage source minor change of the voltage leads to HUGE change in the LED current. It may also considerably change due to temperature and ageing (both the LED and the source). You need something to limit the current (the LED may have something built in - we don’t know what you are using).

OTOH if the diode does not have so sharp diode characteristic and the voltage source is weak (has internal resistance high enough) and the switching MOSFET has high enough resistance it MAY work as drawn (except for the LED is reversed). However until you test the system thoroughly you cannot say if it is not working close to a limit of a part causing premature failure.

Sorry, but most of led strips are dimmed by PWM dimmers.

Tofer: Sorry, but most of led strips are dimmed by PWM dimmers.

I don't have any LED strip but AFAIK they have the current limiting resistors (or other means to limit current) included.

EDIT: You NEED to verify if your LED may be powered from your source directly. It may be possible. But it may also cause magic smoke release or worse - parts of the devices flying around and/or fire.