Zelfbouw Arduinio Ph controller


nee er zat helemaal niks bij dus ales zelf moeten uitvogelen via het interet en zo.

Maar ik had zelf al een beetje een idee stel ik zou een code maken die uitgaat van de waarden die ik meet bij ph 7 en 4
zodat die daaruit verder gaat rekenen.
 
hallo Jan,

ik heb een soortgelijke pH probe, echter op mijn analoog printje zit maar 1 potmeter voor de gain instelling, de offset is een vaste weerstand blijkbaar.
Als je de probe van het printje afkoppelt en de ingang van het printje kortsluit, moet de offset nagenoeg pH waarde 7 aangeven, de afwijking corrigeer ik met de pH_offset waarde in het programma, maar bij jou zal dat met de extra offset potmeter moeten kunnen worden afgeregeld. De pH_offset waarde zou je dus op 0.00 moeten kunnen laten staan in je programma. Daarna hang je de probe weer aan het printje, hang de probe in een ref 7 pH zakje en moet je met de gain die waarde 7 kunnen afregelen, stop je de probe in een ref 4pH moet de waarde dus naar 4 gaan.De offset zou je niet meer aan hoeven draaien.
Het duurt wel een minuutje of 3 voordat de waarde zich stabiliseerd en vergeet niet de probe af te spoelen als je wisseld van referentie vloeistof. Ik dompel hem even in gedestileerd water.

Hierbij een voorbeeld van mijn controller programmatje.
De pH routine (float phvalue()) zit er ook in .

// Fisk Tank Controller by G.M.G.T. Seegers 2015 Version 3
// V3 contains capacitive sensor control for the LCD
// involved Libraries
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <CapacitiveSensor.h>
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>

#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args) write(args);
#else
#define printByte(args) print(args,BYTE);
#endif

// define clock parameter to rtc
RTC_DS1307 RTC;

