Using LM35 temp sensor with TEC1-12709 peltier (PID code) *confused*

Hi all,

So I’m getting a bit confused with my peltier project; I’m trying to control a peltier using a PID code (basic example from the Br3tt library) with a lm35 temp sensor as the input.

Here is what I’ve got coded:

/********************************************************
 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_v1.h>

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

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
  Setpoint = 10;
  Serial.begin(9600);

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

void loop()
{
  Input = analogRead(0);
  Input = (5.0 * Input * 100.0)/1024.0;
  myPID.Compute();
  analogWrite(3,Output);
  Serial.print(Input); Serial.println(Output);
  delay(1000); //delay next read out
}

The circuit configuration I’ve got is the same as this: http://garagelab.com/profiles/blogs/how-to-use-a-peltier-with-arduino
I currently am using a simple 12V 1.5A DC power supply connected to the GND and V+. The MOSFET I am using is a N Channel one from TI, rated for 60V and 100A (CSD18533KCS).

This configuration however does not work and I’m lacking the experience and knowledge to really know where the problem is, why it’s a problem and how to solve it. I have been looking at loads of different sources of info including the Br3tt step by step introduction and searched the arduino google group but can’t quite figure it out.

Help is much appreciated!!

I think you are missing a statement "pinMode(3, output)"

To save me looking it up, what do you expect myPID.compute() to do?

...R

We could use some more information please. you say:

This configuration however does not work

Tell us what you see, what you expect to see. Is your serial monitor showing readings you would expect? Is the peltier getting hot/cold? Have you tried hooking pin3 to a led to see if the pwm is changing? Go into detail.

Thanks, Jack

I tried a similar thing with de http://playground.arduino.cc/Code/PIDLibaryBasicExample , and I don't know how this PID Library works... the output dont't search the setpoint even input=setpoint (the output jump to 0 or 255). I think topic problems is the same, cause the code is very similar.

Robin2:
I think you are missing a statement “pinMode(3, output)”

To save me looking it up, what do you expect myPID.compute() to do?

…R

If I were to include that statement, where would I put it? What’s the syntax for including output references. Thanks :slight_smile:

jackwp:
We could use some more information please.
you say:

This configuration however does not work

Tell us what you see, what you expect to see.
Is your serial monitor showing readings you would expect?
Is the peltier getting hot/cold?
Have you tried hooking pin3 to a led to see if the pwm is changing?
Go into detail.

Thanks, Jack

Hi Jack,
What I see is that I can receive data from the serial port for the LM35, it was reading 25.6 which I verified with another digital thermometer I have. So that part is working well.

The peltier however, is not doing anything- it simply is lying there with no noticeable difference in temperature. The circuit set up for the peltier part is like this: http://garagelab.com/profiles/blogs/how-to-use-a-peltier-with-arduino and has worked with this code:

int peltier = 3; //The N-Channel MOSFET is on digital pin 3
int power = 0; //Power level fro 0 to 99%
int peltier_level = map(power, 0, 99, 0, 255); //This is a value from 0 to 255 that actually controls the MOSFET

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

//pinMode(peltier, OUTPUT);
}

void loop(){
char option;

if(Serial.available() > 0)
{
option = Serial.read();
if(option == 'a') 
power += 5;
else if(option == 'z')
power -= 5;

if(power > 99) power = 99;
if(power < 0) power = 0;

peltier_level = map(power, 0, 99, 0, 255);
}

Serial.print("Power=");
Serial.print(power);
Serial.print(" PLevel=");
Serial.println(peltier_level);

analogWrite(peltier, peltier_level); //Write this new value out to the port

}

All in all I am expecting to be able to at least feel that the peltier is responding to the set point. I will try an LED from pwm port 3 to see if the code is working with that! Hope that’s a bit more informative.

Cheers, Rhys

Yes, Rhys, that helps a lot. Could the peltier be burned out. It happens sometime. Can you just hook it to power through a dropping resistor to see if it heats up?

jackwp: Have you tried hooking pin3 to a led to see if the pwm is changing?

Ok so I have tried the LED trick- the code is seemingly working.

Fiddling with the settings (change set point to 30- I assume that the setpoint here is 30 degrees NOT power level :S) I can get a response where if the temp probe reads say 22.50 the LED is on a constant and intense brightness. As I hold the end of the probe to up the temp to the set point reading of 30 the LED still stays bright however it does slightly decrease (this would require a decrease in the D value of the PID settings correct?). If I then overshoot the temperature by dipping the sensor in a warm cup of tapwater (37 degrees) the LED will turn off after roughly 30 seconds of going dimmer, dimmer, dimmer (sensors are waterproofed!).

Then leaving the sensor to equalise again the led starts to flicker ON, On dimmer, Off in a fairly rhythmic and cyclic pattern as the temp goes back to 25.

So from this I can at least conclude that the code (even if the PID values need tuning) is doing it's job to pin 3. Meaning that the problem can either be with my peltier (checked and this works fine with just the positive and ground connected to the power supply I'm using. The only other two components in the set up are my mosfet and a 10k resistor.

Sounds like you have narrowed it down pretty well. If you have further questions, we are here.

I suspect you have already figured this out. http://arduino.cc/en/Reference/PinMode

...R

projectspotter: If I were to include that statement, where would I put it? What's the syntax for including output references. Thanks :)