Arduino Uno, IR Temp sensors x 2 and LCD display

Hi there,

I am wanting to set up an arduino UNO coupled with an LCD Keypad shield display (Jaycar XC-4454), showing the temp of a couple of drive motors for the Racing SIM my son and I are building.

The reason I bought the shield vs just an LCD display was due to cost. The same 16 x 2 display is twice the price as a stand alone option. Plus its a nice combo I can place into a box easily.

The IR sensors that I bought (Jaycar XC-3704) use the MLX90615 sensor. The sketch I will use has the following info:

byte sda_1 = 3;
byte scl_1 = 2;
byte sda_2 = 5;
byte scl_2 = 4;
byte sda_3 = 7;
byte scl_3 = 6;

This is for three sensors, however I only need two. The sketch doesn’t talk about pins, but in other sensor videos and info I have found the analog in pins are used. Can anyone tell me what the code above is referencing? If it is the pin numbers, which are which?

Also, once I have that sorted, I want to use the display to read the output. If anyone can point me in the right direction it would be appreciated.

Cheers
Richard

Hey Richard,

In order for us to really get a grip of what’s going on with your project, we’re going to need some additional information (debugging by proxy can be tough). Could you please post:

  1. A brief description what you are trying to accomplish (eg, “Read the temperature from two analog sensors and display it on an LCD”)
  2. Any relevant code that is running in your project (or that you intend to run)

We won’t be able to tell you what this part of the code means without seeing it context. So please share the whole sketch and we will see what we can find!

Hi Stephen,

Thanks for the reply

The plan, as you have highlighted, was to read the temp from two sensors attached (or in my case, being IR, close to) to two separate DC motors, and show the result on an LCD. I have since done some more research and now I understand that the sensors I have purchased, being MLX90614 (not the MLX90615 as noted above) should be connected to the I2C pins, of which there are two opportunities to do so on the UNO.

I have used the following sketch which operates them beautifully, one at a time. If I connect them both at the same time one reads very strangely. I am guessing that is due to something extra needed in the code.

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

Serial.println(“Adafruit MLX90614 test”);

mlx.begin();
}

void loop() {
Serial.print(“Ambient = “); Serial.print(mlx.readAmbientTempC());
Serial.print(”*C\tObject = “); Serial.print(mlx.readObjectTempC()); Serial.println(”*C”);
Serial.print(“Ambient = “); Serial.print(mlx.readAmbientTempF());
Serial.print(”*F\tObject = “); Serial.print(mlx.readObjectTempF()); Serial.println(”*F”);

Serial.println();
delay(500);
}

Even if I could get them both to work, the LCD Shield I purchased won’t allow one of the sensors as it uses those pins for itself.

The code I was eluding to in my first post, which I thought would do the trick is below. As you can see it refers to the other sensor which I don’t think I in fact have. That aside, it also is an I2C setup, which confuses me more because there are only two places on the UNO to have this setup…from my very limited knowledge :laughing:

#include “MLX90615.h”
#include <I2cMaster.h>

byte sda_1 = 3;
byte scl_1 = 2;
byte sda_2 = 5;
byte scl_2 = 4;
byte sda_3 = 7;
byte scl_3 = 6;

SoftI2cMaster i2c_1(sda_1, scl_1);
MLX90615 mlx90615_1(DEVICE_ADDR, &i2c_1);

SoftI2cMaster i2c_2(sda_2, scl_2);
MLX90615 mlx90615_2(DEVICE_ADDR, &i2c_2);

SoftI2cMaster i2c_3(sda_3, scl_3);
MLX90615 mlx90615_3(DEVICE_ADDR, &i2c_3);

void setup()
{
Serial.begin(9600);
Serial.println(“Setup…”);
}

void loop()
{
float temperatureObj1 = mlx90615_1.getTemperature(MLX90615_OBJECT_TEMPERATURE);
float temperatureObj2 = mlx90615_2.getTemperature(MLX90615_OBJECT_TEMPERATURE);
float temperatureObj3 = mlx90615_3.getTemperature(MLX90615_OBJECT_TEMPERATURE);
float temperatureAmb1 = mlx90615_1.getTemperature(MLX90615_AMBIENT_TEMPERATURE);
float temperatureAmb2 = mlx90615_2.getTemperature(MLX90615_AMBIENT_TEMPERATURE);
float temperatureAmb3 = mlx90615_3.getTemperature(MLX90615_AMBIENT_TEMPERATURE);

Serial.print("Temp_1: ");
Serial.print(temperatureObj1);
Serial.print("C "); Serial.print(temperatureAmb1); Serial.println("C ");

Serial.print("Temp_2: ");
Serial.print(temperatureObj2);
Serial.print("C "); Serial.print(temperatureAmb2); Serial.println("C ");

Serial.print("Temp_3: ");
Serial.print(temperatureObj3);
Serial.print("C "); Serial.print(temperatureAmb3); Serial.println("C ");

Serial.println("\n=======================================\n\r");

delay(1000);
}

If you can suggest alternative hardware and code that is compatible with what I am trying to achieve I will place an order. I have lots of UNO’s though.

Cheers
Richard

Hi Richard,

I’m pretty confident that your sensors will be compatible with your Arduino Uno. It sounds like you may need to work on the way that the i2C devices are connected. You are definitely on the right track if one sensor is working properly. The next step is to get both sensors on the same bus talking with the Arduino.

Here is a good tutorial on how to connect two sensors via i2C to an Arduino. This tutorial includes some example code, and you should be able to adapt it to your purpose without too much work!

Great! Thanks Stephen,

I’ll have a look at this and let you know how I go.

Cheers
Richard

2 Likes