Hey everyone!
Here are the codes we used for our prototypes:
Turbidity Meter
[code]
/*
Displays text sent over the serial port (e.g. from the Serial Monitor) on
an attached LCD.
YWROBOT
Compatible with the Arduino IDE 1.0
Library version:1.1
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int sensorPin = A0;
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
float sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
float turbidity = map(sensorValue, 0, 640, 100, 0);
delay(100);
lcd.setCursor(0, 0);
lcd.print("Turbidity:");
lcd.print(turbidity);
lcd.setCursor(10, 0);
delay(100);
if (turbidity < 15)
{
lcd.setCursor(0, 1);
lcd.print(" CLEAR ");
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if ((turbidity > 15) && (turbidity < 25))
{
lcd.setCursor(0, 1);
lcd.print(" FAIRLY TURBID ");
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
else if ((turbidity > 25) && (turbidity < 35))
{
lcd.setCursor(0, 1);
lcd.print(" RATHER TURBID ");
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
else if ((turbidity > 34) && (turbidity < 50))
{
lcd.setCursor(0, 1);
lcd.print(" TURBID ");
digitalWrite(2, LOW);
digitalWrite(3, HIGH) ;
digitalWrite(4, HIGH);
}
else
{
lcd.setCursor(0, 1);
lcd.print(" VERY TURBID ");
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
}
}
[/code]
pH Meter
[code]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
float calibration_value = 21.34;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10],temp;
float ph_act;
// for the OLED display
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
void setup()
{
Wire.begin();
Serial.begin(9600);
lcd.init();
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" pH Meter ");
lcd.setCursor(0, 1);
lcd.print(" pH Meter ");
delay(2000);
lcd.clear();
}
void loop() {
for(int i=0;i<10;i++)
{
buffer_arr[i]=analogRead(A0);
delay(30);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buffer_arr[i]>buffer_arr[j])
{
temp=buffer_arr[i];
buffer_arr[i]=buffer_arr[j];
buffer_arr[j]=temp;
}
}
}
avgval=0;
for(int i=2;i<8;i++)
avgval+=buffer_arr[i];
float volt=(float)avgval*5.0/1024/6;
float ph_act = (-5.70 * volt + calibration_value) + 10.8;
lcd.setCursor(0, 0);
lcd.print("pH Val:");
lcd.setCursor(8, 0);
lcd.print(ph_act);
delay(1000);
if ((ph_act) < 7)
{
lcd.setCursor(0, 1);
lcd.print(" ACIDIC ");
}
else if ((ph_act) = 7)
{
lcd.setCursor(0, 1);
lcd.print(" NEUTRAL ");
}
else if ((ph_act) > 7)
{
lcd.setCursor(0, 1);
lcd.print(" ALKALINE ");
}
}
[/code]