Week 0

Cardboard Modelling

Click the images to enlarge the pictures and find out more about our design process.

Key findings of cardboard model:

  • The model allowed us to better visualise the dimensions required of our project – dimensions can be seen upon clicking on the pictures.
  • There is a need for the user to be able to dismantle and remove either the clean tank or waste water tank.
    • To facilitate this we prototype a housing to contain the 2 tanks which includes a flap and a hub. The intended aim is to provide the user with a means to easily remove the sensors and pumps from the tank without the need of unplugging them. This should be done solely by lifting the flap upwards.

Sensor code

Code for pH Sensor:

 

#include<Wire.h>

#include <LiquidCrystal_I2C.h>

#include <Adafruit_GFX.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define SensorPin 0 // the pH meter Analog output is connected with the Arduino’s Analog

unsigned long int avgValue; //Store the average value of the sensor feedback

float b;

int buf[10],temp;

void setup()

{

pinMode(13,OUTPUT);

lcd.init();

lcd.backlight();

}

void loop()

{

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;

}

}

}

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 lcd.setCursor(0, 0);

lcd.print(“pH Val:”);

lcd.setCursor(8, 0);

lcd.print(phValue);

delay(500);

digitalWrite(13, HIGH); 

delay(300);

digitalWrite(13, LOW);

}

Code for TDS Sensor:

#include<Wire.h>

#include <LiquidCrystal_I2C.h>

#define TdsSensorPin A1

#define VREF 5.0 // analog reference voltage(Volt) of the ADC

#define SCOUNT 30 // sum of sample point

int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC

int analogBufferTemp[SCOUNT];

int analogBufferIndex = 0 , copyIndex = 0;

float averageVoltage = 0, tdsValue = 0, temperature = 25;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()

{

Serial.begin(115200);

pinMode(13,OUTPUT);

lcd.init();

lcd.backlight();

pinMode(TdsSensorPin,INPUT);

}

void loop()

{

static unsigned long analogSampleTimepoint = millis();

if(millis()-analogSampleTimepoint > 40U) //every 40 milliseconds,read the analog value from the ADC

{

analogSampleTimepoint = millis();

analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the buffer

analogBufferIndex++;

if(analogBufferIndex == SCOUNT)

{

analogBufferIndex = 0;

}

}

static unsigned long printTimepoint = millis();

if(millis()-printTimepoint > 800U)

{

printTimepoint = millis();

for(copyIndex=0;copyIndex<SCOUNT;copyIndex++)

{

analogBufferTemp[copyIndex]= analogBuffer[copyIndex];

averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)VREF / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value float

compensationCoefficient=1.0+0.02*(temperature-25.0); //temperature compensation formula:

fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));

float compensationVolatge=averageVoltage/compensationCoefficient; //temperature compensation

tdsValue=(133.42*compensationVolatge*compensationVolatge*compensationVolatge – 255.86*compensationVolatge*compensationVolatge + 857.39*compensationVolatge)*0.5; //convert voltage value to tds value

lcd.setCursor(0, 0);

lcd.print(“TDS:”);

lcd.setCursor(0, 1);

lcd.print(tdsValue,0);

lcd.setCursor(10, 1);

lcd.println(“ppm”);

}

 

}

int getMedianNum(int bArray[], int iFilterLen)

{

int bTab[iFilterLen];

for (byte i = 0; i<iFilterLen; i++)

{

bTab[i] = bArray[i];

int i, j, bTemp;

for (j = 0; j < iFilterLen – 1; j++)

{

for (i = 0; i < iFilterLen – j – 1; i++)

{

if (bTab[i] > bTab[i + 1])

{

bTemp = bTab[i]; bTab[i] = bTab[i + 1];

bTab[i + 1] = bTemp;

}

}

}

if ((iFilterLen & 1) > 0)

{

bTemp = bTab[(iFilterLen – 1) / 2];

}

else

bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 – 1]) / 2; return bTemp;

}

No Comments

Post a Comment