I am trying to sense the temperature using the LM70 temperature sensor with an Arduino Mega. As you can see in the Datasheet, it uses the SPI protocol. I have made the following connections (VSSOP-8 Package):
- SI/O pin --> Pin 50 Arduino Mega.
- SC pin --> Pin 52 Arduino Mega.
- CS pin --> Pin 53 Arduino Mega.
- V+ pin --> 3.3V Arduino Mega.
- GND pin --> GND Arduino Mega.
My code does not work (it does not print the right temperature), and I think it can be for two reasons:
- I am not reading correctly the information from the sensor. It sends 16 bits, from which the 11 first bits store the data for the temperature.
- I am not calculating the temperature in the right way.
This is my code:
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
void setup() {
pinMode(51,OUTPUT); //MOSI
pinMode(50,INPUT); //MISO
pinMode(52,OUTPUT); //CLOCK PIN
digitalWrite(53,HIGH); //slave select stays high. When we set this to low, the sensor will start to send data.
SPI.begin();
Serial.begin(9600);
//time to set up
delay(500);
}
void loop() {
//enable Slave
digitalWrite(A0,LOW); //Enable communication with slave
delay(500); //wait for conversion
int val = SPI.transfer(0x00); // read from sensor
Serial.println(val); //display reading on serial monitor
int temperature = val * 0.25;
Serial.println(temperature); //display temperature on serial monitor
//disable Slave
digitalWrite(53,HIGH); //set to High again
}
Please, if you see something wrong in my code, let me know. Thank you in advance.
digitalWrite(A0,LOW)
-- Are you sure about that one?