Buona sera a tutti ho comperato questo prodotto : http://www.robotics-3d.com/component/virtuemart/analog-ph-meter-kit ma ho grandi problemi ha farli fare una lettura consona, ho seguito e provato a fare la calibrazione come descritto in wiki, quando lo provo lo sketch sia per calibrazione sia sw che hw riesco a mettere i dati giusti, ma appena ricarico il mio sketch mi da valori anomali: questo è il mio sketch:
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <PCF8574_HD44780_I2C.h>
#include <Time.h>
#include <DS3232RTC.h>
#include <RTClib.h>
#include <SPI.h>
#include <Ethernet.h>
int rele5 = 43; // pin a cui è connesso il LED
boolean acceso = false;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip( 192, 168, 1, 6 );
EthernetServer server(80);
PCF8574_HD44780_I2C lcd(0x3F, 20, 4);
long Pompa_Accesa_in_data=0;
const unsigned long quanto_tempo_deve_restare_accesa_la_pompa = 300000;
long inizio_accensione_arduino= 0;
unsigned long quanto_tempo_deve_restare_spento_skim_avvio_arduino = 300000;
int pompa_spenta =0;
int oraAlba = 9;
int minAlba = 10;
long albas;
int durataAlbas = 720;
int oraTramonto = 18;
int minTramonto = 10;
long tramontos;
int durataTramontos = 720;
long nows;
int delayR = 0;
int delayG = 120;
int delayB = 240;
int delayUV = 360;
int delayW = 360;
//LED
int pinR = 2;
int pinG = 3;
int pinB = 4;
int pinW = 5;
int pinUV = 6;
//RELE
float rele1 = 35;
float rele2 = 37;
int rele3 = 39;
int rele4 = 41;
int rele6 = 45;
int rele7 = 47;
int rele8 = 49;
const int buttonPin = 7;
const int but2 = 9;
int buttonState = 0;
int buttonState2 = 0;
//menu
/*int Menu=0; // VARIABILE CHE IDENTIFICA IL MENU' IN USO
const int buttonPingiu = 22; // pin Giu
const int buttonPinsu= 24; // pin Su
const int buttonPinok = 26; // pin OK
const int buttonPinPiu = 30; // pin modifica più
const int buttonPinMeno = 32; // pin modifica meno
int lastButtonokState = LOW; // the previous reading from the Enter input pin
int lastButtongiuState = LOW; // the previous reading from the Esc input pin
int lastButtonsuState = LOW; // the previous reading from the Left input pin
int lastButtonPiuState = LOW; //
int lastButtonMenoState = LOW; //
long lastEnterDebounceTime = 0; // the last time the output pin was toggled
long lastEscDebounceTime = 0; // the last time the output pin was toggled
long lastLeftDebounceTime = 0; // the last time the output pin was toggled
long lastRightDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 500; // the debounce time
//Variabili del menu
void menuUseEvent(MenuUseEvent used)
{
Serial.println("menuUseEvent found Dealy (D)");
}
void menuChangeEvent(MenuChangeEvent changed)
{
Serial.print("Menu change ");
Serial.print(changed.from.getName());
Serial.print(" ");
Serial.println(changed.to.getName());
}
// MENU' IMPOSTAZIONI
MenuItem menu1Item3 = MenuItem("Item3");
MenuItem menuData=MenuItem("Data/Ora");
MenuItem menuOra=MenuItem("Ora");
*/
char buffer1[20];
char buffer2[20];
//ALLARMI
float riscaldatore = 22.0; // allerta temperatura acqua bassa
float alertacqua = 27.0; // ventola tangenziale
float alertplafo = 45.0; // alerta plafoniera temperatura troppo alta
float tempSoglia = 38.0; //temperatura ventole plafo
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tmp_address;
float temp0=0;
float temp1=0;
int numberOfDevices;
#define SensorPin A0 //pH meter Analog output to Arduino Analog Input 0
#define Offset -1.30 //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex=0;
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
void setup() {
pinMode(rele1,OUTPUT);
pinMode(rele2, OUTPUT);
pinMode(rele3, OUTPUT);
pinMode(rele4,OUTPUT);
pinMode(rele5,OUTPUT);
pinMode(rele6,OUTPUT);
pinMode(rele7,OUTPUT);
pinMode(rele8,OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(but2, INPUT);
digitalWrite(rele1,LOW);
digitalWrite( rele2, LOW);
digitalWrite( rele3, HIGH );
digitalWrite(rele4, LOW);
digitalWrite(rele5,0);
digitalWrite(rele6, LOW);
digitalWrite(rele7, LOW);
digitalWrite(rele8, LOW);
/*
//BUTTON
pinMode(buttonPinMeno, INPUT);
pinMode(buttonPinPiu, INPUT);
pinMode(buttonPinok, INPUT);
pinMode(buttonPinsu, INPUT);
*/
Serial.begin(9600);
Wire.begin();
sensors.begin();
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
lcd.init(); // LCD Initialization
lcd.backlight( ); // Backlight ON
lcd.clear(); // Clear the display
numberOfDevices = 1;
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinW, OUTPUT);
pinMode(pinUV, OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println("Ready"); //Test the serial monitor
inizio_accensione_arduino= millis();
}
void loop()
{
if (millis() >= (quanto_tempo_deve_restare_spento_skim_avvio_arduino + inizio_accensione_arduino)) {
digitalWrite(rele3, LOW);
}
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue,voltage;
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPin);
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
pHValue = 7.0*voltage+Offset;
samplingTime=millis();
}
if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
Serial.print("Voltage:");
Serial.print(voltage,2);
Serial.print(" pH value: ");
Serial.println(pHValue,2);
digitalWrite(LED,digitalRead(LED)^1);
printTime=millis();
}
}
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
Serial.println("Error number for the array to avraging!/n");
return 0;
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Serial.print(" pH:");
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
lcd.setCursor(10,0);
lcd.println("PH");
lcd.setCursor( 13,0);
lcd.println(phValue);
// prendo ora attuale
DateTime now = RTC.get();
sprintf(buffer1, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
lcd.setCursor(0,0);
lcd.print( buffer1 );
sprintf(buffer2, "%02d/%02d/%d", now.day(), now.month(), now.year());
lcd.setCursor(0,1);
lcd.print( buffer2 );
Serial.println(buffer1);
Serial.println(buffer2);
// Richiesta temperatura
sensors.requestTemperatures(); // Comando per misurare la temp.
temp0 = sensors.getTempCByIndex(0);
lcd.setCursor(0,2); // Colonna 0, Riga 2
lcd.print("acqua:");
lcd.setCursor (6, 2);
lcd.print(temp0);
Serial.println(temp0);
temp1 = sensors.getTempCByIndex(1);
lcd.setCursor (0,3); //Colonna 0, Riga 3
lcd.print("plafo:");
lcd.setCursor (6,3);
lcd.print(temp1);
Serial.println(temp1);