Data logging gone wronging

hi guys, i seems to have incurred in a problem, apparently, when i try to write to my micro sd card with my arduino uno, if i upload this code here it works http://www.dallaf.it/simo/wp/2015/06/20/arduino-sd-card-module/
If i upload my code
include <SPI.h>
include <SD.h>
include <LiquidCrystal_I2C.h>
include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2); //dichiara l’LCD
int pintemp=1;
int val=0;
File file;
void setup() {
SD.begin(10);
lcd.init(); //fa partire l’lcd
lcd.backlight(); //aggiungi una luce dietro
}
void loop() {
file = SD.open(“numeri.txt”, FILE_WRITE);
if(file)
{
val = analogRead(pintemp);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
lcd.setCursor(0,0);
lcd.print(“Temperatura”);
lcd.setCursor(0,1);
lcd.print(cel);
lcd.setCursor(5,1);
lcd.print(“C”);
file.println(cel);
file.close();
delay(2000); }
}
it doesn’t open. As you can see i’m logging from a lm35, and without the sd card everything worked, i added the sd card and display works but there is no file in the sd card, also, when i changed the code a bit i discovered the sd card doesn’t even open, like the line file=SD.open doesn’t work. What am i doing wrong ?

I can't get to the web site where you have the code that works. Post it HERE.

You should put EVERY { on a line by itself. You should put every } on a line by itself. You should use Tools + Auto Format.

If the code you posted writes to the LCD, then the file IS opened.

What am i doing wrong ?

Not formatting the code to make it easier to read and not using [­code] ... [­/code] tags for a start.

Neither of these is causing your problem but presenting your code in an easy to read and copy format would make it easier to provide help.

Sorry guys, i’m a bit rusty with these kind of things, also no, it wrote to the lcd before i added all the sd stuff, now it doesn’t, the code that work is

/* Sketch che permette di aprire un file numeri.txt su SD Card
 * scrivere un numero casuale tra 0 e 999, chiudere il file
 * e rileggerne il contenuto
 */


#include <SPI.h>
#include <SD.h>



File file;




void setup()
{
  Serial.begin(9600);
  Serial.print("Inizializzazione Card: ");

  if (!SD.begin(4)) //il Pin 4 è collegato a CS
  {
    Serial.println("FALLITA!");
    return;
  }
  Serial.println("ESEGUITO!");
  
}






void loop()
{
  int c = random(0,1000); //Estraggo numero casuale tra 0 e 999
  
  file = SD.open("numeri.txt", FILE_WRITE); //File in scrittura

  if (file) //Se il file è stato aperto correttamente
  { 
    Serial.print("Numero casuale scelto: ");
    Serial.println(c);
    Serial.println("Scrittura su file: ");
    file.println(c); //Scrivo su file il numero
    
    file.close(); //Chiusura file
    Serial.println("ESEGUITO!");
  } 
  else 
  {
    Serial.println("ERRORE: apertura file numeri.txt");
  }

  file = SD.open("numeri.txt"); //Riapro il file
  if (file) //Se il file è stato aperto correttamente
  {
    Serial.println("Contenuto file numeri.txt: ");

    //Continua fino a che c'è qualcosa
    while (file.available()) 
    {
      Serial.write(file.read());
    }
    
    file.close(); //Chiudo file
  } 
  else 
  {
    Serial.println("ERRORE: apertura file numeri.txt");
  }
  
  delay(5000); //Attendi 5 secondi prima di ricominciare
}

and it works correctly, the same words on mine doesn’t … maybe the lcd is interfering ? is one of those that require only 4 pins. Also, now i took apart the sd and continued without, adding a relay.
Basically the thing i have to do is a temperature logger that when it senses a temperature below x degrees it closes a switch and turns on a heater. This is working, this is behind me at this moment, even though for some reason now the temperature oscillates 2 degrees strangely, the display says one temperature then another 2 degree below, and when the relay turns on, the lcd dims a lot … i’m powering it with cable, the circuit is easy, only connected everything to their place, lo lm35 to A2 (changed pin), a4 and a5 for lcd screen, pin 7 for relay, 5 volts to everyone.
Thank you for your help

This is my code now, sorry for the mess, it doesn’t have the sd card but it works.
I need the sd card to log the temperatures, so i know what happened … also coming in the future a smoke detector and buzzer or something like that.

#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); //declare the lcd
int pintemp = 2; //pin for the lm35
int val = 0; 
#define relay 7
File file;


void setup()
{
  lcd.init(); //start the lcd
  lcd.backlight();  //add backlight
  pinMode(relay, OUTPUT);
}

void loop()
{
  val = analogRead(pintemp);
  float mv = ( val / 1024.0) * 5000;
  float cel = mv / 10;
  lcd.setCursor(0, 0);
  lcd.print("Temperatura"); //print message to lcd
  lcd.setCursor(0, 1);
  lcd.print(cel);
  lcd.setCursor(5, 1);
  lcd.print("C");
  if (cel >= 40) 
  {
    digitalWrite(relay, 1); //turn on heater
  }
  else 
  {
    digitalWrite(relay, 0);
  }
  delay(2000);

}

Regardless of which pin is the slave select pin, pin 10 must be declared as an OUTPUT pin, on the UNO and other 328 based Arduinos. That makes the Arduino the SPI master. Without setting pin 10 to OUTPUT, it is INPUT, and the Arduino is a SPI slave. A slave (the Arduino) can't make another slave (the SD device) do anything.

I would not rely on some library making pin 10 an OUTPUT pin.

Your posts are pretty hard to read, since you seem to leave "not" out in a lot of places, where you say "this works" except that it doesn't do what you want.

So, I really can't figure out which of your code does what it is supposed to, in terms of writing to the SD card or in terms of writing to the LCD.