Re: [응용하기] 수분+워터펌프_릴레이 사용X

Re: [응용하기] 수분+워터펌프_릴레이 사용X

Makerist 1 1680

// 토양 수분 센서 및 워터 펌프 핀 설정
const int soilSensorPin = A0; // 토양 수분 센서를 A0 핀에 연결
const int waterPumpPin = 2;   // 워터 펌프 모터를 2번 핀에 연결


// 토양 수분 센서의 임계값 설정
const int threshold = 500; // 수분이 부족한 경우의 임계값 설정 (임의로 설정)


void setup() {
  // 워터 펌프 핀을 출력으로 설정
  pinMode(waterPumpPin, OUTPUT);
  
  // 초기 상태에서 워터 펌프 비활성화
  digitalWrite(waterPumpPin, LOW);
}


void loop() {
  // 토양 수분 센서 값 읽기
  int soilMoisture = analogRead(soilSensorPin);
  
  // 토양 수분이 부족한 경우 워터 펌프 작동
  if (soilMoisture < threshold) {
    Serial.println("수분 부족! 워터 펌프 작동");
    digitalWrite(waterPumpPin, HIGH); // 워터 펌프 모터 활성화
  } else {
    Serial.println("수분 충분. 워터 펌프 작동 중지");
    digitalWrite(waterPumpPin, LOW); // 워터 펌프 모터 비활성화
  }
  
  // 잠시 대기
  delay(1000);
}

1 Comments
Makerist 2024.03.17 04:21  
토양 수분 센서의 값이 임계값(threshold)보다 작으면 워터 펌프를 작동시키고, 그렇지 않으면 워터 펌프를 멈춥니다. 릴레이 모듈이나 모터 드라이버를 사용하여 워터 펌프를 제어할 수 있습니다.
Category
반응형 구글광고 등
State
  • 현재 접속자 133 명
  • 오늘 방문자 549 명
  • 어제 방문자 3,368 명
  • 최대 방문자 4,586 명
  • 전체 방문자 675,809 명
  • 전체 게시물 26,011 개
  • 전체 댓글수 36 개
  • 전체 회원수 22 명
Facebook Twitter GooglePlus KakaoStory KakaoTalk NaverBand