Conductivity Code Problem

I’ve a big problem with a code for an conductivity probe.
I want to buy a special conductivity probe but the code they have in the description have errors in code.
If anyone can help me to complete the code then i’m very happy.
When I Compile the code in Arduino IDE I get many Errors.
I need a fixed code and I hope I can put the Code into ArduBlockly to convert that I can take the output into Blockly to use with raspberry and home automation for my reef tank.
Pease Help!

Arduino codice sorgente:
# Umfassen <OneWire. h>
# Definieren StartConvert 0
# Definieren ReadTemperature 1
Const numReadings = 20 byte;//il numero del campione volte
Byte ECsensor Spille = A1;//Meter CE uscita analogica, Spille su analogico 1
Byte DS18B20 _ Spille = 2;//DS18B20 segnale, Spille su digitale 2
Unsigned int AnalogSampleInterval = 25, printInterval = 700, tempSampleInterval = 850;//analogico intervallo di campionamento; di serie di stampa intervallo; temperatura intervallo di campionamento
Unsigned int letture [numReadings];//le letture da il ingresso analogico
Indice di byte = 0;//la indice di la lettura corrente
Unsigned lungo AnalogValueTotal = 0;//il da corsa totale
Unsigned int AnalogAverage = 0, averageVoltage = 0;//la media
Unsigned lungo AnalogSampleTime, printTime, tempSampleTime;
Galleggiante di temperatura, ECcurrent;
//Temperatura chip di i/o
OneWire ds (DS18B20 _ Spille);//auf digitale Spille 2
Nichtig setup () {
//Inizializzazione di comunicazione seriale con il computer:
Serial. beginnen (115200);
//Inizializzare tutte le letture pro 0:
Pro (byte thisReading = 0; thisReading <numReadings; thisReading + +)
Letture [thisReading] = 0;
TempProcess (StartConvert);//lasciare che il DS18B20 avviare il convertire
AnalogSampleTime = millis ();
PrintTime = millis ();
TempSampleTime = millis ();
}
Nichtig loop () {
/*
Ogni tanto un po ", del campione il valore analogico e calcolare la media.
*/
Se (millis ()-AnalogSampleTime> = AnalogSampleInterval)
{
AnalogSampleTime = millis ();
//Sottrarre l'ultima lettura:
AnalogValueTotal = AnalogValueTotal-letture [index];
//Leggere dal sensore:
Letture [index] = analogRead (ECsensorPin);
//Aggiungere la lettura pro il totale:
AnalogValueTotal = AnalogValueTotal + letture [index];
//Anticipo pro il prossimo posizione nella matrice:
Indice = indice + 1;
//Se siamo alla feine della matrice...
Se (indice> = numReadings)
//. .. Wrap um all'inizio:
Indice = 0;
//Calcolare la media:
AnalogAverage = AnalogValueTotal/numReadings;
}
/*
Ogni tanto un po ", MCU leggere la temperatura da il DS18B20 e poi lasciare che il DS18B20 avviare il convertire.
Attenzione: la intervallo di tempo tra avviare il convertire e leggere la temperatura deve essere maggiore di 750 millisecondi, o la temperatura nicht & egrave; preciso!
*/
Se (millis ()-tempSampleTime> = tempSampleInterval)
{
TempSampleTime = millis ();
Temperatura = TempProcess (ReadTemperature);//leggere la temperatura attuale dal DS18B20
TempProcess (StartConvert);//dopo la lettura, avviare il convertire pro la prossima lettura
}
/*
Ogni tanto un po ", stampa le informazioni su il monitor seriale.
*/
Se (millis ()-printTime> = printInterval)
{
PrintTime = millis ();
AverageVoltage = AnalogAverage * (float) 5000/1024;
Serial. print ("il valore Analogico di:");
Serial. print (AnalogAverage);//analogico, in media, da 0 eine 1023
Serial. print ("Tensione:");
Serial. print (averageVoltage);//millivolt, in media, da 0mv pro 4995mV
Serial. print ("mV");
Serial. print ("temp:");
Serial. print (temperatura);//temperatura attuale
Serial. print ("^ C EC:");
Galleggiante TempCoefficient = 1,0 + 0,0185 * (temperatura-25.0);//formel di compensazione della temperatura: fFinalResult (25 ^ C) = fFinalResult (corrente) /(1,0 + 0,0185 * (fTP-25.0));
Galleggiante CoefficientVolatge = (float) averageVoltage/TempCoefficient;
Se (CoefficientVolatge <150) di Serie. println ("Nessuna soluzione! "); //25 ^ C 1413us/cm <-> circa 216mv se la tensione (tensione di compensazione) <150, che & egrave; <1 MS/cm, fuori della gamma
Altrimenti se (CoefficientVolatge> 3300) di Serie. println ("Fuori della gamma! ");//> 20 MS/cm, fuori della gamma
Altro
{
Se (CoefficientVolatge <= 448) ECcurrent = 6,84 * CoefficientVolatge-64.32; //1 MS/cm <EG <= 3 MS/cm
Altrimenti se (CoefficientVolatge <= 1457) ECcurrent = 6,98 * CoefficientVolatge-127; //3 MS/cm <EG <= 10 MS/cm
Altro ECcurrent = 5,3 * CoefficientVolatge + 2278; //10 MS/cm <EG <20 MS/cm
ECcurrent/= 1000;//convertire uns/cm pro MS/cm
Serial. print (ECcurrent, 2);//durch decimali
Serial. println ("ms/cm");
}
}
}
/*
Ch = 0, lasciare che il DS18B20 avviare il convertire; ch = 1, MCU leggere la temperatura attuale dal DS18B20.
*/
Galleggiante TempProcess (bool ch)
{
//ICH ritorni la temperatura da un DS18B20 in GRADI Celsius
Statica di dati byte [12];
Statica byte addr [8];
Statica galleggiante TemperatureSum;
Wenn (! Ch) {
Wenn (! Ds. suchen (addr)) {
Serial. println ("nicht pi & ugrave; sensori sulla catena-jacke, reset di ricerca! ");
Ds. reset_search ();
Di ritorno 0;
}
Se (OneWire:: crc8 (addr, 7)! = addr [7]) {
Serial. println ("CRC nicht & egrave; valido!");
Di ritorno 0;
}
Se (addr [0]! = 0x10 & & addr [0]! = 0x28) {
Serial. print ("Dispositivo nicht & egrave; riconosciuto!");
Di ritorno 0;
}
Ds. reset ();
Ds. selezionare (addr);
Ds. schreiben (0x44,1);//inizio di conversione, con potenza parassita su alla feine
}
Altro {
Regalo byte = ds. Reset ();
Ds. selezionare (addr);
Ds. schreiben (0xBE);//Leggere Appunti
Pro (int i = 0; i <9; i + +) {//abbiamo bisogno di 9 byte
Dati [ich] = ds. Lesen ();
}
Ds. reset_search ();
MSB = dati byte [1];
LSB = dati byte [0];
Galleggiante tempRead = ((MSB <<8) LSB);//con durch delle complimentarmi con
TemperatureSum = tempRead/16;
}
Di ritorno TemperatureSum;
}

