Transistor circuit interfers with sensor reading (SHT85)

Hello my dears,

I am building a "simple" circuit based on the Arduino Micro to control the temperature in a box. The principle is simple:

  • SHT85 sensor to read the temperature
  • 4 power resistors to generate heat (25W, 1.5 Ohm) on a 24V power supply
  • PID controller with 2 transistors (BC337 and IRFZ44NPBF) to PWM control the 24V

The circuit without connected devices looks as follows:

...and with connected devices:

The power supply is connected to a regular outlet with no ground wire (German outlet). The 24V go into U5 in the diagram. U4 takes the power resistors. The SHT85 gets the power and ground from U3 and the SCL and SDA lines are connected to U2. The Arduino gets its power from my laptop, which is connected to its power supply.
The BC337 is used to fire the IRFZ44NPBF which inverts the logic: when BC337 is on, the IRFZ44NPBF is off and the other way around.

My problem is that when I do not connect the 24V power supply, the sensor readings work well. As soon as I connect the power supply, some readings fail and the Arduino even freezes from time to time. I suspect it may be an issue with ground between the Arduino and the power supply.

Here is the code:

#include <Wire.h>
#include "SHTSensor.h"
#include <PID_v1.h>
#define PIN_OUTPUT 6

SHTSensor sht;

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp = 5, Ki = 0, Kd = 0; //Kp=50, Ki=1, Kd=5;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup() {
  pinMode(PIN_OUTPUT, OUTPUT);
  
  Wire.begin();
  Serial.begin(9600);
  delay(1000);

  if (sht.init()) {
      Serial.print("init(): success\n");
  } else {
      Serial.print("init(): failed\n");
  }
  sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x

  if (sht.readSample()) {
    Input = sht.getTemperature();
    Setpoint = 30; // desired temperature
  } else{
    Serial.println("Failed to init PID");
  }

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void loop() {
  if (sht.readSample()) {
      String temp = String(sht.getTemperature(), 2);
      String hum = String(sht.getHumidity(), 2);
      String per = String(Output, 2); // percentage of max. voltage
      Serial.println(temp + " " + hum + " " + per);

      Input = sht.getTemperature();
      myPID.Compute();
      analogWrite(PIN_OUTPUT, 255-Output); 
  } else {
      Serial.print("Error in readSample()\n");
  }
 
  delay(1000);

}

Edit:

I designed a PCB (which is actually my first PCB). Don't get confused by the lower right part of it. I intended to control two lines of resistors. I removed these from the schematic to reduce confusion. The ground of the PCB is on the lower side, which is connected to the Arduino ground.

Not the problem, but R4 should be at least 10K.

Please post a schematic showing ALL the connections, and a photo of the setup.

1 Like

Time for opt-isolator to be used.

1 Like

I added it to my initial post. I will resolder a 10K resistor to R4 and see if that helps. Could it be that there is too much current on the PCB? My copper traces could be a bit narrow for up to 4A. On the other hand, even when there is much less current flowing I get reading errors.

Edit: the 10K resistor did not help, unfortunately.

Edit: I swapped the power resistors (connected to U4) with an LED which draws about 30mA max. No errors in sensor readings so far.

Sorry, I am just a mechanical engineer. Could you please clarify what you mean exactly? Where would I put this optical isolator? I suppose you are suggesting to exchange the BC337 with an optical isolator. Would I still need to connect the ground of the IRFZ44NPBF to the Arduino ground?

You are creating a ground loop through the uC. Bond all IC grounds at one location.

image

1 Like

The first thing I would try is to connect the 24v ground to the Arduino powersupply ground, not to the arduino ground pin.

What is powering the Arduino?

The Arduino is being powered via USB through my laptop (which is connected to its power supply). I would not know how to access the USB ground. Any advice?

Laptop grounds are often very noisy when connected to another ground. I suggest:

  1. Replace the laptop with 5V adapter
  2. Replace Q2 with a transistor Opto Isolator.
1 Like

I will try option 2). Option 1) is not feasible for me, because I need to want to read the temperature and humidity readings and visualise them using a Python script.

Is this all with the 'U4' connector open (no load applied)?

U4 takes 4 power resistors in series.

I was asking whether the load was connected or not.

Hi,
I agree with post #6, your PCB shows it.
Gnd the negative of the 5V supply AT THE 5V CONNECTOR ON THE EDGE OF THE PCB, scratch away some of the mask and connect the negative pin of connector U3 to the gnd fill around it.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi,
What is your 24V supply for the heater resistors?
1.5 Ohms on a 24V supply at full 100% pwm will need;
I = V / R = 24 / 1.5 = 16 Amps.
Power dissipated in heater resistors;
P = I x I x R = 16 x 1.5 = 384 Watts.

16A is a lot of current through that PCB trace.

Or do you have 4 x 1R5 in series?
If so then
24 / (4 x 1R5) = 4A
4 x 4 x (4 x 1R5) = 96W

But 4A is a bit much for those tracks.
You have two systems on your PCB, do you have two 24V power supplies?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:
PS. Your schematic needs to include ALL components, including power supplies, the SHT85, not just connectors with meaningless numbers. I do not see the I2C connection on your schematic either. Please labels, labels, labels.

Hi,
BUS I2C needs pull-up resistors.
Does your SHT85 sensor have these resistors fitted?
I didn't find them in your schematic.
Without them, I2C doesn't work.

1 Like

When the load is not connected, then everything works well with the readings. When I connect a tiny load, such as a LED, it still works with no errors. When I connect the power resistors, which take up to 4A, it gets messy.

Shouldn't the GND connections within the Arduino Micro be cross connected already? Instead of scratching something away, could I also just put a cable between connector U3-1 and say U5-1?

Yes, it is 4 heater resistors in series, so you are right with the 96W. To operate two systems on the PCB was my initial plan, but I figured that one would be plenty to reach the temperatures that I want. Therefore, the second system is not in use, so it is not connected to the power supply or anything at all.
Concerning the schematic, I updated the initial post schematic including all the components. Thank you.

That is a good comment. In fact I did not use pull-up resistors. I should have made a better drawing to make this clear...

I added two pull-up resistors of 10kOhm between SCL and VDD and between SDA and VDD. Unfortunately, I still get errors in the readings.