Automated Plant Waterer

Here is a circuit diagram of the circuit shown in the video:
rect4159-09-4

This is the C program that runs on the dsPIC:

// Program to control automated plant waterer
//wattnotions 2/16/15
#include <xc.h>
#include <libpic30.h>
#include<stdio.h>
//#include <stdlib.h>
 
// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, i.e. 30 MIPS
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin

//Functions
void setup(void);
void servo(int pw); // controls the servo angle accepts pulse width in us eg 1500 = 1.5ms pulse
void pump (int n, unsigned long int ms); // flips pins high and low to change direction of actuator motor and pump the handle
// n = number of pumps ; ms = time delay in between pumping motion

//variables
unsigned int pw_cyc;
long int  total_p;
unsigned long int delay_cyc;
int i;


int main(void)
{
	
	setup();
	
	while(1)
	{
		
		for(i=0 ; i<50 ; i++) servo(1800); // off
		pump(10, 300);
		for(i=0 ; i<200 ; i++) servo(1100); //on
	}
	
	

	
	
}

void setup(void)
{
    //configure pins
	TRISD = 0b00000000;
 
}

void servo(int pw)
{
	
	pw_cyc = pw*30;
	total_p = 600000 - pw_cyc;
	_LATD2 = 1;
	__delay32(pw_cyc);
	_LATD2 = 0;
	__delay32(total_p);
	
}

void pump (int n, unsigned long int ms)
{
	delay_cyc = ms*30000;
	for(i=0; i<n; i++)
	{	
		_LATD1 = 1;
		_LATD3 = 0;
		__delay32(delay_cyc);
		
		_LATD1 = 0;
		_LATD3 = 0;
		__delay32(delay_cyc);
		
		
		_LATD3 = 1;
		_LATD1 = 0;
		__delay32(delay_cyc);
		
		_LATD1 = 0;
		_LATD3 = 0;
		__delay32(delay_cyc);
	}
	
}

This entry was posted in C, Hardware, Ideas, pic microcontrollers, Projects and tagged , , , , . Bookmark the permalink.

8 Responses to Automated Plant Waterer

  1. Pingback: Automated Plant Watering System Uses Car Parts | Hack The Planet

  2. Pingback: Tech News / Automated Plant Watering System Uses Car Parts

  3. Pingback: Automated Plant Watering System Uses Car Parts | MyWebspace

  4. Alastair says:

    Brilliant! Love the plant waterer, even made me laugh.

    I’m just an electronics “dabbler” and have had browse around your blog – lots of interesting and fun stuff.

    Keep up the good work – will follow you (not in a creepy stalker kind of way) from now on!

    Alastair

  5. Ty Tower says:

    Whats a PICIT2 Whats the processor a dsPIC:?

  6. Pingback: Weekly Recap - Watering Hacks / Cooking Hacks Blog

Leave a Reply