//Special diplay characters defined
uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t smiley[8] = {0x0,0x0,0x1f,0x15,0x1f,0x11,0x1f};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t nocheck[8] = {0x0,0x1b,0xa,0x4,0xa,0x1b,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t arrowup[8] = {0x0,0x4,0xe,0x1f,0x4,0x4,0x4};
uint8_t arrowdown[8] = {0x0,0x4,0x4,0x4,0x1f,0xe,0x4};
uint8_t degree[8] = {0xc,0x12,0x12,0xc,0x0,0x0,0x0};

// set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27,20,4);

//Temperature probe definitions
int DS18S20_Pin = 2; //assign DS18S20 outup wire to digital input pin 2
OneWire ds(DS18S20_Pin); // Data collection temperature via OneWire on digital pin 2

//pH probe definitions
#define pH_Pin 0 //pH meter Analog output to Analog Input 0

// SSR pin definitions
#define relay_1 8 //TL lights lights reserved
#define relay_2 7 // Airpump reserved
#define co2_pump 11
#define heater 3
// level pin definition
#define level 4
//define LED test pin
#define Beeper 13
//define capacitive sensor pins
CapacitiveSensor Tlcd = CapacitiveSensor(10,12);

float Tset=24.5; //variable for Fishtank temperature
float Toffset=0.2; //variable to determine water temerature variation
float Tmin=30.0; //variable with overrated value for first lowest temp measurement
float Tmax=15.0; //variable with underrated value for first highest temp measurement
float Tlow_alarm=21.0; //variable for alarm when water temp is to low
float Thigh_alarm=27.0; //variable for alarm hen water temp is to high
int wlevel=0; // variable for waterlevel detection
float pH_offset=0.12; //offset for pH probe to get pH of 7.00

//Main Program initialization
void setup(void) {
Serial.begin(9600);
// initialize I2C bus
Wire.begin();
//initialize clock
RTC.begin();
//Synchromise Arduino internal clock with RTC
setSyncProvider(syncProvider); //reference our syncProvider function instead of RTC_DS1307::get()
RTC.now();
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(__DATE__, __TIME__));
// RTC.adjust(DateTime(2015, 12, 31, 14, 22, 0));

//Time when co2 pump switches ON and OFF
Alarm.alarmRepeat(9,0,0, CO_on); // 23:30 every day on
Alarm.alarmRepeat(23,0,0, CO_off); // 19:00 every day off
//Time when TL lights switches ON and OFF
Alarm.alarmRepeat(16,30,0, TL_on); // 16:30 every day on
Alarm.alarmRepeat(23,30,0, TL_off); // 23:30 every day off

//define relais pinmodes and initial states
pinMode (relay_1,OUTPUT);
pinMode (relay_2,OUTPUT);
digitalWrite (relay_1,LOW);
digitalWrite (relay_2,LOW);

//define solenoid pinmodes and intial states
pinMode (co2_pump,OUTPUT);
pinMode (heater,OUTPUT);
digitalWrite (co2_pump,LOW);
digitalWrite (heater,LOW);

//define level pinmode and state
pinMode (level,INPUT);

//define Test LED pinmode and initial state
pinMode (Beeper,OUTPUT);
digitalWrite (Beeper,LOW);

// Initialize the display
lcd.init();
lcd.backlight();
//assign special characters to var
lcd.createChar(0, bell);
lcd.createChar(1, smiley);
lcd.createChar(2, clock);
lcd.createChar(3, arrowdown);
lcd.createChar(4, arrowup);
lcd.createChar(5, check);
lcd.createChar(6, nocheck);
lcd.createChar(7, degree);
lcd.home();

// opening screen on power up
lcd.setCursor(0, 0);
for(int i = 0;i < 20; i++) lcd.printByte(1);
lcd.setCursor (0, 1);
lcd.print(" Fish Tank Control");
lcd.setCursor (0, 2);
lcd.print(" Guus Seegers");
lcd.setCursor(0, 3);
for(int i = 0;i < 20; i++) lcd.printByte(1);
delay (3000); //showtime
lcd.clear();
lcd.home();
// Build static part of display
// First display line watertmperature and clock
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.setCursor(9, 0);
lcd.printByte(7);
lcd.setCursor(10,0);
lcd.print("C ");
//second display line static values start here
lcd.setCursor(0,1);
lcd.print("T-:");
lcd.setCursor(7,1);
lcd.printByte(7);
lcd.print("C ");
lcd.print("T+:");
lcd.setCursor(18,1);
lcd.printByte(7);
lcd.print("C");
//third display line static values start here
lcd.setCursor(0, 2);
lcd.print("pH:");
lcd.setCursor(8,2);
lcd.print("O2:");
lcd.printByte(6); //remove when Relay1 gets a function
lcd.setCursor(14,2);
lcd.print("Lit:");
TL_on(); //On power up ilumination always on
//fourth display line static values start here
lcd.setCursor(0,3);
lcd.print("Htr:");
lcd.setCursor(7,3);
lcd.print("CO2:");
CO_on(); //On power-up turn CO2 pump always on
lcd.setCursor(14,3);
lcd.print("Lvl:");
Alarm.timerOnce(30,LCDlightoff); //display for 30 seconds before turning backlight off
}
// create a sync. provider variable and load with unixtime
time_t syncProvider() //this does the same thing as RTC_DS1307::get()
{
return RTC.now().unixtime();
}

