Salam and hai everyone.. Thank you because you all still follow my progress FYP project .
Hmm.. This week are to busy for me..i have the quiz and the lab that need to complete on time. However, i try to look my progress FYP project .
In this week , my task is compile the coding for three sensor which is temperature,turbidity and the temperature . Alhamdulila.. thank you to my SV Sir Zubir because sir are helping me a lot to compile all three coding . At the same time, i learned the function of each part in this coding .
**** This is my coding for three sensor *******
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 5
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;
// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress insideThermometer = { 0x28, 0xFF, 0xA7, 0x03, 0x81, 0x17, 0x05, 0xD6 };
int sensorPin = A0;
float volt;
float ntu;
//////////////////////////////////////////////
#define SensorPin A1 //pH meter Analog output to Arduino Analog Input 0
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
float phValue;
///////////////////////////////////////////////
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println("Ready");
sensors.begin();
//lcd.begin();
// Turn on the blacklight and print a message.
//lcd.backlight();
}
void loop() {
turbidity();
ph_sensor();
temp_A();
delay(500);
}
void turbidity()
{
int sensorValue = analogRead(A0);// read the input on analog pin 0:
float voltage = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
Serial.println(voltage); // print out the value you read:
}
void ph_sensor(){
for(int i=0;i<10;i++){ //Get 10 sample value from the sensor for smooth the value
buf[i]=analogRead(A1);
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;
}
}
}
//Serial.println(temp);
avgValue=0;
for(int i=2;i<8;i++) avgValue+=buf[i]; //take the average value of 6 center sampl
avgValue=avgValue/6;
Serial.print("Average Analog Reading: ");
Serial.println(avgValue);
float VoltageValue=(float)avgValue*5.0/1024; //convert the analog into volt
Serial.print("Input Voltage:");
Serial.println(VoltageValue);
// float phValue;
phValue=(VoltageValue-3.77)/-0.1698;
Serial.print(" pH:");
Serial.print(phValue,2);
Serial.println(" ");
}
float round_to_dp( float in_value, int decimal_place )
{
float multiplier = powf( 10.0f, decimal_place );
in_value = roundf( in_value * multiplier ) / multiplier;
return in_value;
}
void temp_A()
{
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
}
The next task is.... develop an IOT ..
see you next week ..

No comments:
Post a Comment