Go Down

Topic: Code problem for DS18b20 (Read 901 times) previous topic - next topic

Paul_KD7HB

Please someone help cause this is urgently needed for a bigger project. I am really bad with circuits and programming as I am a mechanical engineer so I am not really good at this. I can post the picture of the circuit as well if someone wants to help and wish to double check if I did it correctly
I always buy at least two of all components for a new project. Your device may be defective.

Paul

omar-anan

Well I do have another sensor, Alright I will test the other one when I am home, I just wanted to be sure that I have nothing wrong with the circuit or the code first

Paul_KD7HB

Well I do have another sensor, Alright I will test the other one when I am home, I just wanted to be sure that I have nothing wrong with the circuit or the code first
Ok, let us know the results, good or bad.

By the way, just for general knowledge, the high temperature limit for the device is 125C. I have tested that and it is a logical limit and will not reset even when the temperature goes down. It will always report 125C until power is removed. Then it will report correctly, again.

Paul

omar-anan

I tried the other sensor and still the result is the same unfortunately, on serial monitor keeps showing -127

omar-anan

I am using UNO R3 ATmega328P USB-B, would that be the issue?

Paul_KD7HB

Here is my code for the drying oven:

float current_Temp = 0.0;        // reading from temperature sensor
float previous_Temp = 0.0;

int entered_Temp = 0;     // Temperature in whole degrees C.
int running_Temp = 0;

void check_current_Temp() {
  sensors.requestTemperatures();           // Send the command to get temperatures
  current_Temp = sensors.getTempCByIndex(0);
  running_Temp = current_Temp;             // use only the integer part of returned temperature value
  if (running_Temp >= max_Temperature) {  // have we met or exceeded the max temperature limit?
    turnOven_off();                       // yes!
    temp_Emergency = true;
    long_beep = true;
    reset_the_Parameters();
    show_Operator_message(5);
  }
}

Your problem may be that the unit is returning a float. My program was only concerned with the integer portion of the temperature, so I converted float to int.

Try the line in my code where I get the temperature into a float and see if that works. The sample program may be in error, or may be out of date.

Paul

terryking228

Hi,
Good overall DS18B20 information and code HERE.

You code shows pin 5 and pin 2 for the sensor. Which is it??
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

omar-anan

@terry It is connected to pin 5 on the board as it is mentioned on the code.

@Paul Can you please specify which line and with what should I replace it on the original code? or do you mean take your whole code and upload it?

Thanks guys


Paul_KD7HB

@terry It is connected to pin 5 on the board as it is mentioned on the code.

@Paul Can you please specify which line and with what should I replace it on the original code? or do you mean take your whole code and upload it?

Thanks guys


Just these two, where current_Temp is a float. Replace your line with these two.

    sensors.requestTemperatures();           // Send the command to get temperatures
    current_Temp = sensors.getTempCByIndex(0);


Paul

terryking228

Hi, Here's your problem: These 2 lines:
---------------------( COPY )---------------------
// Data wire is plugged into pin 5 on the Arduino
#define ONE_WIRE_BUS 2
-----------------( END COPY )----------------------
The first line is just a comment

The second line says what pin you are really using.   You are using pin 2
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Paul_KD7HB

Hi, Here's your problem: These 2 lines:
---------------------( COPY )---------------------
// Data wire is plugged into pin 5 on the Arduino
#define ONE_WIRE_BUS 2
-----------------( END COPY )----------------------
The first line is just a comment

The second line says what pin you are really using.   You are using pin 2
Well, I haven't heard from the OP in quite a while, so I guess he is off reading temperatures.

Nice catch, Terry. I missed it entirely.

Paul

Go Up