// Main Program loop
void loop(void) {
digitalClockDisplay(); //prepare RTC time for displaying
Alarm.delay(1000); // wait one second between clock display

WaterLevel(); //check waterlevel

LCDSensor(); //call LCD sensor check

// dynamic display section, shows live measurement values
float temperature = getTemp(); //read result from getTemp subroutine
Serial.print("Water-temperatuur: "); //print temp value on serial monitor
Serial.println(temperature);
lcd.setCursor(5,0); //set display cursor on target col-5 row-1
lcd.print(temperature,1); //display temp value with only 1 decimal
// determine lowest temperature and put it on display
if (temperature <= Tmin) {
Tmin=temperature;
}
// determine highest temperature and put it on display
if (temperature >= Tmax) {
Tmax=temperature;
}
lcd.setCursor(3,1);
lcd.print(Tmin,1);
lcd.setCursor(14,1);
lcd.print(Tmax,1);

//heater control water temperature with hysteresis check
if (temperature <= (Tset-Toffset)) {
digitalWrite (heater,HIGH);
lcd.setCursor(4,3);
lcd.printByte(5);
}
if (temperature >= Tset) {
digitalWrite (heater,LOW);
lcd.setCursor(4,3);
lcd.printByte(6);
}
// water alarm checks
if (temperature<=Tlow_alarm) {
Alarmloop();
Serial.println ("Watertemp is too low !");
}
if (temperature>=Thigh_alarm) {
Alarmloop();
Serial.println("Watertemp is too high");
}

//Subroutines from here

float pH=getpH(); //read result from pH subroutine getpH
Serial.print("pH-waarde: "); //print pH value on serial monitor
Serial.println(pH);
lcd.setCursor(3,2); // set display cursor on target col-15 row-1
// avoid display overflow by limiting a max of 3 characters and a decimal point as value
if( (pH > 10.00)&&(pH <= 14.00)){
lcd.print(pH,1); // display pH value with 1 decimal
} else
if (pH > 14.00) {
lcd.print ("n/c ");
} else
{lcd.print(pH,2); // display pH value with 2 decimals
}
delay(1000); //delay between temperature and pH measurements in msec

}

//Temperature probe subroutine section - measurement reading and conversion
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
// put value in getTemp() variable
return TemperatureSum;
}