Please read and follow the instructions in the "How to use this forum" post.

Const numReadings = 20 byte;//il numero del campione volte
Byte ECsensor Spille = A1;//Meter CE uscita analogica, Spille su analogico 1
Byte DS18B20 _ Spille = 2;//DS18B20 segnale, Spille su digitale 2
Unsigned int AnalogSampleInterval = 25, printInterval = 700, tempSampleInterval = 850;//analogico intervallo di campionamento; di serie di stampa intervallo; temperatura intervallo di campionamento
Unsigned int letture [numReadings];//le letture da il ingresso analogico
Indice di byte = 0;

Too many capital letters.

Indice = indice + 1;"Indice" is not the same as "indice".

It looks like someone set Google Translate loose on the original code...

someone set Google Translate loose

Maybe, but how do you do that with German and Italian at the same time?

Step 1: Have Google translate the sketch from Italian to English:

# Include <OneWire. h>


# Define StartConvert 0
# Define ReadTemperature 1


Const numReadings = 20 bytes; // the sample number times
Byte ECsensor Pins = A1; // Meter CE analogue output, Pins on analogue 1
Byte DS18B20 _ Brooches = 2; // DS18B20 signal, pins on digital 2
Unsigned int AnalogSampleInterval = 25, printInterval = 700, tempSampleInterval = 850; // analog sampling interval; standard print interval; sampling interval temperature
Unsigned int reads [numReadings]; // readings from the analog input
Byte index = 0; // the index of the current reading
Unsigned long AnalogValueTotal = 0; // the total running
Unsigned int AnalogAverage = 0, averageVoltage = 0; // the average
Unsigned long AnalogSampleTime, printTime, tempSampleTime;
Temperature float, ECcurrent;


