万博网页版登陆页派论坛

QQ登录

只需一步,快速开始

查看: 43|回复: 0
收起左侧

arduino测试

[复制链接]
发表于 2024-10-22 07:16:17 | 显示全部楼层 |阅读模式
//#include <LiquidCrystal.h>

#include <EEPROM.h>


//The time between each EEPROM write function call in ms
#define SAMPLE_TIME 2000  


const int analogInPin = A0;
int sensorValue = 0;
int sensorValue1 = 0;
const int turbPin=A1;
unsigned long int avgValue;
float b;
int buf[10],temp;
float min = 1000000000000;
float max = 0;
boolean varSet = false;
float volt;
float ntu;

void setup(void) {
Serial.begin(9600);
Serial.print(" pH, ");
Serial.print("  Max, ");
Serial.print("  Min, ");
Serial.print("  Avg, ");
Serial.println("  Turbidity");
}

void loop(void) {
   for(int i=0;i<10;i++)
{

  buf[i]=analogRead(analogInPin);

  delay(100);
}
for(int i=0;i<9;i++)
{
  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;
float pHAverage = 0;

for(int i=2;i<8;i++)
avgValue+=buf[i];
float pHVol=(float)avgValue*5.0/1024/6;
float pHValue = -5.70 * pHVol + 24.34;

pHAverage += pHValue;

if(min > pHValue){
    min = pHValue;
}
if(max < pHValue){
    max = pHValue;
}

/*Serial.print("pH ");
Serial.print("Maximum pH");
Serial.print("Minimum pH");
Serial.println("Average pH");*/

Serial.print(pHValue);
Serial.print(", ");

//print max and min pH levels overall
//Serial.print("Highest pH = ");
Serial.print(max);
Serial.print(", ");
//Serial.print("Lowest pH = ");
Serial.print(min);
Serial.print(", ");

//prints the average pH
//Serial.print("Average pH: ");
Serial.print(pHAverage);
Serial.print(", ");

//message to interpret pH level
//if(pHAverage > 4 && pHAverage < 9) {
  //Serial.println("Water levels are normal!");}
//else if (pHAverage <= 4) {
  //Serial.println("Water is too acidic!");
  //}
//else if (pHAverage >= 9) {
  //Serial.println("Water is too basic!");
  //}
delay(3000);

float sensorValue1 = analogRead(turbPin);




    /*volt = 0;
    ntu = 0;
    for(int i=0; i<800; i++)
    {
        volt += ((float)analogRead(turbPin)/1023)*5;
    }
    volt = volt/800;
    volt = round_to_dp(volt,1);
    volt = 4;
    if(volt < 2.5){
      ntu = 3000;
    }else{
      ntu = -1120.4*square(volt)+5742.3*volt-4353.8;
    }*/



//Serial.print("Turbidity: ");
Serial.println(sensorValue1 / 500);

//Serial.println();

delay (3000);


}//end loop

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;
}




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|万博网页版登陆页派论坛 ( 粤ICP备15075382号-1  

GMT+8, 2024-11-14 06:17 , Processed in 1.125000 second(s), 24 queries , Gzip On.

Powered by Shumeipai.net! X3.2

© 2001-2015 万博网页版登陆页派论坛安全联盟

快速回复 返回顶部 返回列表