//pH probe subroutine section - measurement and conversion
float getpH(){
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;

for (int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf=analogRead(pH_Pin);
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>buf[j])
{
temp=buf;
buf=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf;
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue+pH_offset; //convert the millivolt into pH value

// put value in getpH() variable
return phValue;
}
void digitalClockDisplay()
{
// display date and time
// DateTime now = RTC.now();
lcd.setCursor(14,0);
lcd.printByte(2);
lcd.setCursor(15,0);
print2digits(hour());
lcd.print(":");
print2digits(minute());
//Serial time check
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void print2digits(int number) {
// Subroutine for Output leading zero date and time format LCD
if (number >= 0 && number < 10) {
lcd.write ('0');
}
lcd.print(number);
}
// Subroutine for Output leading zero date and time format Serial Monitor
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
// Subroutine to turn CO2 pump on
void CO_on(){
digitalWrite (co2_pump,HIGH);
lcd.setCursor(11,3);
lcd.printByte(5);
Serial.println("CO2 pump is on");
}
//Subroutine to turn CO2 pump off
void CO_off(){
digitalWrite (co2_pump,LOW);
lcd.setCursor(11,3);
lcd.printByte(6);
Serial.println("CO2 pump is off");
}

//Subroutine for waterlevel check
void WaterLevel(){
int wlevel=digitalRead (level);
if (wlevel==1) {
lcd.setCursor(18,3);
lcd.printByte(5);
Serial.println ("Waterlevel is OK");
}
else {
lcd.setCursor(18,3);
lcd.printByte(6);
Serial.println("Waterlevel is too low"); }
}

//Subroutine for LCD touchsensor
void LCDSensor() {
long start = millis();
long total = Tlcd.capacitiveSensor(30);
//Serial.print(millis() - start); // check on performance in milliseconds
//Serial.print("\t"); // tab character for debug window spacing
Serial.println(total); // print sensor output sensitivity

if (total > 5000) {
lcd.backlight(); //turn LCD backlight on for 60 seconds
Alarm.timerOnce (60,LCDlightoff);}
}

//Subroutine for TL lights are on
void TL_on(){
digitalWrite (relay_1,HIGH);
lcd.setCursor(18,2);
lcd.printByte(5);
Serial.println("Lights are on");
}
//Subroutine for TL lights are off
void TL_off(){
digitalWrite (relay_1,LOW);
lcd.setCursor(18,2);
lcd.printByte(6);
Serial.println("Lights are off");
}
//Subroutine for beeper alarm
void Alarmloop() {
digitalWrite(Beeper,HIGH);
delay (1000);
digitalWrite(Beeper,LOW);
}

//Subroutine to turn LCD-backlight off
void LCDlightoff() {
lcd.noBacklight();
}
//end of void loops



Hopelijk heb je er iets aan.

mvg
Guus
 
Ik heb ook even naar je eerste foto gekeken, daar waar het pH probe print op zit.
Linksboven zit een zwart halfrond blokje met 3 pootjes (transistorachtige component) , die zit bij mij als optie op het printje, dus niet gemonteerd. Dit is bij mij voor de een temperatuur sensor op het printje erbij tye plakken, type DS18S40 of zoiets (kijk even wat erop staat...). Het zou dus kunnen zijn dat 1 van de instelmogelijkheden is om de temperatuur te calibreren en de andere de gain voor de pH probe. De gain afstelling van de pH probe zit naast de zilverkleurige connector waar je de probe aan bevestigd, die link ernaast zou dan voor de temperatuursensor zijn. Je zou dan uitkomen op dezelfde calibratie methode voor de pH probe zoals ik die heb uitgevoerd, beschreven in vorig bericht.

gr
Guus
 
oke ik zal wel eens kijken of er zoon temperatuur sensor op zit
en wat bedoel je met kortsluiten welke moet ik dan aan elkaar monteren?
 
hoi Jan,

inderdaad, de plug van de pH probe op het printje.
Ik gebruik altijd even een metalen pincet, waarvan ik 1 poot in dat middelste gaatje stop en de andere op de omhulling van de plug. De ph waarde moet dan in de buurt van 7 komen, ongeacht of je aan een afstelschroefje (=potentiometer)draait.
Als je nu bijvoorbeeld 6.90 als waarde uit het programma ziet komen, dan is de waarde voor je pH-offset in het programma :
7.0-6.9= 0.1
Dus vul je 0.1 in achter die variabele. Hiermee corrigeer je de pH waarde afwijking van de componenten van het printje en komt er mooi een pH 7 uit het programma als je de plug dus kortsluit.
Vervolgens haal je de kortsluiting weg en prik je de pH probe erop. Steek die in een referentie oplossing bijvoorbeeld pH7 of pH 4 en regel met het afstelpunt (direct naast de pH probe plug) de pH zo af dat de waarde wat het meetprogramma geeft, overeenkomt met de waarde van de referentie vloeistof.
Neem daar de tijd voor, want het duurt even voordat de waarde stabiliseerd (minuutje of 3).

gr
Guus
 
Sorry maar dat heeft niet geholpen.

Maar ik ben zelf weer een stukje verder gekomen aan de hand van dit topic
http://arduino.stackexchange.com/questi ... sor-module

Nu is de code als volgd:
/*
The setup function runs once when you press reset or power the board
int CO2Klep =4;
int LED = 7;
int PhElec = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
int Phwaarde = 0;
int Phscherm = 0;
int Phinstpod = 1;
int Phinst = 0;
int Phinstscherm = 0;
const byte pHpin = A2; // Connect the sensor's Po output to analogue pin 0.

float Po;
float a=.0294; // 7 = 495 4 = 393 a=3/(495-393).
float b=-7.553; // b=7-(r1*a) .

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup() {
// initialize digital pin 13 as an output.
pinMode(CO2Klep, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("GemetPh");
lcd.setCursor(0, 1);
lcd.print("inPh");

}
// the loop function runs over and over again forever
void loop() {
{
Po = (1023 - analogRead(pHpin)) ;
Serial.print("Raw: ");
Serial.print(Po, 2); // Print the result in the serial monitor.
Serial.print(", ph =");
Po=Po*a+b;
Serial.println(Po, 2); // print ph
delay(1000); // Take 1 reading per second.
}
Phscherm = map(Phwaarde, 0, 1023, 0, 14);

Phwaarde = analogRead(PhElec); // read the input pin

Serial.println(Phscherm); // print as an ASCII-encoded decimal
Phinstscherm = map (Phinst, 0, 1023, 0,14);
Phinst = analogRead (Phinstpod);
lcd.setCursor(9, 1);
lcd.print(Phinstscherm);
Serial.println(Phinst);

{


lcd.setCursor(9, 0);
lcd.print(Po);
lcd.print(" ");
if(Po < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (Po > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}
}

}
/*
if(pHValue < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (pHValue > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}*/

verder komt er nog een 4x5 keyboard bij
en nog een temperatuur sensor
 
ik ben op een probleem gestuit, ik wil mijn lcd scherm volgens 3 wire aansluiten. Maar nu werkt het niet.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
lcd.begin (16,2); // <<----- My LCD was 16x2


// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

lcd.print("SainSmartI2C16x2");
}

void loop()
{
// Backlight on/off every 3 seconds
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print(n++,DEC);
lcd.setBacklight(LOW); // Backlight off
delay(3000);
lcd.setBacklight(HIGH); // Backlight on
delay(3000);
}

Als ik deze alleen gebruik dan doet hij het wel en als ik hem dan de delen die ik nodig heb i mijn code zet dan doet hij het niet.

Hier de code
// the setup function runs once when you press reset or power the board
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);