// I / O chip temperature
OneWire ds (DS18B20 _ Spille); // on digital Spille 2


Void setup ()
{
  // Initialization of serial communication with the computer:
  Serial. begin (115200);
  // Initialize all readings for 0:
  For (thisReading byte = 0; thisReading <numReadings; thisReading + +)
  Readings [thisReading] = 0;
  TempProcess (StartConvert); // let the DS18B20 start converting
  AnalogSampleTime = millis ();
  PrintTime = millis ();
  TempSampleTime = millis ();
}


Void loop ()
{
  / *
    Every once in a while, from the sample the analog value and calculate the average.
  * /
  If (millis () - AnalogSampleTime> = AnalogSampleInterval)
  {
    AnalogSampleTime = millis ();
    // Subtract the last reading:
    AnalogValueTotal = AnalogValueTotal - readings [index];
    // Read from the sensor:
    Readings [index] = analogRead (ECsensorPin);
    // Add the reading for the total:
    AnalogValueTotal = AnalogValueTotal + readings [index];
    // Advance for the next position in the matrix:
    Index = index + 1;
    // If we are at the end of the matrix ...
    If (index> = numReadings)
    //. .. Wrap around at the beginning:
    Index = 0;
    // Calculate the average:
    AnalogAverage = AnalogValueTotal / numReadings;
  }
  / *
    Every once in a while, MCU read the temperature from the DS18B20 and then let the DS18B20 start the convert.
    Attention: The time interval between starting the conversion and reading the temperature must be greater than 750 milliseconds, or the temperature is not accurate!
  * /
  If (millis () - tempSampleTime> = tempSampleInterval)
  {
    TempSampleTime = millis ();
    Temperature = TempProcess (ReadTemperature); // read the current temperature from the DS18B20
    TempProcess (StartConvert); // after reading, start the convert for the next reading
  }
  / *
    Every once in a while, print the information on the serial monitor.
  * /
  If (millis () - printTime> = printInterval)
  {
    PrintTime = millis ();
    AverageVoltage = AnalogAverage * (float) 5000/1024;
    Serial. print ("the Analog value of:");
    Serial. print (AnalogAverage); // analogue, on average, from 0 to 1023
    Serial. print ("Voltage:");
    Serial. print (averageVoltage); // millivolts, on average, from 0mv to 4995mV
    Serial. print ("mV");
    Serial. print ("temp:");
    Serial. print (temperature); // current temperature
    Serial. print ("^ C EC:");


    Float TempCoefficient = 1.0 + 0.0185 * (temperature - 25.0); // temperature compensation formula: fFinalResult (25 ^ C) = fFinalResult (current) /(1.0 + 0.0185 * (fTP-25.0));
    Float CoefficientVolatge = (float) averageVoltage / TempCoefficient;
    If (Coefficient Volatge <150) Series println ("No solution!"); // 25 ^ C 1413us / cm <-> about 216mv if the voltage (compensation voltage) <150, which is <1 ms / cm, outside the range
    Otherwise if (CoefficientVolatge> 3300) Series. println ("Out of range!"); //> 20 ms / cm, outside the range
    Other
    {
      If (CoefficientVolatge <= 448) ECcurrent = 6.84 * CoefficientVolatge - 64.32; // 1 ms / cm <EC <= 3 ms / cm
      Otherwise if (CoefficientVolatge <= 1457) ECcurrent = 6.98 * CoefficientVolatge - 127; // 3 ms / cm <EC <= 10 ms / cm
      Other ECcurrent = 5.3 * CoefficientVolatge + 2278; // 10 ms / cm <EC <20 ms / cm
      ECcurrent / = 1000; // convert us / cm to MS / cm
      Serial. print (ECcurrent, 2); // two decimals
      Serial. println ("ms / cm");
    }
  }


}
/ *
  Ch = 0, let the DS18B20 start converting; ch = 1, MCU read the current temperature from the DS18B20.
