Selcius and Fahrenheit with "Adafruit-MLX90614-Library in an Arduino-scrypt

Celsius and Fahrenheit with " Adafruit-MLX90614-Library" in a Arduino-scrypt.

Hi, i am using the "Adafruit-MLX90614-Library in an Arduino-scrypt.
(below the scrypt)

My problem is that it is using Fahrenheit and i want to use Celsius.
I am a newbee in making or changing the scrypt (still learning :slight_smile: )

How can i change this in this Arduino-scrypt please ?

Can somebody help me?.......

Thank you

Guido Monstrey from Belgium The Flanders

This is the Arduino-scrypt below :

////////////////////////////////////////////////
// iThermowall Thermometer Firmware //
// by Tomy Abuzairi and Ridho Maulana Mohamad //
// Modified by Open Green Energy //
////////////////////////////////////////////////

#include <Adafruit_SSD1306.h> //library oled
#include <Adafruit_MLX90614.h> //library sensor temperature
#include <Wire.h> //library I2C
#include <millisDelay.h> //library looping

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

const int GREEN_LED = 3; // pin D3 for green LED
const int RED_LED = 5; // pin D5 for red LED
const int buzzer = 7; // pin D7 for buzzer
const int statePin = 9; // pin D9 for IR proximity sensor

bool measurement = false; //check temperature measurement running

const unsigned long interval_sensor = 50; // interval refresh sensor in mS
millisDelay sensorDelay; // the delay object

const unsigned long interval_display = 500; // interval refresh OLED display in mS
millisDelay displayDelay; // the delay object

const unsigned long delay_hold_red = 5000; // delay hold red LED in mS
const unsigned long delay_hold_green = 1000; // delay hold green LED in mS
millisDelay holdDelay; // the delay object

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Declaration for an MLX90614 sensor connected to I2C (SDA, SCL pins)
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("OLED Display allocation failed"));
for(;;);
}

pinMode(statePin, INPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
pinMode(buzzer, OUTPUT);

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 20);
display.println("Initializing");
display.display();
delay(250);
display.clearDisplay();

mlx.begin(); //sensor initialization

displayDelay.start(interval_display); //refresh display
}

void loop()
{
static float temperature = -1; //initial condition

int state = digitalRead(statePin); //IR sensor condition

// check if the IR sensor detect people in front of sensor. If it is, the state is LOW:
if (state == LOW && measurement == false)
{
sensorDelay.start(interval_sensor); //read sensor
displayDelay.finish(); //finish interval refresh for display
measurement = true; //change state of measurement
}

if (measurement == true)
{
//if sensor reading
temperature = GetTemp(); //get temperature in celcius

}else
{
temperature = -1; //marker if sensor not reading temperature
}

ShowTemp(temperature ); //display temperature to OLED

holdReading(); //call holdReading function
}

float GetTemp()
{
static int index = 0;
static float temptot = 0;
float hasil = 0;
if (sensorDelay.justFinished())
{
// read sensor and repeat
sensorDelay.repeat(); // repeat
// temptot += mlx.readObjectTempC(); //add the reading to the total
temptot += mlx.readObjectTempF();
index++; //increment index
if(index==19)
{
//if already 20 measurement
hasil = temptot/20; //calculate average
temptot = 0; //zero total
index = 0; //zero index

  sensorDelay.stop();     //stop reading
  displayDelay.finish();  //complete the refresh interval so that it shows immediately
  
  return hasil;           //give results
}

}
return hasil; //As long as there are no results, give a value of result = 0
}

