ATtiny85 and MLX90614 cannot read temperature data

I'm trying to read sensor data from an MLX90614 using an ATtiny85 to turn on some LEDs if the temperature is in the corresponding temperature range.

Right now, all my readings are under 0 degrees. I am very new to electronics so I suspect I am doing something wrong.

I am using the Digistump Attiny85 (this one). Currently I have the SCL and SDA ports directly plugged into the SCL/ SDA pins of the Attiny85. But this doesn't seem to work.

Please advise on how to get the Attiny85 to read the sensor data.

Posted code in code tags.

An image of the project, posted.

A schematic, posted.

When you used the I2C scanner was your device detected. Oh wait, did you know there is a sketch to see if a I2C device can be found? My bad in assuming, sorry. Do an internet search using words "arduino i2c scanner" let us know what the scanner reports.

For I2C to work, there must be pullup resistors between SDA, SCL and 5V (typically 2.2K to 4.7K).

@Idahowalker Ok I will try and report thanks.

@jremington ok I will try thanks.

Adding a 4.7k pull up resistor seems to have done the trick.

However now the readings seem to be quite unreliable, the sensor sometimes reads what seems to be accurate other times it starts saying that its above 60 C and below 15 C in the next second. Any idea what is causing the flipping behavior?

try 1.7K to 2.2K

At 2.2k and 2k (I don't have a 1.7k) its back to reading just below 0.

POST THE CODE, using code tags.

post an image or 2 or 3 so that we can get a look-see on the thing do.


// Include library
#include <TinyWireM.h>
#include <Adafruit_MiniMLX90614.h>

// Define pins

int TINY_SDA = 0; //ATtiny SDA pin 5
int TINY_SCL = 2; //ATtiny SCL pin 7

int RED_PIN = 1;
int GREEN_PIN = 3;
int BLUE_PIN = 4;

float temp = 0;  //temperature is stored here

Adafruit_MiniMLX90614 mlx = Adafruit_MiniMLX90614(); //Set up MLX90614

void setup() {
  mlx.begin(); //init sensor

  pinMode(RED_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);

void loop() {

  temp = mlx.readObjectTempC();

  if (temp > 61) {
    digitalWrite(RED_PIN, HIGH);
  else {
    digitalWrite(RED_PIN, LOW);

  if (temp > 0 && temp < 60) {
    digitalWrite(GREEN_PIN, HIGH);
  else {
    digitalWrite(GREEN_PIN, LOW);

  if (temp < 1) {
    digitalWrite(BLUE_PIN, HIGH);
  else {
    digitalWrite(BLUE_PIN, LOW);


most likely the LEDS being driven with the SCL and SDA pins are an issue.

How come?

How else could I turn LEDs on and off based on some sensor input?

This might not be the cause of the problem, but it is a problem for the logic of your code anyway. Let us suppose that the temperature is 0.5. It would satisfy both conditions to light up green and blue pins simultaneously.

It is not common practice to have LED's on the I2C lines. If you want to see LED's blinking at 400Khz then tap the lines with some sort of isolation circuit and then drive the LED's. Right now the LED's are a load on the I2C line. I2C was not designed to drive LED's.

If you insist on seeing LED's flash at 400Khz then expect issues.

I don't think that I connected the LEDs to the I2C lines though. I2C is using pin 0 and 2 (digispark board pins), LEDs are on pins 1, 3 and 4. Or am I misunderstanding?

Also true, thanks for pointing that out.

1 Like

I thought the LED's were connected to the I2C pins from looking at a pinout of a ATtiny and a close up of the breadboard. Most likely I am in error.

Thanks for the help everyone.

Inserting the wires directly into the temperature sensor module did the trick. It was a faulty connection between the module and standoff pins after all.

Works both with and without the 4.7k pull up resistors.