* /
TempProcess float (bool ch)
{
  // I return the temperature from a DS18B20 in GRADES Celsius
  Data statics byte [12];
  Static byte addr [8];
  Static TemperatureSum float;
  If (! Ch)
  {
    If (! Ds. Search (addr))
    {
      Serial. println ("no more sensors on the chain, search reset!");
      Ds. reset_search ();
      Return 0;
    }
    If (OneWire :: crc8 (addr, 7)! = Addr [7])
    {
      Serial. println ("CRC is not valid!");
      Return 0;
    }
    If (addr [0]! = 0x10 & & addr [0]! = 0x28)
    {
      Serial. print ("Device is not recognized!");
      Return 0;
    }
    Ds. reset ();
    Ds. select (addr);
    Ds. write (0x44, 1); // start of conversion, with parasitic power on at the end
  }
  Other
  {
    Gift byte = ds. reset ();
    Ds. select (addr);
    Ds. write (0xBE); // Read Notes
    For (int i = 0; i <9; i + +) // we need 9 bytes
    {
      Data [i] = ds. read ();
    }
    Ds. reset_search ();
    MSB = byte data [1];
    LSB = byte data [0];
    Float tempRead = ((MSB << 8) LSB); // with two of the compliments
    TemperatureSum = tempRead / 16;
  }
  Return TemperatureSum;
}

Step 2: Fix the syntax errors caused by the translations:

#include <OneWire.h>
#define StartConvert 0
#define ReadTemperature 1


const byte numReadings = 20; // the sample number times
byte ECsensorPin = A1; // Meter CE analogue output, Pins on analogue 1
byte DS18B20Pin = 2; // DS18B20 signal, pins on digital 2
unsigned int AnalogSampleInterval = 25, // analog sampling interval;
             PrintInterval = 700,  // standard print interval; 
             TempSampleInterval = 850; // sampling interval temperature
unsigned int Readings[numReadings]; // readings from the analog input
byte Index = 0; // the Index of the current reading
unsigned long AnalogValueTotal = 0; // the total running
unsigned int AnalogAverage = 0,
             AverageVoltage = 0; // the average
unsigned long AnalogSampleTime,
         PrintTime,
         TempSampleTime;
float Temperature, ECcurrent;


// I / O chip temperature
OneWire ds(DS18B20Pin); // on digital pin 2


void setup ()
{
  // Initialization of serial communication with the computer:
  Serial. begin (115200);
  // Initialize all readings for 0:
  for (byte thisReading = 0; thisReading < numReadings; thisReading++)
    Readings [thisReading] = 0;
  TempProcess (StartConvert); // let the DS18B20 start converting
  AnalogSampleTime = millis ();
  PrintTime = millis ();
  TempSampleTime = millis ();
}


