Peltier temperature control

Hi,
Like this example.

Tom... :slight_smile:

TomGeorge:
Hi,
If you are controlling a MOSFET gate with the UNO or any controller, you must have the gnds of the controller connected to the gnd of the load supply, so that you apply the correct bias to the MOSFET gate.

Use you DMM and measure if there is any voltage between the UNO gnd and the MOSFET source pin, please.

Tom.. :slight_smile:

I'm still waiting on the mosfets to arrive but will do when they get here.

TomGeorge:
Hi,
Like this example.

Tom... :slight_smile:

Yes that looks basically like what I am trying to build.

Study the first part/diagram in the link I gave you in post#11.
Hope you ordered logic-level n-channel fets.
Leo..

SethC:
Sorry guys, that was a diagram from someone else with a similar project I stole and didnt pay much attention to.

Thumbs up for your honesty, but do you really believe that such an attitude motivates people to help you?

You are too lazy to create a schematic yourself, or to find one that matches your setup?

Do you want answers that match your project/questions,
or some that relate to a similar project/questions?

P.S. do at least some research on Peltier elements before mistreating them.

Whandall:
Thumbs up for your honesty, but do you really believe that such an attitude motivates people to help you?

You are too lazy to create a schematic yourself, or to find one that matches your setup?

Do you want answers that match your project/questions,
or some that relate to a similar project/questions?

P.S. do at least some research on Peltier elements before mistreating them.

I apologize, I haven't had much time to focus on this much so i took some shortcuts.

I dont know if this is detailed enough for yall or not but heres the basic circuit I am trying to build.

Useless diagram.

Find a hobby that you have time for.

Maybe this is better

Hi,
This might be better;

Tom... :slight_smile:

TomGeorge:
Hi,
This might be better;

Tom... :slight_smile:

Thank you.

Finally got the mosfets in, now working on writing the code.
What I have now compiles correctly and shows no errors, just wanted to check with yall to see if there is anything I should change.
Here's what I have:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
Adafruit_BME280 bme;

#include <LiquidCrystal.h>
#include <TimerOne.h>
#include <PID_v1.h>

//Temperature variables - LM35
const int temperaturePin1 = A0;
const int temperaturePin2 = A1;

float getVoltage(int pin)
{
return(analogRead(pin) * 0.004882814);
}

//H-Bridge variables
int pwmPin = 10;

//PWM & PID variables
double Setpoint, Input;
volatile double Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

PID fridgePID(&Input, &Output, &Setpoint, consKp, consKi, consKd, REVERSE);

// Initialise LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int loopNum = 0;

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

bool status;
status = bme.begin(0x76);
Serial.begin(9600);

//LCD
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Peltier");
lcd.setCursor(0,1);
lcd.print("Controller 1.0");

// Change PWM frequency to 16KHz
Timer1.initialize(62); //62 microsecond pulse period
Timer1.attachInterrupt(pidLoop);

//PID
fridgePID.SetOutputLimits(300, 1023); //Timer1 library takes 0-1023 for analog write
fridgePID.SetMode(AUTOMATIC);

}

void loop() {
// Reading temperature
float RH = bme.readHumidity();
float getVoltage(int pin);
float voltage1, degreesC1, degreesF1;
float degreesCout = bme.readTemperature();
voltage1 = getVoltage(temperaturePin1);
degreesC1 = (voltage1 - 0.5) * 100.0;
degreesF1 = degreesC1 * (9.0/5.0) + 32.0;

float H = (log10(RH)-2)/0.4343 + (17.62*degreesCout)/(243.12 + degreesCout);

float dewpointtemp = 243.12*H/(17.62-H);

if (loopNum == 20000) {
degreesC1 = dewpointtemp / 20000;
dewpointtemp = 0.00;
}

//PID
Setpoint = dewpointtemp;
Input = degreesC1;

double gap = abs(Setpoint-Input); //distance away from setpoint
if(gap < 2)
{ //we're close to setpoint, use conservative tuning parameters
// fridgePID.SetTunings(consKp, consKi, consKd);
fridgePID.SetTunings(aggKp, aggKi, aggKd);
}
else
{
//we're far from setpoint, use aggressive tuning parameters
fridgePID.SetTunings(aggKp, aggKi, aggKd);
}

fridgePID.Compute();

if (loopNum == 20000) {
loopNum = 0;

lcd.clear();

// First row
lcd.print("Temp: ");
lcd.print(degreesC1);
lcd.print("/");
lcd.print(dewpointtemp);

//Second row
lcd.setCursor(0,1);
lcd.print("Power:");
lcd.print((Output/1023) * 100);
lcd.print("%");
}

loopNum = loopNum + 1;
}

void pidLoop() { // Repeats every 62 microseconds
Timer1.pwm(pwmPin, Output);
}

check with yall to see if there is anything I should change.

Use code tags when posting code.

ok

ok, so ive built the circuit with the mosfet and trying to run with the code above, but the mosfet is staying on. Here is the link to the mosfet I am using: N-MOSFET Driver / Output Module | Freetronics. any suggestions?

Hi,
Have you got it connected correctly?


Have you got valid temperature readings on the lcd?

Tom... :slight_smile:

Hi,

 float getVoltage(int pin);

What is the pin number for "int pin" and what is that line supposed to do?

Tom... :slight_smile:

TomGeorge:
Hi,
Have you got it connected correctly?


Have you got valid temperature readings on the lcd?

Tom... :slight_smile:

TomGeorge:
Hi,

 float getVoltage(int pin);

What is the pin number for "int pin" and what is that line supposed to do?

Tom... :slight_smile:

Yes, I have it connected as shown in the diagram, but the mosfet will not turn off. That line of code is for the inside temp sensor.

Also, I dont have the lcd hooked up, but i'm printing them in serial so I can see the temps.

Ok, so i have it running now and the desire temperature is being reached, however I dont think it is due to the pwm control. The serial monitor is printing the power percent and it is staying around 30% but when I measure the current output of the power supply and the current input of the peltier it is running at the normal amount for 12 volts. I think this piece of code may be an issue :

  if (loopNum == 20000) {
    degreesC1 = dewpointtemp / 20000;
    dewpointtemp = 0;
  }

My dewpoint will never be 0, so this is incorrect. Not sure how to correct it though.