I am a novice in Arduino. I am working on a temperature controller for a hot plate. I have a PT100 as sensor which is being driven by a 1mA constant current source. As the resulting output voltage is quite low, I am using an OpAmp for a gain of 11. The output of the OpAmp is connected to pin A4 of the Arduino.

The desired temperature is set by means of a potentiometer, the output of which (0-5V) is connected to pin A1 on the Arduino.

The PWM output for the heater is from Pin 9 and is fed to an opto-isolator (the output of which is connected to a Triac, which in turn controls the power to the heater element).

All this works quite well, except for a bug that I have not been able to find: On switching on, the PWM output is zero. It activates only when the potentiometer setting is brought quite low. After that, the setting can be changed as desired and everything works well. For example, if the potentiometer setting is for say, 150 degrees, the system will work just fine as long as it is not switched off (or if the power is not disrupted). In case of switching off (or power failure), followed by a subsequent switching on, the PWM output remains zero. It is only on bringing the potentiometer to a relatively lower setting that the PWM output gets reactivated. Once it does, then the potentiometer can safely be brought back to the original (or any other desired setting) and everything works just fine. Can anyone help me in finding the bug? I want that on switching on, the system should start working right away and control the heater (PWM) so as to attain the temperature as set by the potentiometer.

My sketch is as below:

// Heater Controller 

int heatingInPin = A1;// Heating pot slider connects here
int sensorPin = A4;// Temp Sensor output (amplified) connects here
int heaterPin = 9;// PWM heater output is available here
int tempDiff;

int sensorCount;// this holds the value of the Temperature Sensor after amplification
int heatSetCount;// this holds the value of the Temperature Control Pot
int pulseWidth;

void setup(){
    pinMode(heaterPin, OUTPUT);

void loop()
    sensorCount = analogRead(sensorPin);
    sensorCount = (sensorCount - 247);// apply offsetvalue  
    heatSetCount = analogRead(heatingInPin);

    heatSetCount = map(heatSetCount, 31,1023,0,440);// This gives a maximum temp of 400 degrees

    if (sensorCount >= heatSetCount)
        tempDiff = (heatSetCount - sensorCount);

        if (tempDiff >= 25)
            pulseWidth == 255;// heater is full ON
            pulseWidth = (10 * tempDiff);
        analogWrite (heaterPin,pulseWidth);
    delay (10);
  • I see a closing bracket to much at the end, that maybe should be after one of the else statements. Was that a copy paste error? – chrisl Apr 17 at 7:15
  • @chrisl, no bracket too much. I formatted it right – Juraj Apr 17 at 7:42
  • 2
    I find an error in your logic. Change pulseWidth == 255; to pulseWidth = 255;. – Vaibhav Apr 17 at 7:45
  • Thank you, Vaibhav. Although I don't see how this will effect the working of the sketch, it is definitely a logic error. I will revert after implementing it tomorrow. Thanks once again. – Deepak Nair Apr 17 at 15:28
  • until you start heating, the difference will be larger then 25. and there you don't start heating – Juraj Apr 17 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.