int CO2Klep =4;
int LED = 7;
int PhElec = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
int Phwaarde = 0;
int Phscherm = 0;
int Phinstpod = 1;
int Phinst = 0;
int Phinstscherm = 0;
const byte pHpin = A2; // Connect the sensor's Po output to analogue pin 0.

float Po;
float a=.0294; // 7 = 495 4 = 393 a=3/(495-393).
float b=-7.553; // b=7-(r1*a) .


void setup() {
// initialize digital pin 13 as an output.
pinMode(CO2Klep, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
/*lcd.setCursor(0, 0);*/
lcd.home ();
lcd.print("GemetPh");
lcd.setCursor(0, 1);
lcd.print("inPh");

}
// the loop function runs over and over again forever
void loop() {
{
Po = (1023 - analogRead(pHpin)) ;
Serial.print("Raw: ");
Serial.print(Po, 2); // Print the result in the serial monitor.
Serial.print(", ph =");
Po=Po*a+b;
Serial.println(Po, 2); // print ph
delay(1000); // Take 1 reading per second.
}
Phscherm = map(Phwaarde, 0, 1023, 0, 14);

Phwaarde = analogRead(PhElec); // read the input pin

Serial.println(Phscherm); // print as an ASCII-encoded decimal
Phinstscherm = map (Phinst, 0, 1023, 0,14);
Phinst = analogRead (Phinstpod);
lcd.setCursor(9, 1);
lcd.print(Phinstscherm);
Serial.println(Phinst);

{


lcd.setCursor(9, 0);
lcd.print(Po);
lcd.print(" ");
if(Po < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (Po > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}
}

}
/*
if(pHValue < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (pHValue > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}*/
 
Mooi projectje om te volgen.

Ik met een soortgelijk project bezig voor mijn tuinkasje.
In plaats van een LCD gebruik ik een Raspberry A+ als webservertje die ik dan kan benaderen via m'n laptop of telefoon. Ik kan 'm ook via de router naar buiten beschikbaar maken zodat ik bijvoorbeeld vanaf mijn werk kan kijken wat de temperaturen en vochtigheid is.
Projectje heb ik op GitHub: https://github.com/SmartDuck/MijnTuinkas
pH moet ik nog ontwikkelen ik gebruik hier een pH meter voor die je in de aarde moet steken.
https://github.com/SmartDuck/MijnTuinka ... dleidingen
 
Jou projectje ziet er ook leuk uit.

Ik ben zelf ook weer een heel erg stuk verder gekomen (eigenlijk is alle hardware zo goed als af)
Al als ik hem via een raspberry pi of zo zou willen sturen moet ik eerst eens gaan kijken voor een i2c om mijn toetsenbord aan te kunnen sturen want deze neemt nu best veel pennetjes in beslag. Dus denk dat ik het eerst zo maar laat kwa hardware.

Hier de code tot nu toe:
// the setup function runs once when you press reset or power the board
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>

#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

#include <Keypad.h>

const byte ROWS = 5; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'A','B','#','*'},
{'1','2','3', 'C'},
{'4','5','6', 'D'},
{'7','8','9', 'E'},
{'L','0','R' , 'R'}
};
byte rowPins[ROWS] = {12, 11, 10, 9, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


int CO2Klep =2;
int LED = 3;
int PhElec = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
int Phwaarde = 0;
int Phscherm = 0;
int Phinstpod = 1;
int Phinst = 0;
int Phinstscherm = 0;
const byte pHpin = A2; // Connect the sensor's Po output to analogue pin 0.

float Po;
float a=.0294; // 7 = 495 4 = 393 a=3/(495-393).
float b=-7.553; // b=7-(r1*a) .
String msg = "";

OneWire ds(13); // on pin 2 (a 4.7K resistor is necessary)

void setup() {
// initialize digital pin 13 as an output.
pinMode(CO2Klep, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
/*lcd.setCursor(0, 0);*/
lcd.home ();
lcd.print("GemetPh");
lcd.setCursor(0, 1);
lcd.print("Temp");

kpd.setDebounceTime(1);
unsigned long loopCount = 0;
String msg = "";

}
// the loop function runs over and over again forever
void loop() {
//{
Po = (1023 - analogRead(pHpin)) ;
Serial.print("Raw: ");
Serial.print(Po, 2); // Print the result in the serial monitor.
Serial.print(", ph =");
Po=Po*a+b;
Serial.println(Po, 2); // print ph
delay(1000); // Take 1 reading per second.
//}
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}

Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr, HEX);
}