void loop ()
{
  /*
    Every once in a while, from the sample the analog value and calculate the average.
  */
  if (millis () - AnalogSampleTime >= AnalogSampleInterval)
  {
    AnalogSampleTime = millis ();
    // Subtract the last reading:
    AnalogValueTotal = AnalogValueTotal - Readings[Index];
    // Read from the sensor:
    Readings [Index] = analogRead (ECsensorPin);
    // Add the reading for the total:
    AnalogValueTotal = AnalogValueTotal + Readings[Index];
    // Advance for the next position in the matrix:
    Index = Index + 1;
    // if we are at the end of the matrix ...
    if (Index >= numReadings)
      //. .. Wrap around at the beginning:
      Index = 0;
    // Calculate the average:
    AnalogAverage = AnalogValueTotal / numReadings;
  }
  /*
    Every once in a while, MCU read the temperature from the DS18B20 and then let the DS18B20 start the convert.
    Attention: The time interval between starting the conversion and reading the temperature must be greater than 750 milliseconds, or the temperature is not accurate!
  */
  if (millis () - TempSampleTime >= TempSampleInterval)
  {
    TempSampleTime = millis ();
    Temperature = TempProcess (ReadTemperature); // read the current temperature from the DS18B20
    TempProcess (StartConvert); // after reading, start the convert for the next reading
  }
  /*
    Every once in a while, print the information on the serial monitor.
  */
  if (millis () - PrintTime >= PrintInterval)
  {
    PrintTime = millis ();
    AverageVoltage = AnalogAverage * (float) 5000 / 1024;
    Serial. print ("the Analog value of:");
    Serial. print (AnalogAverage); // analogue, on average, from 0 to 1023
    Serial. print ("Voltage:");
    Serial. print (AverageVoltage); // millivolts, on average, from 0mv to 4995mV
    Serial. print ("mV");
    Serial. print ("temp:");
    Serial. print (Temperature); // current temperature
    Serial. print ("^ C EC:");


    float TempCoefficient = 1.0 + 0.0185 * (Temperature - 25.0); // temperature compensation formula: fFinalResult (25 ^ C) = fFinalResult (current) /(1.0 + 0.0185 * (fTP-25.0));
    float CoefficientVolatge = (float) AverageVoltage / TempCoefficient;
    if (CoefficientVolatge < 150)
      Serial.println ("No solution!"); // 25 ^ C 1413us / cm <-> about 216mv if the voltage (compensation voltage) <150, which is <1 ms / cm, outside the range
    else if (CoefficientVolatge > 3300)
      Serial.println ("Out of range!"); //> 20 ms / cm, outside the range
    else
    {
      if (CoefficientVolatge <= 448) ECcurrent = 6.84 * CoefficientVolatge - 64.32; // 1 ms / cm <EC <= 3 ms / cm
      else if (CoefficientVolatge <= 1457) ECcurrent = 6.98 * CoefficientVolatge - 127; // 3 ms / cm <EC <= 10 ms / cm
      else ECcurrent = 5.3 * CoefficientVolatge + 2278; // 10 ms / cm <EC <20 ms / cm
      ECcurrent /= 1000; // convert us / cm to MS / cm
      Serial. print (ECcurrent, 2); // two decimals
      Serial. println ("ms / cm");
    }
  }


}


/*
  Ch = 0, let the DS18B20 start converting; ch = 1, MCU read the current temperature from the DS18B20.
*/
float TempProcess(bool ch)
{
  // I return the temperature from a DS18B20 in GRADES Celsius
  static byte data [12];
  static byte addr [8];
  static float temperatureSum;
  if (! ch)
  {
    if (! ds.search(addr))
    {
      Serial. println ("no more sensors on the chain, search reset!");
      ds.reset_search ();
      return 0;
    }
    if (OneWire::crc8(addr, 7) != addr[7])
    {
      Serial. println ("CRC is not valid!");
      return 0;
    }
    if (addr[0] != 0x10 && addr [0] != 0x28)
    {
      Serial. print ("Device is not recognized!");
      return 0;
    }
    ds.reset ();
    ds.select (addr);
    ds.write (0x44, 1); // start of conversion, with parasitic power on at the end
  }
  else
  {
    ds.reset();
    ds.select (addr);
    ds.write (0xBE); // Read Notes
    for (int i = 0; i < 9; i++) // we need 9 bytes
    {
      data[i] = ds.read();
    }
    ds.reset_search ();
    byte MSB = data[1];
    byte LSB = data[0];
    float tempRead = ((MSB << 8) | LSB); // with two of the compliments
    temperatureSum = tempRead / 16;
  }
  return temperatureSum;
}