reading LM 35 with I2c

how this code program, slave_sender and master_reader, if i want read sensor LM 35 using slave sender, and master reader can reading this sensor to display in computer. please give me solution.

You have two Arduino boards ? And they are connected with an I2C bus ? And the LM35 is connected to the Slave ?

This is the example : http://arduino.cc/en/Tutorial/MasterReader

You can pass an integer (in 1/100 degree Celsius) or a float (in Celsius).

When you show us your sketch for both Arduino boards, we can tell where to go from there. You can paste you sketch between code tags.

Is the LM35 already working ? Can you get the temperature ?

An LM35 is not I2C compatible, it provides an analog signal. It can be read using an analog input pin.

You have two Arduino boards ?
And they are connected with an I2C bus ?
And the LM35 is connected to the Slave ?

This is the example : http://arduino.cc/en/Tutorial/MasterReader

You can pass an integer (in 1/100 degree Celsius) or a float (in Celsius).

When you show us your sketch for both Arduino boards, we can tell where to go from there. You can paste you sketch between code tags.

Is the LM35 already working ? Can you get the temperature ?

ihave two arduino boards, they are conected with I2C, and LM35 connecct to the slave. LM 35 not read.

slave code

#include <Wire.h>
#include <LiquidCrystal.h>
#define tempPin A0

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
float tempC;

void setup()
{
//pinMode (8, OUTPUT);
//pinMode (9, OUTPUT);
//pinMode (10, OUTPUT);
lcd.begin(16, 2);

  Wire.begin(2);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
delay(100);
float tempC;
int tempPin = 0;
tempC = analogRead(tempPin);           //pembacaan nilai dari sensor
tempC = (5.0*tempC*100.0/1024.0);     //Converter dari tegangan ke suhu
  
  
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()

{
  //Wire.write("hello"); // 
 Wire.write(tempC); // respond with message of 6 bytes
                       // as expected by master
}

Master I2C

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

thanks

The LM35 is not producing a reading? How do you know that?
Do you have a working LCD on the slave arduino that you can display the raw analog input values? What does it show for a few different temperatures?

What two arduino boards are you using? What pins are you using to connect them using I2C ?

i have two arduino uno boards, and i’m using sda a4 and scl a5 to pin comunication i2c

You need to clarify what you mean by "not read". What exactly is appearing on your Serial Monitor. Have you verified that your slave is interpreting the temperature correctly by printing its value to the serial monitor? Have you verified exactly how many bytes are sent from the slave with Wire.write()? Do you know what format the float is sent as? Is it sent raw or converted first?

rudydarmawan: how this code program, slave_sender and master_reader, if i want read sensor LM 35 using slave sender, and master reader can reading this sensor to display in computer. please give me solution.

What is the problem exactly?

http://www.gammon.com.au/i2c

#define tempPin A0
int tempPin = 0;

Make up your mind!

float tempC;

This global variable and

float tempC;

this local variable occupy two different memory locations.

This:

tempC = analogRead(tempPin);           //pembacaan nilai dari sensor
tempC = (5.0*tempC*100.0/1024.0);     //Converter dari tegangan ke suhu

writes to the local variable.

This:

 Wire.write(tempC); // respond with message of 6 bytes

sends one byte, from the 4 bytes that make up the global variable (which you haven't valued).

That is NOT how to send a float.

Thanks Caltoa for the link to the tutorial. In his wire examples (the code itself, that comes with the Arduino software), Mr. Zambetti forgot to point out a very important point: that the master and slave devices need to share a common ground. It would have been good to know this.