if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44); // start conversion, use ds.write(0x44,1) with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
Serial.print(data, HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();

// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");

Phscherm = map(Phwaarde, 0, 1023, 0, 14);

Phwaarde = analogRead(PhElec); // read the input pin

Serial.println(Phscherm); // print as an ASCII-encoded decimal
Phinstscherm = map (Phinst, 0, 1023, 0,14);
Phinst = analogRead (Phinstpod);
lcd.setCursor(9, 1);
lcd.print(celsius);
Serial.println(Phinst);

{


lcd.setCursor(9, 0);
lcd.print(Po);
lcd.print(" ");
if(Po < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (Po > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}
} if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key.stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key.kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key.kchar);
Serial.println(msg);
}
}
}

}
/*
if(pHValue < 100){
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

}
if (pHValue > 105){
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
// wait for a second
}*/





873855jan_fokke_0_85_apri.jpg
 
Nu nog bezig met een menutje waar ik de parameters van temperatuur en ph kan veranderen. En mischien nog iets waar ik hem automatisch kan calibreren de ph meter.
 
918363jan_fokke_0_85_aquariu.jpg



Dit is een beetje hoe ik het in gedachte heb maar nu moet ik het nog in een werkende code krijgen.
Kan iemand me daar mischien een beetje bij opweg helpen.
 
Goed idee van je.
Zou je willen helpen. Keypads is nieuw voor me daar zal ik me eerst in moeten verdiepen.
 
oke ik ga zelf ook gewoon wat prutsen
Het is voor mij ook allemaal zeer basic wat ik er vanaf weet en door gewoon te googlen en te proberen ben ik tot zo ver gekomen
 
Hallo Jan,

Heb je inmiddels al fatsoenlijke waardes uit je PH sensor kunnen krijgen?
 
ja ik heb met de code die ik nu gebruik hele mooie waarden er uit kunnen krijgen
 
ik vroeg me af hoe ver je gekomen bent, wil in de zomer vakantie misschien dit ook gaan proberen
 
Opzich werkt alles al maar ik ben nu nog bezig met het menu gebeuren om alle waarden te kunnen aanpassen via het keyboard
 
Dag Jan,

Hoe is het eigenlijk met je Arduino activiteiten afgelopen? Ik vraag dit om dat dit topic kennelijk nogal abrupt is geëindigd?
Zelf heb ik ook een Arduino aquariumcomputer gebouwd die mijn verlichting, temperatuur en PH regelt. Verder heb ik een Arduino doseersysteem gemaakt.
 

Terug
Bovenaan