void ShowTemp(float temperature)
{
if (displayDelay.justFinished())
{
displayDelay.repeat(); // repeat
//show temperature
if(temperature == -1)
{
//if there are no object in front of sensor
display.clearDisplay();
display.setTextSize(2);
display.setCursor(35, 5);
display.print("-----");
display.setCursor(105, 20);
display.print("");
display.setTextSize(2);
display.setCursor(35, 40);
display.print("-----");
display.setCursor(105, 46);
display.print("");
display.display();
}else if(temperature == 0)
{
//if still reading temperature
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 25);
display.println("WAIT ....");
display.display();
}else
{
//if there is a new result

  temperature += 8.5; // sensor temperature calibration
  
  display.clearDisplay();     
  
  if( temperature > 100)
  {
    display.setTextSize(3);
    display.setCursor(5, 20);
    display.print(temperature,1);      
    display.print("F"); 
    // display.print("C");       
  }
  else
  {
  display.setTextSize(3);
  display.setCursor(10, 20);
  display.print(temperature,1);      
  display.print(" F");
 // display.print("C ");
  }
  display.display();

  if (temperature > 100.4) 
  {
    //if the temperature is too high
    digitalWrite(RED_LED, HIGH);
    holdDelay.start(delay_hold_red);  //run delay for red LED or temp > 38
  }else
  {
    //if the temperature is normal
    digitalWrite(GREEN_LED, HIGH);
    holdDelay.start(delay_hold_green);  //run delay for green LED or temp < 38
  }
  digitalWrite(buzzer, HIGH);
  
  displayDelay.stop();          //stop refresh display
}

}
}

void holdReading()
{
if (holdDelay.justFinished()) {
// if holddelay finish
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW);
digitalWrite(buzzer, LOW);

measurement = false; //allow new measurements

displayDelay.start(interval_display); //restart the OLED display 

}
}

Suppose I said that the temperature was 61 degrees Fahrenheit. Do you know the formula to convert that to Centigrade ? If not, then I am sure that Google does

It would also be common for libraries dealing with temperature to have function to do it for you

What do you suppose this line might do if it were not commented out in your code ?

// temptot += mlx.readObjectTempC(); //add the reading to the total

Hi, Bob,
thank you for helping me.
So , i place the line number 105 not commented :slight_smile:

105 temptot += mlx.readObjectTempC(); //add the reading to the total

and line number 106 commented ?

106 // temptot += mlx.readObjectTempF();

Then at line 168 , i place it in not commented :

168 display.print("C ");

and line 175 commented :

175 // display.print("F ");

Then at line 175 commented :

175 // display.print(" F");

And at last ( i think) i place line 176 not commented :

176 display.print("C ");


Can you say it is all i have to change please?

Sorry for asking this question, but as i say i am a newbee and arduino is not so simple.....
Thank you for puting your time in this.....for me.....
I will try it and let you know, but first i make the machine. It is a project from Instructabels :

Thanks again Bob for helping a not so smart person....lol.....

Friendly greatings

Guido

What happened when you tried it ?

hi, Bob,
i did not yet change it.....i have to wait for the parts.
I did order them last week at Amazon.nl, so maybe this week or later.
I saw in the instructions from that project (instructabels ) that it was set on Fahrenheit.
So, in the questions below instructabels) i did read that some people did ask for Celsius.
I did a google-search on the Library but this was to complicated for me....(the language Arduino , i must learn more....lol) So, i did place a question in the Arduino-forum and there you were....lol...
Thanks to you....
I will let you know asap.....
But you think that it will be all to change?

Guido

Yes. The main change is to get the value into the variable in the units that you require. The rest is just cosmetic

ok, thanks.....i let you know.......

It is working Bob !!!!!!
Thanks to you it shows Celsius instead of Fahrenheit.
I did make the changes at the lines 105 106 167 168 175 176 and it was WOW.

thank you so much for helping me out

Guido

Well done

It is you : well done !!!!.......

So, you know the whole language for making scripts. Can i ask what work you do please? Or did you learn it all by your self?
I am learning this to but....... :wink:
At the start you were a little bit angry at me, can it be?
Was it because i did ask a kind of stupid question?
Never the less.....you did help me and putted me on the right track....lol.....
Therefore thank you thank you thank you.....
Guido from Belgium The Flanders

Programming is a hobby activity for me. I do it because I enjoy it and enjoy helping others. I have never been employed as a programmer but I have written programs to help me with my job testing and implementing software solutions for hospitals and I have taught myself enough of any programming language that I needed to use, including C++

I was never angry with you but the solution was staring you in the face and I was surprised that you could not see it as the function names were very obvious, but there may have been a language problem

When answering questions here I often respond by asking a question to get the poster thinking for themselves rather than just giving them the answer. Sometimes that can seem less than helpful but I don't mean it that way

oke....at first i did look into the script....not good enough......lol......

thanks again for helping me....

Guido

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.