Design Thinking 4번째: 프로토

by 유수엽 | 2018-08-16 15:21
배수펌프 아두이노

재료

  • 펌프달린 분무기 1개
  • 아두이노 모터 드라이버 1개
  • 릴레이 1개

만들기 -

하드웨어 - 흠 회로도 되로 만듬. 

소프트웨어 - +/- 인가 될때만다 전압이 약간 달라서 

두가지 별도로 처리함. 

소프트웨어 전체 라인 130라인도 안됨


=====================코드===================================

/* water level detector and motor/Pump driver

   when detect it will run for 3 minute

   and rest 30 second

   and doing againg

*/


#define SensorPlus   3

#define SensorMinus  4

#define MotorOut     5

#define SenseLevel   A0


unsigned long TimeOld;

unsigned long TimeNow;

float LPFZ1P;

float LPFZ1M;

unsigned long Time500m;


unsigned int Mode0Time;

unsigned int Mode1Time;

byte         Mode;


enum sysMode { idle, RunPump};


bool SensorPolar;


int SensorRead;

float sensorVolt, sensorVolt0, sensorVolt1;

int WaterVolt0, WaterVolt1;

float lpfSensorout0, lpfSensorout1 ;


float ZL0, ZL1;


void setup() {

  Serial.begin(38400);

  Serial.println("airconn sensor for Arduino");

  pinMode(SensorPlus, OUTPUT);

  pinMode(SensorMinus, OUTPUT);

  pinMode(MotorOut, OUTPUT);

  pinMode(LED_BUILTIN, OUTPUT);

  TimeOld = TimeNow = millis();

  SensorPolar = 0;

  SwitchPolar();


  Mode = idle;

}


void loop() {

  TimeNow = millis();


  //every 200m Sec READ sensor and Calcurate sensor

  if ((TimeNow - Time500m) > 200) {  //test 2 second

    int SensorIntVolt = analogRead(SenseLevel);


    if (SensorPolar == 0) {

      WaterVolt0 = SensorIntVolt;

      sensorVolt0 = (float)WaterVolt0 * 0.005;

      lpfSensorout0 = 0.1 * ZL0;

      ZL0 += sensorVolt0 - lpfSensorout0;

      SensorPolar = 1;

    } else {

      //if (SensorPolar == 0) {

      WaterVolt1 = 1010 - SensorIntVolt;

      sensorVolt1 = (float)WaterVolt1 * 0.005;

      lpfSensorout1 = 0.1 * ZL1;

      ZL1 += sensorVolt1 - lpfSensorout1;

      SensorPolar = 0;

    }


    SwitchPolar();

    Time500m = TimeNow;

    /*

        Serial.print("Mode ");  Serial.print(Mode); Serial.print(":\t");

        Serial.print("SensorPolar ");  Serial.print(SensorPolar); Serial.print(":\t");

        Serial.print("AnalogInput ");  Serial.print(WaterVolt0); Serial.print(":\t");

        Serial.print(WaterVolt1); Serial.print(":\t");

        Serial.print("sensorVolt ");  Serial.print(sensorVolt0); Serial.print(":\t");

        Serial.print(sensorVolt1);

        Serial.println(":\t");

    */

    if (lpfSensorout0 < lpfSensorout1) sensorVolt = lpfSensorout1;

    if (lpfSensorout0 > lpfSensorout1) sensorVolt = lpfSensorout0;

    //Serial.print("sensorVolt ");  Serial.print(sensorVolt);

    //Serial.println(":\t");

  }


  if ((sensorVolt > 2.0)  && (Mode0Time > 60) && (Mode == idle))

  {

    digitalWrite(MotorOut, HIGH);

    digitalWrite(LED_BUILTIN, LOW);

    Mode = RunPump;

  }

  if ((Mode1Time > 180) && (Mode == RunPump))

  {

    digitalWrite(LED_BUILTIN, HIGH);

    digitalWrite(MotorOut, LOW);

    Mode = idle;

  }


  if ((TimeNow - TimeOld) >  1000) {

    TimeOld = TimeNow;

    if (Mode == idle) {

      Mode1Time = 0;

      Mode0Time++;

      if (Mode0Time > 3000) Mode0Time = 3000;

    } else {

      Mode0Time = 0;

      Mode1Time++;

      if (Mode1Time > 3000) Mode1Time = 3000;

    }

    Serial.print("Mode ");  Serial.print(Mode);

    Serial.print(":\t");

    Serial.print("Mode0Time ");  Serial.print(Mode0Time);

    Serial.print(":\t");

    Serial.print("Mode1Time ");  Serial.print(Mode1Time);

    Serial.print(":\t");

    //Serial.print("sensorVolt "); Serial.print(sensorVolt, 2);

    Serial.println(":\t");

  }

}


void SwitchPolar(void) {

  if (SensorPolar == LOW) {

    digitalWrite(SensorPlus, HIGH);

    digitalWrite(SensorMinus, LOW);

  } else {

    digitalWrite(SensorPlus, LOW);

    digitalWrite(SensorMinus, HIGH);

  }

}




  

댓글 0

MADE BY

유수엽

농사, 레이저커팅 활용, 아두이노 활용, 회로설계 프로그램