Max Tern
Published © GPL3+

Keep Your Plant Moist (Appropriate Amount)

Shows level of plant moisture, and lasts more than a year from a battery.

IntermediateWork in progress8 hours417

Things used in this project

Hardware components

ATmega328
Microchip Technology ATmega328
DIP case
×1
resistor 27k
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
Resistor 475 ohm
Resistor 475 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

front_ghwoPKcHaH.f3d

arrow_tUN9kA8fNF.f3d

Schematics

ServoPlantS.jpg

Code

ServoPlant

Arduino
#include <Arduino.h>
// needs to install this libs;
#include <LowPower.h>
#include <Servo.h>

#define ANALOG_PIN A0 // read moister data from this pin
#define PLANT_PIN 4 // connect moister senser 
#define EN_MOTOR_PIN 5 // transistor to enable servo
#define SERVO_PIN 3 // controll the server
#define WATCH_DOG_OVERFLOW 1350 // deley counter for watch dog 1350 -> watchdog fires every 8 sec 7.5 times a minute * 60 = 450 times an hour *3 = 1350 times in 3 hours;

//move servo only if the data changes more than 50
int old = 0;
Servo servo;
volatile int watchdog_counter = WATCH_DOG_OVERFLOW;

// sleep for 8 secs
void sleep (){
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

// read analog data from the plant;
int read(int pin){
  digitalWrite(pin, HIGH);
  int value = analogRead(ANALOG_PIN);
  digitalWrite(pin, LOW);  
  return value;
};

void setup() {
  Serial.begin(9600);
  pinMode(PLANT_PIN, OUTPUT);
  pinMode(EN_MOTOR_PIN, OUTPUT);
  // disable plant and monter on the start;
  digitalWrite(EN_MOTOR_PIN, HIGH);
  digitalWrite(PLANT_PIN, LOW);
}

void loop() {
  Serial.println("loop");
  sleep();
  // after sleep checking if I sleep long for plant to dry 
  if(watchdog_counter < WATCH_DOG_OVERFLOW){ 
     // increment spleep counter;
      watchdog_counter++;
      return;
  }
  watchdog_counter = 0;

  // read plant data;
  int value = read(PLANT_PIN);
  
  Serial.print("old: ");
  Serial.println(old);
  // if data changes more than 50 update servor postion;
  if(abs(old - value) > 50){
    // enable servo
    digitalWrite(EN_MOTOR_PIN, LOW);
    servo.attach(SERVO_PIN); 
    delay(50);
    // map plant data to servro angle 
    int servoValue = map(value, 0, 1024, 180, 0);
    Serial.print("value: ");
    Serial.print(value);
    Serial.print(" servo: ");
    Serial.println(servoValue);
    servo.write(servoValue);
    // wait for servo rich angle
    delay(1000);
    // update old plant value;
    old = value;
    // disable servo
    servo.detach();
    digitalWrite(EN_MOTOR_PIN, HIGH);
  }
  // go to spleep;
}

Credits

Max Tern

Max Tern

1 project • 1 follower

Comments