Skip to content

16. System integration

Integrating the electronics

My project has the particularity of having to be water-resistant, so I have to put all my electronics in boxes. I’ll have two main electronic parts: the ventilation system and the lighting system. The ventilation system will be integrated in a small box at the top of the cabinet, and the lighting system in the middle on the left. All wires will be made of plastic, and the connection will also be protected by plastic.

To control the LEDs, I’m going to create a two-way system: - Internet-based (based on ESP32) - Manually with 3 buttons and a small screen

Assemble, disassemble, replace

As my project will be used by students, it needs to be “idiot-proof”. This means that parts must be easy to disassemble, and there must be as little chemical assembly as possible. All parts are also well documented, so that if one breaks, it’s easy to replace. This will enable the project to be used over the long term, and perhaps improved in the future. In addition, I try to use inexpensive materials as much as possible, so that the maintenance of my project is not too costly.

As for the rest, it’s not done yet!

A little electronics

This week, I’m also doing a bit of electronics, the temperature control part. For this, I need a sensor, a power supply recovered from an LED kit and 2 fans.

Part quantity Supplyer
RP2040 1 Digikey
Resistances 0 OHM 3 Digikey
Resistances 10 OHM 1 Digikey
N mofset 2 Digikey
Thermistor 1 Digikey
Regulator 3.3V 1 Digikey
Diode 1.3A 2 Digikey
Capacitor 10uF 1 Digikey
Capacitor 1uF 3 Digikey
12V connector 1 Digikey
Fans 2 Trash

I made this circuit :

To make this part work, I’ve added 2 codes, the one that controls the temperature :

const int thermistorPin = A3; 
const float refResistance = 10000.0; 
const float refVoltage = 3.3; 
const float refTemperature = 25.0; 
const float betaValue = 3750.0;

void setup() {
  Serial.begin(9600); 
}

void loop() {
  int rawValue = analogRead(thermistorPin); 
  float voltage = rawValue * refVoltage / 1023.0; 
  float resistance = refResistance * (refVoltage / voltage - 1.0); // Calculer la rsistance du thermistor
  float temperature = 1.0 / ((log(resistance / refResistance) / betaValue) + (1.0 / (refTemperature + 273.15))) - 273.15; 
  Serial.print("Temprature : ");
  Serial.print(temperature);
  Serial.println(" C");
}

I’m having some problems with the code. I first used the previous code, but it didn’t work. After several attempts, I chose to redo it with ChatGPT 3.5. I also have a problem with the pin declaration, I have to put A and the pin number, otherwise I’ll get impossible numbers (90 degrees in the room).

And the one that controls the fans:

const int mosfetPin1 = D0; 
const int mosfetPin2 = D1; 
const int pwmFrequency = 1000;

void setup() {
  pinMode(mosfetPin1, OUTPUT); 
  pinMode(mosfetPin2, OUTPUT);
}

void loop() {

  for (int dutyCycle = 150; dutyCycle <= 255; dutyCycle += 5) {
    analogWrite(mosfetPin1, dutyCycle); 
    analogWrite(mosfetPin2, dutyCycle); 
    delay(100); 
  }

  // Diminuer progressivement l'amprage
  for (int dutyCycle = 255; dutyCycle >= 150; dutyCycle -= 5) {
    analogWrite(mosfetPin1, dutyCycle); 
    analogWrite(mosfetPin2, dutyCycle);
    delay(100); 
  }
}

I also have problems with the fans. My problem was also with the pin declaration. I need to put D and the number, not just the number. And it’s working !

So I created a code that combines the sensor and the fans. If the temperature value is below 25 degrees celcius, the temperature is perfect and the fans don’t need to run. Between 25 and 30 degrees, the temperature is too high but not too bad, so the fans will run at a moderate speed to reduce energy consumption and noise. Between 30 and 35 degrees, the temperature really starts to get too high, so fans will run at moderate/high speed. Above 35 degrees, the fans run at full speed.

const int thermistorPin = A3; 
const float refResistance = 10000.0; 
const float refVoltage = 3.3;
const float refTemperature = 25.0; 
const float betaValue = 3750.0;

int pwmValue = 0;

const int mosfetPin1 = D0; 
const int mosfetPin2 = D1; 
const int pwmFrequency = 1000;

void setup() {
  Serial.begin(9600);

  pinMode(mosfetPin1, OUTPUT); 
  pinMode(mosfetPin2, OUTPUT);
}

void loop() {
  int rawValue = analogRead(thermistorPin); 
  float voltage = rawValue * refVoltage / 1023.0; 
  float resistance = refResistance * (refVoltage / voltage - 1.0); 
  float temperature = 1.0 / ((log(resistance / refResistance) / betaValue) + (1.0 / (refTemperature + 273.15))) - 273.15; 
  Serial.print("Temperature : ");
  Serial.print(temperature);
  Serial.println(" C");

    if (temperature <= 25) {
        pwmValue = 0; 
    } else if (temperature >= 35) {
        pwmValue = 250; 
    } else {
        pwmValue = map(temperature, 25, 35, 100, 250);
    }

    analogWrite(mosfetPin1, pwmValue);
    analogWrite(mosfetPin2, pwmValue);

    delay(1000);

}