Sunday, 28 October 2018

Sem 7 : week 6 & 7

Hai everyone..

i'm just want to highlight for both week for week 6 and week 7 .. i am going to meet Sir Zubir and we are disscusing about the coding for each sensor and compile all the three coding for three sensor.

There is the coding for 3 sensor which temperature, turbidity and the PH 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 output from the coding .


So, settle my task about the coding . Thanks to Sir Zubir because always help me in develop my project.

# next week is mid semester break .

No comments:

Post a Comment