[스마트화분] 기초모듈로 만드는 스마트화분

[스마트화분] 기초모듈로 만드는 스마트화분

Makerist 0 706

#include <AFMotor.h>


const int soilMoisturePin = A0; // 토양수분센서 핀 설정
const int pumpPin = 3; // 워터 펌프 핀 설정


int soilMoistureThreshold = 500; // 수분 임계치 설정


AF_DCMotor pumpMotor(1); // DC 모터 객체 생성


void setup() {
  Serial.begin(9600); // 시리얼 통신 시작
  pumpMotor.setSpeed(255); // 모터 속도 설정
  pinMode(pumpPin, OUTPUT); // 워터 펌프 핀을 출력으로 설정
}


void loop() {
  int soilMoistureValue = analogRead(soilMoisturePin); // 토양수분센서 값을 읽음
  Serial.print("Soil Moisture: ");
  Serial.println(soilMoistureValue);


  if (soilMoistureValue < soilMoistureThreshold) {
    Serial.println("Soil is dry. Pumping water.");
    activatePump(); // 펌프 활성화
    delay(5000); // 5초 동안 대기
  } else {
    Serial.println("Soil is moist enough.");
    deactivatePump(); // 펌프 비활성화
  }
  delay(1000); // 1초 대기
}


void activatePump() {
  pumpMotor.run(FORWARD); // 펌프를 전진 방향으로 작동
}


void deactivatePump() {
  pumpMotor.run(RELEASE); // 펌프 정지
}

0 Comments
Category
반응형 구글광고 등
State
  • 현재 접속자 137 명
  • 오늘 방문자 554 명
  • 어제 방문자 3,368 명
  • 최대 방문자 4,586 명
  • 전체 방문자 675,814 명
  • 전체 게시물 26,013 개
  • 전체 댓글수 36 개
  • 전체 회원수 22 명
Facebook Twitter GooglePlus KakaoStory KakaoTalk NaverBand