automatic watering systems

124
Politecnico di Torino Laurea Magistrale in Ingegneria Elettronica Codesign Methods and Tools Automatic Watering System Group 1: Busignani Fabio 197883 Gianoglio Emanuele 200090 Anno Accademico 2013/2014

Upload: eebuso

Post on 20-Oct-2015

47 views

Category:

Documents


5 download

DESCRIPTION

UML homework for description of an automatic watering systems.In order to achieve this project, PIC18F4520 is used as reference microcontroller

TRANSCRIPT

  • Politecnico di TorinoLaurea Magistrale in Ingegneria Elettronica

    Codesign Methods and Tools

    Automatic Watering System

    Group 1:

    Busignani Fabio 197883Gianoglio Emanuele 200090

    Anno Accademico 2013/2014

  • Vese1 root

    ActorsName Documentation

    Actor - User User is an adult person who uses the Automatic_Watering_System.

    Actor - Technician Man Technician Man is a person who has technical skills for what concern the Automatic_Watering_System. She/He is able to repair the system substituting the sensors

    Actor - Soil Soil is the terrain where the Automatic_Watering_System manages Watering Pump to drive the watering pump. The system measures the humidity and decides if activate the watering or not.

    Actor - Air Air is the environment around the Automatic_Watering_System. The system measures thetemperature of the air in order to decide if activate the watering or not.

    Actor - Watering Pump

    Automatic Watering ProjectAutomatic Watering Project consist in an Automatic_Watering_System that is configurable by the User through an LCD displaay. Thesystem drive the watering pump through a relay that is active only when the User decide to start watering or when the time reach the hour set by the User in the automatic mode. The system start watering after have verified that the moisture percentage in the soil is not too high. The system moreover control the air temperature and provides all the data to the User through the LCD display. User can interact with the system through a KeyPad with 4x4 key matrix.Technician Man can act on the system to repair it and connect it.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 3 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 4 of 124

  • Vese1 rootUse Case - Turn ON SystemUser shift the switch in ON position to turn on the Automatic_Watering_System.

    Turn ON SystemThe User activate the system by switching on the power supply switch. main() initializes the peripherals and the LCD shows the Principal Men. The project is completely linked through the various men displayed by the LCD.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 5 of 124

  • Vese1 root

    Use Case - Turn OFF SystemUser shift switch in OFF position to turn off the Automatic_Watering_System.

    Turn OFF SystemUser turn off the system by switching off the power supply.

    Use Case - Configure SystemUser, following the instruction on LCD_4X20 and through press(SWi) function ,where SWi is one of among the 16 buttons of the KeyPad (from 0 to 9, from A to D, * and #), is able to use and configure the Automatic_Watering_System. It is possible to: - start watering manually - stop watering manually - enter in a menu where it is possible to: * set time * turn on/off the automatic watering * set time and duration of the watering * set humidity and temperature thresholds - read the current values of soil humidity and air temperature In all of the cases User can return to the previous menu by pressing #.

    Use Case - Principal menThe LCD_4X20 show(string) the following menu on 4 lines:

    Start Watering Stop Watering Autom. sys. men Hum/Temp

    User press(SWi) SWi on KeyPad to activate the relative functionality, in particular: SWi=10 (A) calls use case Start watering; SWi=11 (B) calls use case Stop watering; SWi=12 (C) calls use case Automatic system menu; SWi=13 (D) calls use case Show humidity and temperature;

    User press(SWi) SWi = 15 (#) to return back in the previous men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 6 of 124

  • Vese1 root

    Principal MenuThis is the first menu that appears at the User on LCD display. The User can decide how to navigate it by pressing one among A,B,C or D on the keypad.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 7 of 124

  • Vese1 rootUse Case - Stop wateringUser orders the Automatic_Watering_System to turn off the Watering Pump without any verification on the current values of temperature and humidity.

    Stop wateringUser has pressed button B (key=11) in the Principal Men, this means that the system is deactivated manually and so the sw control if the relay status is on and if this is the case, turn off it and stop to drive the watering pump. At the end of the operation the system returns in status 0 (principal men waiting for a new press on keypad)

    Use Case - Start wateringUser orders the Automatic_Watering_System to turn on the Watering Pump without any verification on the current values of temperature and humidity.

    Start wateringUser has pressed button A (key=10) in the Principal Men, this means that the system is activated manually and so the sw control if the relay status is off and if this is the case, turn on it and drive the watering pump. At the end of the operation the system returns in status 0 (principal men waiting for a new press on keypad)

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 8 of 124

  • Vese1 root

    Use Case - Show humidity and temperature LCD_4X20 show(string) to User two lines. In the first line is shown the Air temperature measured by (model element not found) in the format "xx C"; In the second line is shown the Soil humidity measured by MoistureSensor in the format "xx %";

    Show humidity and temperatureUser has pressed button D (key=13) in the Principal Men, this means that the system show on LCD the current humidity and temperature. User can press # to return in the Principle men

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 9 of 124

  • Vese1 rootUse Case - Automatic system menu LCD_4X20 show(string) to User a new men where it is possible to set the functionalities of the automatic watering like set time, turn on and off the automatic watering mode, set time and duration of the watering and set humidity thresholds above that the system starts watering by activating Watering Pump.

    Use Case - Settings menThe LCD_4X20 show(string) the following menu on 4 lines:

    Set time Autom. sys. ON/OFF Watering settings Set Hum thresh.

    User press(SWi) SWi on KeyPad to activate the relative functionality, in particular: SWi=10 (A) calls use case Set time; SWi=11 (B) calls use case Automatic system ON/OFF; SWi=12 (C) calls use case Watering settings; SWi=13 (D) calls use case Set humidity thresholds;

    User press(SWi) SWi = 15 (#) to return back in the previous men.

    Settings menUser has pressed button C (key=12) in the Principal Men, this means that the LCD changes the displayed option and offer a new list of possible action. User can navigate it by pressing A,B,C,D or can return to the principle men by pressing #

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 10 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 11 of 124

  • Vese1 rootUse Case - Set time LCD_4X20 show(string) the time in format hh:mm User can set the current time by press(SWi) SWi on KeyPad with SWi from 0 to 9 (numbers from 0 to 9). At the first press the user sets the most significant digit of the hour, at the second press sets the last significant digit of the hour. At the third press the user sets the most significant digit of the minutes and at the fourth press sets the last significant digit of the minutes.

    Set timeUser has pressed A(key=10) in the Settings men. User can set the time by pressing the digits on the keypad. SW transfer the set time to the RTCC that give the time reference to the system. In any moment user can press # to return to the Settings men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 12 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 13 of 124

  • Vese1 rootUse Case - Set humidity thresholds LCD_4X20 show(string) the humidity in format HH % User can set the watering duration by press(SWi) SWi on KeyPad with SWi from 0 to 9 (numbers from 0 to 9). At the first press the user sets the most significant digit of the humidity, at the second press sets the last significant digit of the humidity. After that HumidityTH: unsigned char is set, LCD_4X20 show(string) the following string: "Set! HH%", in which HH is substituted by HumidityTH: unsigned char current value.

    Set humidity thresholdsUser has pressed D (key = 13) in the Settings men. User can set the humidity threshold by pressing the digits on the keypad. User can press # to return to the Settings menu

    .

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 14 of 124

  • Vese1 rootUse Case - Automatic system ON/OFFUser can decide if the Automatic_Watering_System is able to turn on automatically the Watering Pump at the pre-set hour by checking the temperature and the humidity or if the automatic system is turned OFF.

    Use Case - Automatic system ON/OFF menThe LCD_4X20 show(string) the following menu on 4 lines:

    Autom. sys. ON Autom. sys. OFF Actual Status

    User press(SWi) SWi on KeyPad to activate the relative functionality, in particular: SWi=10 (A) calls use case Automatic system ON; SWi=11 (B) calls use case Automatic system OFF;

    User press(SWi) SWi = 15 (#) to return back in the previous men.

    Automatic System ON/OFF menUser has pressed B (key = 11) in the Settings men. LCD shows a new men were user can decide if press A or B to set the automatic system on or off. User can press # to return to the Settings men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 15 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 16 of 124

  • Vese1 root

    Use Case - Automatic system OFFThe Automatic_Watering_System is OFF and isn't able to control automatically Watering Pump. The watering can be started only manually with Start watering. The LCD_4X20 show(string) the following string: "Status OFF"

    Automatic system OFFUser has pressed B (key = 11) in the Automatic System ON/OFF men. In this way the automatic system is activated by put AutoStatus=0. This is a global variable that is used by the interrupt subroutine that control the automatic watering. At the end of the operation the system return in the previous men.

    Use Case - Automatic system ONThe Automatic_Watering_System is ON and is able to control Watering Pump. The LCD_4X20 show(string) the following string: "Status ON"

    Automatic system ONUser has pressed A (key = 10) in the Automatic System ON/OFF men. In this way the automatic system is activated by put AutoStatus=1. This is a global variable that is used by the interrupt subroutine that control the automatic watering. At the end of the operation the system return in the previous men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 17 of 124

  • Vese1 root

    Use Case - Watering settingsUser can decide the hour at which the automatic system start watering during the day (if there are properly humidity and temperature conditions), and the duration of the watering.

    Use Case - Automatic system settings menThe LCD_4X20 show(string) the following menu on 4 lines:

    Watering time Watering duration

    User press(SWi) SWi on KeyPad to activate the relative functionality, in particular: SWi=10 (A) calls use case Set watering time; SWi=11 (B) calls use case Set watering duration;

    User press(SWi) SWi = 15 (#) to return back in the previous men.

    Automatic system settings menUser has pressed C (key = 12) in the Settings men. LCD shows a new men were user can decide if press A or B to set the watering start time and stop time. User can press # to return to the Settings men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 18 of 124

  • Vese1 root

    Use Case - Set watering duration LCD_4X20 show(string) the switch-off time in format hh:mm. User can set the watering duration by press(SWi) SWi on KeyPad with SWi from 0 to 9 (numbers from 0 to 9). At the first press the user sets the most significant digit of the hour, at the second press sets the last significant digit of the hour. At the third press the user sets the most significant digit of the minutes and at the fourth press sets the last significant digit of the minutes.

    Set watering durationUser has pressed B(key = 11) in the Automatic system settings men. User can set the stop watering time by pressing the digits on the keypad. This hour is sent to the RTCC that create an interrupt when that hour is reached. User can press # to return to the Automatic system settings men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 19 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 20 of 124

  • Vese1 rootUse Case - Set watering time LCD_4X20 show(string) the time in format hh:mm User can set the watering time by press(SWi) SWi on KeyPad with SWi from 0 to 9 (numbers from 0 to 9). At the first press the user sets the most significant digit of the hour, at the second press sets the last significant digit of the hour. At the third press the user sets the most significant digit of the minutes and at the fourth press sets the last significant digit of the minutes.

    Set watering timeUser has pressed A (key = 10) in the Automatic system settings men. User can set the start watering time by pressing the digits on the keypad. This hour is sent to the RTCC that create an interrupt when that hour is reached. User can press # to return to the Automatic system settings men.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 21 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 22 of 124

  • Vese1 rootUse Case - Sensor substitutionTechnician Man substitutes the broken sensor.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 23 of 124

  • Vese1 root

    Automatic Watering Project

    Class - MoistureSensor_CableIt is a shielded cable composed by 3 wires.

    ReferencesType Value

    URL http://vegetronix.com/Products/VG-WIRE-SH3/

    Tagged Valuesmanufactorer

    Value Vegetronix

    Name

    Value VG-WIRE-SH3

    Cost

    Value 1.99 $/m

    Number of conductors

    Value 3

    Shielded

    Value Yes

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 24 of 124

  • Vese1 rootMax Operating voltage

    Value 300V

    OperationsSignature: connect()This operation is executed by Technician Man to connect 3 pins with others three pins.

    Class - Power_SupplyPower_Supply provides the power that our systems needs. At this class two attribute are associated:

    GND VCC

    AttributesSignature Documentation

    -GND It is the electrical reference to 0V.

    -VCC It is the electrical value of voltage supply and it's equal to 5V.

    Class - PowerOnCircuitPowerOnCircuit is the part of circuit which interrupts the current coming from Power_Supply. When User wants to turn on the systems uses the Switch, to shortCircuit(). Or, when User wants to turn off the systems uses the Switch, to openCircuit(). The schematic view of this PowerOnCircuit is the following:

    AttributesSignature Documentation

    -SW2 : Switch

    Class - DS18B20It is a digital sensor with communicates with microcontroller, or an a general CPU, using 1Wire protocol.

    The I/O digital port of this component (D0()) must to be connected with a pullup resistor, as shown in figure:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 25 of 124

  • Vese1 root

    ReferencesType Value

    URL http://www.newark.com/maxim-integrated-products/ds18b20/thermometer-prog-12bit-3to92/dp/96K8885?ost=ds18b20&rpsku=DS18B20

    URL http://www.farnell.com/datasheets/46379.pdf

    Tagged ValuesManufactorer

    Value MAXIM INTEGRATED PRODUCTS

    Newark Part No.

    Value 96K8885

    Manufacturer Part No

    Value DS18B20+

    IC Output Type

    Value Digital

    No. of Pins

    Value 3

    Packaging

    Value TO - 92

    Resolution (Bits)

    Value 12 bit

    Sensing Accuracy Range

    Value 0.5C

    Sensing Temperature Max

    Value 125C

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 26 of 124

  • Vese1 root

    Sensing Temperature Min

    Value -55C

    Supply Current

    Value 1mA

    Supply Voltage Max

    Value 5.5V

    Supply Voltage Min

    Value 3V

    Cost

    Value 6.46$

    OperationsSignature: VDD()It is an electrical pin that has to be connected to VDDSignature: GND()It is an electrical pin that has to be connected with GNDSignature: D0()It is the digital pin that realize the I/O serial port of DS18B20.Signature: ShowTemperature_DS18B20()This operation allows the User to see the current value of temperature in the LCD_4X202. The algorithm that implements this function is shown below:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 27 of 124

  • Vese1 root

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 28 of 124

  • Vese1 rootCode Body:

    if(!ResetPulse_OW()) //controlla la presenza del sensore, eseguendo anche un reset sulla linea{

    /***************************** Accesso al DS18B20******************************/

    OW_write_byte(SKIP_ROM_DS18B20); //salta la ricezione del ROM CODE, in quanto presente un solo sensore sul bus

    OW_write_byte(CONVERT_T_DS18B20); //invia la richiesta di conversione, il cui risultato posto in memoria del sensore

    delay_ms(750); //attesa conversioneOW_reset_pulse(); //controllo presenza +

    reset sulla lineaOW_write_byte(SKIP_ROM_DS18B20); //salta ricezione ROM CODEOW_write_byte(READ_COMMAND_DS18B20); //invio richiesta di lettura, il sensore

    trasmette tutto il contenuto della sua memoria a partire da banco 0 fino a banco 9

    /***************************** Acquisizione temperatura******************************/

    LSB=OW_read_byte(); //byte meno significativo temperatura (banco 0)

    MSB=OW_read_byte(); //byte pi significativo temperatura (banco 1)

    if(MSB & 0x08) //controllo il bit di segno (1=temp negativa)

    {LSB = ~LSB; //complemento a 1 LSBMSB = ~MSB; //complemento a 1

    MSBif(LSB == 0xFF) //verifico quando necessario

    sommare 1 all'MSB{ //altrimenti

    sommo 1 aolo al byte meno significativoMSB = MSB +1;LSB = ~LSB;

    }else{LSB = LSB +1;

    }WriteStringLCD("Temp. -");

    }else{WriteStringLCD("Temp. +");

    }

    INTbin=(LSB>>4)|(MSB

  • Vese1 root2

    decine=INTbin/10; // 32/10 = 3

    /***************************** Teperatura parte decimale*****************************/

    dec=0;

    if (DECbin & 0x80) //si preleva da DECbin il solo valore 2^(-1), il quale se vale 1 si incrementa

    { //la variabile dec di 0.5 gradi dec=dec+5000;

    }if (DECbin & 0x40) //si preleva da DECbin il solo valore 2^(-2), il quale se

    vale 1 si incrementa{ //la variabile dec di 0.25 gradi

    dec=dec+2500;}if (DECbin & 0x20) //si preleva da DECbin il solo valore 2^(-3), il quale se

    vale 1 si incrementa{ //la variabile dec di 0.125 gradi

    dec=dec+1250;}if (DECbin & 0x10) //si preleva da DECbin il solo valore 2^(-4), il quale se

    vale 1 si incrementa{ //la variabile dec di 0.0625 gradi

    dec=dec+625;} decimi=dec/1000; //esempio con dec = 4375 restituisce 4 centesimi=(dec%1000)/100; //4375 % 1000 = 375; 375/100 = 3 millesimi=(dec%100)/10; //4375 % 100 = 75; 75/10 = 7 decimill=dec%10; //4375 % 10 = 5

    /*******************************Scrittura su display LCD

    ********************************/

    WriteCharLCD(decine+0x30); //si somma 0x30 = 48 perch i caratteriWriteCharLCD(unita+0x30); //numerici iniziano da tale posizione (vedi

    Tabella Ascii)WriteStringLCD(".");WriteCharLCD(decimi+0x30);WriteCharLCD(centesimi+0x30);WriteCharLCD(millesimi+0x30);WriteCharLCD(decimill+0x30);

    }else{

    WriteStringLCD ("18B20 assente ");GotoLineLCD(1);

    }GotoLineLCD(1);

    Signature: fixing()The DS18B20 is soldered in bottom layer following the figures shows below:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 30 of 124

  • Vese1 root

    Signature: connection()

    Class - RTCCThis component realizes a Real Time Clock Calendar. So, using the I2C protocol to communicate with it, a microcontroller can knowsevery information about the clock and the calendar. Microcontroller can also set this attribute and the alarm.

    ReferencesType Value

    URL http://it.farnell.com/nxp/pcf8563t-f4-112/ic-rtc-calendario-smd-8563-soic8/dp/8906130

    URL http://www.farnell.com/datasheets/1696817.pdf

    Tagged ValuesManufactorer

    Value NXP

    Cost

    Value 1.36

    Farnell Code

    Value 8906130

    Manufactorer Code

    Value PCF8563T/F4,112

    Supply Voltage Min

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 31 of 124

  • Vese1 rootValue 1V

    Supply Voltage Max

    Value 5.5V

    Digital IC Case Style

    Value SOIC

    N. of Pins

    Value 8

    IC Interface Type

    Value I2C

    Operating Temperature Min

    Value -40C

    Operating Temperature Max

    Value 85C

    AttributesSignature Documentation

    -BypassCapacitor_RTCC : SMD_Capacitor_0402

    OperationsSignature: OSCI()It is an electrical pin associated with oscillator input.Signature: OSCO()It is an electrical pin associated with oscillator output.Signature: INT()It is a digital output which is normally set at value 1. When an alarm is generated inside the RTCC, this output port changes its value.Signature: VSS()This electrical pin must to be connected with the ground reference of the circuit.Signature: VDD()This electrical pin has to be connected to VDD of the circuit.Signature: CLKOUT()This is an electrical output pin, in which clock output is available.Signature: SCL()This is a digital pin which represents the serial clock input of I2C communication.Signature: SDA()This is a digital pin which represents the serial data input and output of I2C communication.Signature: setMinutes_RTCC(minutes : unsigned char) : voidThis function allows to set minutes of the RTCC. minutes have to be expressed as two digits BCD format.Code Body: EEByteWrite (0xA2,0x03,minutes);Signature: setHours_RTCC(hours : unsigned char) : voidThis function allows to set hours of the RTCC. hours have to be expressed as two digits BCD format.Code Body:Vese1.docx - 2014-02-20 - 1:20 PM Pag. 32 of 124

  • Vese1 root EEByteWrite (0xA2,0x04,hours);Signature: setDays_RTCC(days : unsigned char) : voidThis function allows to set the days in RTCC. The days that has to be written is express as two digits BDC format.Code Body: EEByteWrite (0xA2,0x05,days);Signature: setMonths_RTCC(months : unsigned char) : voidThis function allows to write the months in the RTCC. The months is composed by two digits BCD format.Code Body: EEByteWrite (0xA2,0x07,months);Signature: setYears_RTCC(years : unsigned char) : voidThis function allows to set the years in RTCC. The years that has to be written is express as two digits BDC format. For example, 2014 is only 0x14.Code Body: EEByteWrite (0xA2,0x08,years);Signature: setMinutes_Alarm_RTCC(minutes : unsigned char) : voidThis function allows to write the minutes for the alarm interrupt in the RTCC. The minutes that has to be written is expressed in two digit BCD format.Code Body: EEByteWrite (0xA2,0x09,minutes);Signature: setHours_Alarm_RTCC(hours : unsigned char) : voidThis function allows to write the hours for the alarm interrupt in the RTCC. The hours that has to be written is expressed in two digit BCD format.Code Body: EEByteWrite (0xA2,0x0A,hours);Signature: enableAlarm_RTCC() : voidThis function enables the interrupt generated by RTCC.Code Body: EEByteWrite (0xA2,0x01,0x02);Signature: disableAlarm_RTCC() : voidThis function disables the interrupt generated by RTCC.Code Body: EEByteWrite (0xA2,0x01,0x00);Signature: getMinutes_RTCC() : unsigned charThis function returns the vale of current minutes in RTCC. Minutes are expresses with two digits BCD format.Code Body: //initialize a temp variable for minutesunsigned char TempMinutes;TempMinutes = EERandomRead (0xA2,0x03);

    // because of the max value for the minutes is 59 = 0b01011001, //the MSB is a not significant bit. In order to be sure that its value//isn't read we use a mask

    return (TempMinutes && 0b01111111);

    Signature: getHour_RTCC() : unsigned charThis function returns the vale of current hours in RTCC. Hours are expresses with two digits BCD format.Code Body: //initialize a temp variable for hoursunsigned char TempHours;TempHours = EERandomRead (0xA2,0x04);

    // because of the max value for the minutes is 24 = 0b00100100, //the first two bit are not significant bits. In order to be sure that its value//isn't read we use a mask

    return (TempHours && 0b00111111);Signature: getTime_RTCC() : unsigned charThis function returns the time from the RTCC. The format is HH:MM.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 33 of 124

  • Vese1 rootCode Body: /* we need two chars for hours (HH), * a char for ':'; * others two chars for minutes (MM) * and finally a char for termination '\0' * So, we need 6 chars: */static unsigned char time[6];unsigned char a;

    a = getHours_RTCC();

    // with +48 I convert the number in ASCII number//first char is the units of minutestime[1] = (a & 0b00001111)+48; //the second char is the tens of minutestime[0] = (a >> 4)+48;//the third char is ':'time[2] = ':';

    a = get_minutes_RTCC();//the forth char is the units of hourstime[4] = (a & 0b00001111)+48;//the fiveth char is the tens of hourstime[3] = (a >> 4)+48;

    //the sixth and last char is the termination onetime[5] = '\0';

    return (time);Signature: getDays_RTCC() : unsigned charThis function returns the vale of current days in RTCC. Days are expresses with two digits BCD format.Code Body: //initialize a temp variable for daysunsigned char TempDays;TempDays = EERandomRead (0xA2,0x05);

    // because of the max value for the minutes is 31 = 0b00110001, //the first two bit are not significant bits. In order to be sure that its value//isn't read we use a mask

    return (TempDays && 0b00111111);Signature: getMonths_RTCC() : unsigned charThis function returns the vale of current months in RTCC. Months are expresses with two digits BCD format.Code Body: //initialize a temp variable for monthunsigned char TempMonth;TempMonth = EERandomRead (0xA2,0x07);

    // because of the max value for the minutes is 12 = 0b00010010, //the first three bit are not significant bits. In order to be sure that its value//isn't read we use a mask

    return (TempMonth && 0b00011111);Signature: getYears_RTCC() : unsigned charThis function returns the vale of current years in RTCC. Years are expresses with two digits BCD format.Code Body: //initialize a temp variable for monthunsigned char TempYears;TempYears = EERandomRead (0xA2,0x08);

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 34 of 124

  • Vese1 root

    return (TempYears);Signature: fixing()This component has to be soldered in surface of PCB. The dimensions of it are shown below:

    Class - 1N4004It is a standard diode. In first approximation 1N4004 is used as unidirectional conductive path. If the voltage applied to pin A() is bigger than voltage applied to pin K(), and their difference is also higher than 1N4004 threshold voltage, due to depleted region, so a current can flow from A() to K(). Otherwise, the behavior of this component is equal to an open circuit.

    ReferencesType Value

    URL http://http://it.farnell.com/multicomp/1n4004/diodo-standard-1a-400v-do-41/dp/9565027

    URL http://www.farnell.com/datasheets/574765.pdf

    Tagged ValuesManufactorer

    Value MULTICOMP

    Farnell Code

    Value 9565027

    Manufactred Code

    Value 1N4004

    Diode Kind

    Value Standard Recovery

    Repetitive Reverse Voltage Vrrm Max

    Value 400V

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 35 of 124

  • Vese1 rootForward Current If

    Value 1A

    Forward Voltage VF Max

    Value 1V

    Forward Surge Current Ifsm Max

    Value 30A

    Package

    Value DO-41

    Operating Temperature min.

    Value -65

    Operating Temperature max.

    Value 150

    OperationsSignature: A()It is the anode pin of 1N4004.Signature: K()It is the cathode pin of 1N4004.Signature: fixing()The image below shows how 1N4004 can be fixed and its dimension. The fixing is through round hole.

    Class - PushbuttonPushbutton is a mechanical button that can be fixing() through hole. User can press() it on the top side.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 36 of 124

  • Vese1 root

    It has four electric contact C1(), C2() , C3() and C4() in order to implement open (when released) and short (when pressed) circuit between them.

    As can be see by the picture, the pair of contact C1()-C2() and C3() -C4() are short-circuited between them. So, from the logical point of view, it has only two terminal.

    Comments

    Documentation C3 is normally closed and opens upon press()

    Date Time nov 7, 2013 7:19:52 AM

    ReferencesType Value

    URL http://http://it.farnell.com/omron-electronic-components/b3f1105/interruttore-piatto-6x6x4-3-260gf/dp/1960951

    URL http://www.farnell.com/datasheets/611570.pdf

    Tagged ValuesManufacturer

    Value OMRON ELECTRONIC COMPONENTS

    Farnell Code

    Value 1960951

    Manufacturer Part Number

    Value B3F1105

    Cost

    Value 0,198

    Max voltage

    Value 24V

    Max current

    Value 50ma

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 37 of 124

  • Vese1 root

    Soldering

    Value THT

    Max Operating temperatures(C)

    Value 70C

    Min Operating temperature(C)

    Value -25C

    Operating Force

    Value 2.55N

    Contact resistance

    Value 100Mohm

    OperationsSignature: press()User through press() operation is able to press and release Pushbutton. When pressed the pair C1()-C2() are short circuited to the pair C3()-C4(). When released this contact is open.Signature: C1()Electric terminal, screw type; normally at C3(); shorts to C2() when press(); open otherwise.Signature: C2()Electric terminal, screw type; normally open; shorts to C1() when press(); open otherwise.Signature: C3()Electric terminal, screw type; normally at C1() ;open otherwise.Signature: C4()Electric terminal, screw type; normally at C1() ;open otherwise.Signature: fixing()The image below shows how Pushbutton can be fixed and its dimension. The fixing is through round hole.

    Class - ResetCircuitResetCircuit is the circuit shown below.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 38 of 124

  • Vese1 root

    This circuit if connected to master clear reset of MicroPIC_18F4520 allows the User to reset the system by operation press() of Pushbutton.

    AttributesSignature

    -PullUpResistor_RST : SMD_Resistor_1206

    -SeriesResistor_RST : SMD_Resistor_0805

    -BypassCapacitor_RST : SMD_Capacitor_0402

    -SW1 : Pushbutton

    OperationsSignature: VDD()VDD() pin is an electrical pin that has to be connected to the VDD pin of the power supply connectorSignature: GND()GND() pin is an electrical pin that has to be connected to the GND pin of the power supply connectorSignature: MCRST()MCRST() pin is an electrical pin that has to be connected to the master clear reset pin of MicroPIC_18F4520.

    Class - 32kHz_Oscillator32kHz_Oscillator is a components that uses the mechanical resonance of a quartz to create an electrical signal with a frequency equal to 32.768 KHz.

    ReferencesType Value

    URL http://it.farnell.com/abracon/abs06-32-768khz-1-t/cristallo-32-768khz-12-5pf-smd/dp/2101344

    URL http://www.abracon.com/Resonators/ABS06.pdf

    Tagged ValuesManufactorer

    Value ABRACON

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 39 of 124

  • Vese1 root

    Farnell Code

    Value 2101344

    Manufactorer Code

    Value ABS06-32.768KHZ-1-T

    Frequency

    Value 32.768kHz

    Frequency Tolerance:

    Value 10ppm

    Load Capacitance

    Value 12.5pF

    Operating Temperature Min

    Value -40C

    Operating Temperature Max

    Value 85C

    Crystal Mounting Type

    Value SMD

    Number of Pins

    Value 2

    AttributesSignature Documentation

    -IN it is the input pin of 32kHz_Oscillator

    -OUT it is the output pin of 32kHz_Oscillator

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 40 of 124

  • Vese1 root

    Class - Connector_1x2For relayIt is a connector which has in a row two positions.

    ReferencesType Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=1792766

    URL http://www.farnell.com/datasheets/528137.pdf

    Tagged ValuesManufactorer

    Value PHOENIX CONTACT

    Farnell Code

    Value 1792766

    Manufactorer Code

    Value MKDSN2,5/2-5.08

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 41 of 124

  • Vese1 rootSeries

    Value MKDSN

    N. of Contacts

    Value 2

    Wire Size AWG Min

    Value 24AWG

    Wire Size AWG Max

    Value 14AWG

    Max Operating Current

    Value 16A

    Max Operating Voltage

    Value 250Vac

    OperationsSignature: connect()Using a screwdriver Technician Man can connect an external wire to PCB system.Signature: pin1()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin2()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: fixing()The Connector_1x2 is soldered in bottom layer following the figures shows below:

    Class - KeyPadConditioningKeyPadConditioning is a circuit that allow to read the button pressed on KeyPad through the adc: ADC. It is composed by R10: SMD_Resistor_0805, R11: SMD_Resistor_0805, R12: SMD_Resistor_0805, R13: SMD_Resistor_0805, R7: SMD_Resistor_0805, R8: SMD_Resistor_0805, R9: SMD_Resistor_0805 that give a different analogue value on pin OUT() in order to discriminate the pressed button. The connection are shown in the figure above.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 42 of 124

  • Vese1 root

    AttributesSignature

    -R7 : SMD_Resistor_0805

    -R8 : SMD_Resistor_0805

    -R9 : SMD_Resistor_0805

    -R10 : SMD_Resistor_0805

    -R11 : SMD_Resistor_0805

    -R12 : SMD_Resistor_0805

    -R13 : SMD_Resistor_0805

    -connector : Connector_1x8

    OperationsSignature: readPressedButton() : unsigned charThis function returns what button is pressed following this codification:

    return 0 if user pressed SW14; return 1 if user pressed SW1; return 2 if user pressed SW2; return 3 if user pressed SW3; return 4 if user pressed SW5; return 5 if user pressed SW6; return 6 if user pressed SW7; return 7 if user pressed SW9; return 8 if user pressed SW10; return 9 if user pressed SW11; return 10 if user pressed SW4; return 11 if user pressed SW8; return 12 if user pressed SW12; return 13 if user pressed SW16; return 14 if user pressed SW13; return 15 if user pressed SW15;

    Code Body: //Set AN0 as channel wich will be tied to ADC inputSelectChannel_ADC(1);Vese1.docx - 2014-02-20 - 1:20 PM Pag. 43 of 124

  • Vese1 root

    //Start the convertionConvert_ADC();

    //Wait until the convertion is donewhile(Busy_ADC());

    //Read result of convertionunsigned int result;result = Read_ADC();

    if (result

  • Vese1 root{

    return 11;}else if (result

  • Vese1 rootTagged Values

    Manufactorer

    Value GLOBAL CONNECTOR TECHNOLOGY

    Farnell code

    Value 1798955

    Manufactorer code

    Value BG030-08-A-0650-0300-N-G

    Cost

    Value 0.27

    Pitch Spacing

    Value 2.54mm

    N. of Rows

    Value 1

    N. of Conctacts

    Value 8

    Contact Termination

    Value Through Hole Vertical

    Contact Plating

    Value gold

    Contact Material

    Value copper

    Operating Temperature Max

    Value 125

    Operating Temperature Min

    Value -55

    Class - MoistureSensorMoistureSensor is a soil moisture sensor named VH400. It as be planted in the soil in order to measure the soil humidity.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 46 of 124

  • Vese1 root

    It's an analog sensor which has three pins, that communicate with the system through a MoistureSensor_Cable connected to the PCB exploiting a Connector_1x3. These three pins are:

    Vcc(), the voltage supply that it needs; GND(), the ground reference; VO(), analog output pin;

    ReferencesType Value

    URL http://www.vegetronix.com/Products/Soil-Moisture-Sensor-Probes.phtml/

    Tagged ValuesManufactorer

    Value Vegetronix

    Value VH400

    Cost

    Value 37.95$

    Operating voltage min

    Value 3.3Vdc

    Operating voltage max

    Value 20Vdc

    Power on to Output stable

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 47 of 124

  • Vese1 rootValue 400 ms

    Min. operation temperature

    Value -40C

    Max. operation temperature

    Value 85C

    Output Voltage min

    Value 0V

    Output Voltage max

    Value 3V

    Max current

    Value 7mA

    AttributesSignature Documentation

    -cable : MoistureSensor_Cable This is a MoistureSensor_Cable that has one side soldered with MoistureSensor.

    OperationsSignature: readMoisture() : floatThis function returns the value of soil humidityCode Body: //Set AN0 as channel wich will be tied to ADC inputSelectChannel_ADC(0);

    //Start the convertionConvert_ADC();

    //Wait until the convertion is donewhile(Busy_ADC());

    //Read result of convertionunsigned int result;result = Read_ADC();

    float humidity;humidity = (result*5)/1023;

    if(humidity

  • Vese1 rootSignature: Vcc()It is the input pin in which voltage supply has to be provided. Its range value is [3.3 - 20] VdcSignature: GND()It is an electrical pin in which ground reference is connected.Signature: VO()It is an analog output pin, its value give us an information about soil moisture. VO() follows this figure in function of moisture:

    This characteristic can be expresses by the following equation:

    moisture = 10*VO()-1 if VO() is in the range [0 - 1.1]V; moisture = 25*VO()-17.5 if VO() is in the range [1.1 - 1.3]V; moisture = 48.08*VO()-47.5 if VO() is in the range [1.3 - 1.82]V; moisture = 26.32*VO()-7.89 if VO() is in the range [1.82 - 3]V;

    Signature: fixing()MoistureSensor is simply planted in the soil. Its dimension are shown in the following figure:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 49 of 124

  • Vese1 rootClass - SwitchIt is an electrical component able to interrupt a current flow.

    As can be see in the following figure, the Switch connects terminal c() with or a() or b(), in function of where the User has imposed.

    ReferencesType Value

    URL http://it.farnell.com/eao/09-03290-01/interruttore-spdt-co-0-5a-12v-pcb/dp/674345

    URL http://www.farnell.com/datasheets/1683364.pdf

    Tagged ValuesManufactorer

    Value EAO

    Farnell Code

    Value 674345

    Manufactorer code

    Value 09-03290.01

    Contact Configuration

    Value SPDT-CO

    Contact Voltage DC Max

    Value 12V

    Contact Current Max

    Value 500mA

    Switch Mounting

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 50 of 124

  • Vese1 rootValue THT

    Contact Resistance

    Value 22Mohm

    Operating Temperature Max

    Value 85C

    Operating Temperature Min

    Value -40C

    Series

    Value 1K2

    Switching Power Max

    Value 6W

    OperationsSignature: shortCircuit()Through this operation, Switch creates a conductive path between c() and b(), while a() is floating.Signature: openCircuit()Through this operation, Switch creates a conductive path between c() and a(), while b() is floating.Signature: a()Electrical pin of Switch.Signature: b()Electrical pin of Switch.Signature: c()Electrical pin of Switch.Signature: fixing()The Switch is soldered in bottom layer following the figures shows below:

    Class - Connector_1x3It is a connector which has in a row three connections.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 51 of 124

  • Vese1 root

    ReferencesType Value

    URL http://it.farnell.com/phoenix-contact/1714984/morsettiera-pcb-9-5mm-3-vie/dp/3704713

    URL http://www.farnell.com/datasheets/100944.pdf

    Tagged ValuesManufactorer

    Value PHOENIX CONTACT

    Farnell Code

    Value 3704713

    Manufactorer Code

    Value 1714984

    Series

    Value MKDS

    Number of Contacts

    Value 3

    Wire Size AWG Min

    Value 24AWG

    Wire Size AWG Max

    Value 10AWG

    Max Operating Current

    Value 32A

    Max Operating Voltage

    Value 500Vac

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 52 of 124

  • Vese1 rootMounting Type

    Value THT

    Connector Type

    Value Screw

    OperationsSignature: connect()Using a screwdriver Technician Man can connect an external wire to PCB system.Signature: fixing()The Connector_1x3 is soldered in bottom layer following the figures shows below:

    Signature: pin1()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin2()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin3()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.

    Class - LCD_4X202It is an alphanumeric LCD display, in which sequences of chars can be viewed.

    ReferencesType Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2063162/

    URL http://http://www.farnell.com/datasheets/1485434.pdf

    Tagged ValuesName

    Value MC42004A6W-BNMLWVese1.docx - 2014-02-20 - 1:20 PM Pag. 53 of 124

  • Vese1 root

    Manufacturer

    Value MIDAS

    Cost

    Value 15.56

    Number of Digitis / Alpha

    Value 80

    Character Count x Line

    Value 20x4

    Backlighting Colour

    Value White

    Character Size

    Value 2.30 x 4.03 mm

    Voltage Supply

    Value 5 V

    Display Mode

    Value Transmissive

    Display Area

    Value 22x60 mm

    Operating Temperature Min

    Value -20 C

    Operating Temperature Max

    Value 70 C

    External Volume

    Value 47x77x14.5 mm

    Illumination Colour

    Value Blue

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 54 of 124

  • Vese1 rootInterface

    Value Parallel

    OperationsSignature: Vss()It is an electrical pin that has to be connected to GND.Signature: Vcc()It is an electrical pin that has to be connected to Vcc.Signature: VO()It is an analog input pin which allows to drive the contrast of chars written in LCD_4X202.Signature: RS()It is a digital input pin which realizes the function of register selection. If its value is:

    0, Instruction register (for write) Busy flag :address counter (for read); 1, Data register (for write and read).

    Signature: RW()It is a digital input pin which realizes the function of read or write selection. If it is:

    0, we realize a read operation; 1, we realize a write operation.

    Signature: E()It is the enable digital input pin: if it is asserted, LCD_4X202 stars the read or write operation.Signature: D0()It is a bidirectional tristate data bus pin, used for data transfer and receive. It is don't used if 4-bit mode is enabled.Signature: D1()It is a bidirectional tristate data bus pin, used for data transfer and receive. It is don't used if 4-bit mode is enabled.Signature: D2()It is a bidirectional tristate data bus pin, used for data transfer and receive. It is don't used if 4-bit mode is enabled.Signature: D3()It is a bidirectional tristate data bus pin, used for data transfer and receive. It is don't used if 4-bit mode is enabled.Signature: D4()It is a bidirectional tristate data bus pin, used for data transfer and receive.Signature: D5()It is a bidirectional tristate data bus pin, used for data transfer and receive.Signature: D6()It is a bidirectional tristate data bus pin, used for data transfer and receive.Signature: D7()It is a bidirectional tristate data bus pin, used for data transfer and receive.Signature: VBp()It is an electrical pin, connected to anode of backlighting LED.Signature: VBn()It is an electrical pin, connected to cathode of backlighting LED.Signature: light()LCD_4X202 emits light when VBp() is connected at a voltage greater that LED threshold and VBn() is connected to ground.Signature: fixing()LCD_4X202 can be fixed by a soldering in bottom layer, or exploiting a Connector_1x8. The physical dimension of this hardware component are shown in figure below:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 55 of 124

  • Vese1 root

    Signature: Open_LCD() : voidThis function initializes the LCD_Display to work in 4 bit mode.Code Body: LCD_RS = 0x00;LCD_E = 0x00;LCD_RW = 0x00;

    __delay_ms (100);Send_LCD (0,0,1,1);__delay_ms (5);Send_LCD (0,0,1,1);__delay_ms (5);Send_LCD (0,0,1,1);__delay_ms (5);Send_LCD (0,0,1,0);Send_LCD (0,0,1,0);Send_LCD (1,0,0,0);Send_LCD (0,0,0,0);Send_LCD (1,1,1,0);CursorLCD (0,0);ClearLCD ();Signature: Send_LCD(D3 : unsigned char, D2 : unsigned char, D1 : unsigned char, D0 : unsigned char) : voidAccording to 4 bit operation mode of LCD_Display, this function send a 4 bit command to LCD_Display itself.Code Body: LCD_D0 = D0;LCD_D1 = D1;LCD_D2 = D2;LCD_D3 = D3;

    //Enable pulseLCD_E = 1;__delay_ms (1);LCD_E = 0;__delay_ms (1);Signature: Clear_LCD() : voidThis function allows to clear the LCD_Display from every written char.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 56 of 124

  • Vese1 rootCode Body: Send_LCD (0,0,0,0);Send_LCD (0,0,0,1);Signature: Home_LCD() : voidThis function move the cursor at the first row and first column of LCD_Display.Signature: Shift_LCD(direction : char, shift : char) : voidThis function shifts in the right or left direction (according to direction value) the chars written on LCD_4X202. The amount of shifting is given by the value of shift. direction can assume two value:

    0, in order to have a left shift; 1, in order to have a right shift.

    shift specifies the number of shift operation that have to be done. Code Body: //index of shifting operationchar i;

    for (i=0; i < shift; i++) {

    Send_LCD (0,0,0,1);Send_LCD (1,direction,0,0);

    }Signature: ShiftCursor_LCD(direction : char, shift : char) : voidExploiting this function it's possible to move the actual position of the cursor. The meaning of input parameters are the same which are expose in Shift_LCD(direction: char, shift: char): void.Code Body: //shifting indexchar i;

    for (i=0; i > 7;D2 = (a & 0b01000000) >> 6;D1 = (a & 0b00100000) >> 5;D0 = (a & 0b00010000) >> 4;

    Send_LCD (D3,D2,D1,D0);

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 57 of 124

  • Vese1 root

    // Splitting of the second nibbleD3 = (a & 0b00001000) >> 3;D2 = (a & 0b00000100) >> 2;D1 = (a & 0b00000010) >> 1;D0 = (a & 0b00000001);

    Send_LCD (D3,D2,D1,D0);

    LCD_RS = 0;Signature: WriteString_LCD(pointerToString : unsigned char) : voidThis function writes a string to the LCD_4X202. pointerToString has to be a string, so it should to be inserted in the following mode: "string".Code Body: while(*pointerToString){

    // Write character to LCDWriteChar_LCD(*pointerToString);pointerToString++;

    }Signature: WriteInt_LCD(value : unsigned int, digits : char) : voidThis function writes an unsigned integer value to the LCD_4X202. digits is the number of shown digit. It can be assume the following value: 0, 1, 2, 3, 4, 5. If:

    equal to 0, the unsigned integer value is shown in LCD_4X202 with a left justification; equal to 1 - 5, the unsigned integer value is shown in LCD_4X202 with a right justification and a number of digit equal to

    digits. Code Body: // The maximum array size is 5 plus end of string \0unsigned char Int_converted [6] = {0,0,0,0,0,0};unsigned char i;

    itoa ((unsigned char*) Int_converted, value,10);

    if (digits >0 ) {

    Int_converted[digits] = '\0';

    while (!(Int_converted[digits-1] = '0')){

    for (i = digits-1; i > 0; i--){

    Int_converted[i] = Int_converted[i-1];Int_converted[i-1] = ' ';

    }}

    }

    writeString_LCD (Int_converted);

    Class - RelayBoardThis part of circuit contains all the component used to drive the Watering Pump. It is composed of:

    PNP_Transistor; 1N4150; LED; SRD_Relay; SeriesResistor_Relay: SMD_Resistor_0805;

    Connected as shown in figure:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 58 of 124

  • Vese1 root

    AttributesSignature

    -DecouplingCapacitor_Relay : SMD_Electrolytic_Capacitor

    -SeriesResistor_Relay : SMD_Resistor_0805

    -LedResistor_Relay : SMD_Resistor_0805

    -relay : SRD_Relay

    OperationsSignature: changeState_Relay() : voidThis function change the status of SRD_Relay contacts.Code Body: //save the current status in a temp variablechar stato = PORTAbits.RA3;

    PORTAbits.RA3 = ~stato;Signature: readStatus_Relay() : unsigned charThis functions allows to read the status of SRD_Relay.Code Body: return PORTAbits.RA3;Signature: IN()This pin is the digital input of the RelayBoard. It must be driven by MicroPIC_18F4520 and, when assert it change the status of relay:SRD_Relay from its idle state to the excited state.Signature: VCC()This is the supply voltage pin. It must to be connected to VCC.Signature: GND()This is an electrical pin that must to be connected to GND reference.Signature: OUT1()It is the electrical pin that is associated to high power side of the relay: SRD_Relay.Signature: OUT2()It is the electrical pin that is associated to high power side of the relay: SRD_Relay.Signature: OUT3()It is the electrical pin that is associated to high power side of the relay: SRD_Relay.

    Class - SMD_Electrolytic_CapacitorThis kind of Capacitor is characterized by having a SMD package with standard for aluminum electrolytic. The component shows as below:

    The capacitance value of this capacitor is C F.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 59 of 124

  • Vese1 rootReferences

    Type Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2068644

    URL http://www.farnell.com/datasheets/1680956.pdf

    Tagged ValuesManufactorer

    Value KEMET

    Series

    Value KEMET - EDK Series

    Capacitance

    Value C [F]

    Tolerance

    Value 20%

    Max Operating Voltage

    Value 10V

    Package

    Value SMD

    Operating Temperature Min

    Value -40C

    Operating Temperature Max

    Value 85C

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 60 of 124

  • Vese1 root

    Where for numerical dimensions indicated by letters refer to datasheet.

    Class - SMD_Capacitor_0805This kind of Capacitor is characterized by having a SMD package with standard 0805. The component shows as below:

    The capacitance value of this capacitor is C F.

    ReferencesType Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2370726

    URL http://www.farnell.com/datasheets/1132289.pdf

    Tagged ValuesManufactorer

    Value YAGEO

    Product Range

    Value YAGEO - CC Series

    Value

    Value C [F]

    Capacitance Tolerance

    Value +80%, -20%

    Dielectric

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 61 of 124

  • Vese1 rootValue Y5V

    Max. Operating Voltage

    Value 25 V

    Max. Operating Temperature

    Value 85C

    Min. Operating Temperature

    Value -30C

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Class - SMD_Capacitor_0603This kind of Capacitor is characterized by having a SMD package with standard 0603. The component shows as below:

    The capacitance value of this capacitor is C F.

    ReferencesType Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2310560

    URL http://www.farnell.com/datasheets/1792107.pdf

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 62 of 124

  • Vese1 rootTagged Values

    Manufacturer

    Value MULTICOMP

    Value

    Value C

    Capacitance Tolerance

    Value 10 %

    Dielectric

    Value X7R

    Max operative voltage

    Value 25 V

    Capacitor Case Style

    Value 0603

    Operating Temperature Min

    Value -55C

    Operating Temperature Max

    Value 125C

    Capacitor Terminals

    Value SMD

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Class - SMD_Capacitor_0402This kind of Capacitor is characterized by having a SMD package with standard 0805. The component shows as below:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 63 of 124

  • Vese1 root

    The capacitance value of this capacitor is C F.

    ReferencesType Value

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=2310495

    URL http://http://www.farnell.com/datasheets/1792107.pdf

    Tagged ValuesValue MULTICOMP

    Series

    Value MULTICOMP - MC Series

    Tolerance

    Value 5%

    Capacitance

    Value C [V]

    Dielectric

    Value C0G / NP0

    Capacitor Case Style

    Value 0402

    Max. Operative Voltage

    Value 50V

    Operating Temperature Min

    Value -55C

    Operating Temperature Max

    Value 125C

    Package

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 64 of 124

  • Vese1 rootValue SMD

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Class - CapacitorCapacitor is a reactive electrical component that can store energy in an electric field. Is is used in many applications, such as filter or decoupling. It can be packed in different mode, as shown in figure:

    Its principal electrical quantity is capacitance [F].

    OperationsSignature: A()Electrical pin of Capacitor.Signature: B()Electrical pin of Capacitor.

    Class - SMD_Resistor_0805This is a kind of Resistor characterized by having SMD package with standard 0805.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 65 of 124

  • Vese1 rootReferences

    Type Value

    URL http://www.farnell.com/datasheets/1755795.pdf

    URL http://it.farnell.com/vishay-draloric/crcw08051k00fkeahp/resistore-alimentazione-0805-1/dp/1738959

    URL http://it.farnell.com/te-connectivity/crgh0805f470r/resistore-alimentazione-470r-0/dp/2332067RL

    URL http://it.farnell.com/te-connectivity/crgh0805f330r/resistore-alimentazione-330r-0/dp/2332065RL

    URL http://it.farnell.com/te-connectivity/crgh0805f220r/resistore-alimentazione-220r-0/dp/2332063

    URL http://it.farnell.com/te-connectivity/crgh0805f100r/resistore-alimentazione-100r-0/dp/2332058

    URL http://it.farnell.com/te-connectivity/crgh0805f1k5/resistore-alimentazione-1k5-0-33w/dp/2332074

    Tagged ValuesManufactorer

    Value TE CONNECTIVITY

    Resistance Value

    Value R ohm

    Series

    Value TE CONNECTIVITY - CRG Series

    Power max.

    Value 330mW

    Resistance Tollerance

    Value 1%

    Package

    Value 0805

    Temperature Coefficient

    Value 200ppm/C

    Max. Operating Voltage

    Value 150V

    Min. Operating Temperature

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 66 of 124

  • Vese1 rootValue -55C

    Max. Operating Temperature

    Value 155C

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Class - SMD_Resistor_1206This is a kind of Resistor characterized by having SMD package with standard 1206.

    ReferencesType Value

    URL http://www.farnell.com/datasheets/1755795.pdf

    URL http://it.farnell.com/yageo-phycomp/rc1206fr-074k7l/resistore-4-7k-0-25w-1/dp/9240985

    URL http://it.farnell.com/multicomp/mc0125w12061110k/resistore-110k-0-125w-1-1206-reel/dp/2129812

    Tagged ValuesManufactorer

    Value TE CONNECTIVITY

    Resistance Value

    Value R ohm

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 67 of 124

  • Vese1 root

    Series

    Value TE CONNECTIVITY - CRG Series

    Value 330mW

    Resistance Tollerance

    Value 1%

    Package

    Value 1206

    Temperature Coefficient

    Value 200ppm/C

    Max. Operating Voltage

    Value 150V

    Min. Operating Temperature

    Value -55C

    Max. Operating Temperature

    Value 155C

    OperationsSignature: fixing()Component is soldered in surface of PCB. Its dimension is shown in following picture:

    Class - ResistorResistor is an electrical component which has R as resistance value.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 68 of 124

  • Vese1 rootOperationsSignature: a()It is an electrical pin of Resistor.Signature: b()It is an electrical pin of Resistor.

    Class - 20K_TrimmingPotentiometerThis is a trimmer potentiometer that can be also used as a variable resistor. The 20K_TrimmingPotentiometer presents between A() and B(), always 20Kohm of resistance. While the resistance that can be see between A() and W() or B() and W() is a function of angle. User exploiting a screwdriver can modify the angle value in order to change the resistance ratio

    .

    ReferencesType Value

    URL http://it.farnell.com/bourns/tc33b-1-203e/trimming-potentiometer-20k/dp/1360925

    URL http://www.farnell.com/datasheets/1520225.pdf

    Tagged ValuesManufactorer

    Value BOURNS

    Cost

    Value 0,20

    Farnell Code

    Value 1360925

    Manufactorer Code

    Value TC33B-1-203E

    Track Resistance

    Value 20kohm

    Resistance Tolerance

    Value 25%

    Temperature coeficient

    Value 250ppm/C

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 69 of 124

  • Vese1 rootMax Power

    Value 10mW

    Potentiometer Mounting

    Value SMD

    End Resistance

    Value 400ohm

    Operating Temperature Max

    Value 100C

    Operating Temperature Min

    Value -40C

    Voltage Rating max

    Value 50V

    OperationsSignature: fixing()The component has to be soldered in top layer of PCB following the distances shown below:

    Signature: A()It is the pin associated to one side of the internal resistor end.Signature: B()It is the pin associated to one side of the internal resistor end.Signature: W()Vese1.docx - 2014-02-20 - 1:20 PM Pag. 70 of 124

  • Vese1 rootIt is the pin associated to the wiper of 20K_TrimmingPotentiometer.Signature: turn(angle)User exploiting an screwdriver can change the angle value in order to change the resistance see between A()-W() and B()-W().

    Class - Connector_1x16It is a female connector for PCB which has in a row sixteen connections.

    ReferencesType Value

    URL http://it.farnell.com/samtec/bcs-116-l-s-te/contatto-2-54mm-vert-16-vie/dp/1667483

    URL http://www.farnell.com/datasheets/81213.pdf

    Tagged ValuesManufactorer

    Value SAMTEC

    Farnell code

    Value 1667483

    Manufactorer code

    Value BCS-116-L-S-TE

    Pitch Spacing

    Value 2.54mm

    N. of Rows

    Value 1

    N. of Contacts

    Value 16

    Value Through Hole Vertical

    Contact Plating

    Value gold

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 71 of 124

  • Vese1 rootContact Material

    Value Phosphor Bronze

    Max Current

    Value 3A

    External Width

    Value 5.08mm

    Lead Spacing

    Value 2.54mm

    Operating Temperature Max

    Value 125C

    Operating Temperature Min

    Value -55C

    OperationsSignature: pin1()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin2()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin3()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin4()It is a pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin5()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin6()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin7()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin8()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin9()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin10()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin11()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin12()Vese1.docx - 2014-02-20 - 1:20 PM Pag. 72 of 124

  • Vese1 rootIt is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin13()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin14()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin15()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: pin16()It is an electrical pin of connector. It can be connected with every other component through a conductive path in PCB, which starts from bottom layer.Signature: fixing()The Connector_1x16 is soldered in bottom layer following the figures shows below:

    Signature: connect()

    Class - PCBPCB is a solid and hard mechanical support realized in FR-4 on which are mounted and electrically connected (as shown in the schematic) all components. This PCB is composed by 2 layers, the SMT components are soldered in top one, while THT components in bottom layer.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 73 of 124

  • Vese1 root

    The routing view of PCB are shown below, without ground plane:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 74 of 124

  • Vese1 root

    and with ground plane in both bottom and top layers:

    A 3D-View of the PCB is also illustrated:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 75 of 124

  • Vese1 root

    AttributesSignature

    -DecouplingCapacitance_uC_1 : SMD_Capacitor_0805

    -DecouplingCapacitance_uC_2 : SMD_Capacitor_0805

    -BypassCapacitance_uC_1 : SMD_Capacitor_0603

    -BypassCapacitance_uC_2 : SMD_Capacitor_0603

    -QuartzCapacitance_1 : SMD_Capacitor_0402

    -QuartzCapacitance_2 : SMD_Capacitor_0402

    -DecouplingCapacitance_Relay : SMD_Electrolytic_Capacitor

    Class - FlatCableFlatCable is a kind of electrical cable that is both flat and flexible. It's composed by 8 wires.

    OperationsSignature: connect()This operation allows the electrical connection between 8 pins to other external 8 pins.

    Class - KeyPadKeyPad is a 4x4 key matrix, which has 8 output pins to distinguish the pressed key.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 76 of 124

  • Vese1 root

    The behavioral of this component is the following one: when the user presses a key, the component realizes a short-circuit between the correspondent column and row. For example: Pressing SW7, Col3() and Row2() are connected.

    ReferencesType Value

    URL http://www.farnell.com/datasheets/523847.pdf

    URL http://it.farnell.com/jsp/search/productdetail.jsp?id=1171224

    Tagged ValuesManufaturer

    Value APEM

    Manufacturer Part Number

    Value AC3561

    Cost

    Value 15.64

    Keypad Matrix

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 77 of 124

  • Vese1 rootValue 4x4

    Max DC Voltage

    Value 30 V

    Max Current

    Value 100 mA

    Insulation Resistance at 100V

    Value 100 M

    Max Attuation Force

    Value 400 g

    Min Operating Temperature

    Value -30 C

    Max Operating Temperature

    Value 55 C

    KeyPad Dimension

    Value 95x95 mm

    Key Diameter

    Value 0

    AttributesSignature Documentation

    -KeyPad_Cable2 : FlatCable It is a FlatCable that has one side soldered in KeyPad.

    -SW1 It is a mechanical button of KeyPad.

    -SW2 It is a mechanical button of KeyPad.

    -SW3 It is a mechanical button of KeyPad.

    -SW4 It is a mechanical button of KeyPad.

    -SW5 It is a mechanical button of KeyPad.

    -SW6 It is a mechanical button of KeyPad.

    -SW7 It is a mechanical button of KeyPad.

    -SW8 It is a mechanical button of KeyPad.

    -SW9 It is a mechanical button of KeyPad.

    -SW10 It is a mechanical button of KeyPad.

    -SW11 It is a mechanical button of KeyPad.

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 78 of 124

  • Vese1 root-SW12 It is a mechanical button of KeyPad.

    -SW13 It is a mechanical button of KeyPad.

    -SW14 It is a mechanical button of KeyPad.

    -SW15 It is a mechanical button of KeyPad.

    -SW16 It is a mechanical button of KeyPad.

    OperationsSignature: Row1()Electric terminal: normally opened and:

    shorts to Col1() when SW1 is press(SWi); shorts to Col2() when SW2 is press(SWi); shorts to Col3() when SW3 is press(SWi); shorts to Col4() when SW4 is press(SWi).

    Signature: Row2() Electric terminal: normally opened and:

    shorts to Col1() when SW5 is press(SWi); shorts to Col2() when SW6 is press(SWi); shorts to Col3() when SW7 is press(SWi); shorts to Col4() when SW8 is press(SWi).

    Signature: Row3() Electric terminal: normally opened and:

    shorts to Col1() when SW9 is press(SWi); shorts to Col2() when SW10 is press(SWi); shorts to Col3() when SW11 is press(SWi); shorts to Col4() when SW12 is press(SWi).

    Signature: Row4() Electric terminal: normally opened and:

    shorts to Col1() when SW13 is press(SWi); shorts to Col2() when SW14 is press(SWi); shorts to Col3() when SW15 is press(SWi); shorts to Col4() when SW16 is press(SWi).

    Signature: Col1()Electric terminal: normally opened and:

    shorts to Row1() when SW1 is press(SWi); shorts to Row2() when SW5 is press(SWi); shorts to Row3() when SW9 is press(SWi); shorts to Row4() when SW13 is press(SWi).

    Signature: Col2()Electric terminal: normally opened and:

    shorts to Row1() when SW2 is press(SWi); shorts to Row2() when SW6 is press(SWi); shorts to Row3() when SW10 is press(SWi); shorts to Row4() when SW14 is press(SWi).

    Signature: Col3()Electric terminal: normally opened and:

    shorts to Row1() when SW3 is press(SWi); shorts to Row2() when SW7 is press(SWi); shorts to Row3() when SW11 is press(SWi); shorts to Row4() when SW15 is press(SWi).

    Signature: Col4()Electric terminal: normally opened and:

    shorts to Row1() when SW4 is press(SWi); shorts to Row2() when SW8 is press(SWi); shorts to Row3() when SW12 is press(SWi);

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 79 of 124

  • Vese1 root shorts to Row4() when SW16 is press(SWi).

    Signature: press(SWi)User through press(SWi) operation is able to press and release the key corresponded to SWi. When SWi is pressed, the corresponding column and row are short-circuited.Signature: fixing() : voidKeyPad fixing(): void is through a sticky back surface.

    Class - MicroPIC_18F4520MicroPIC_18F4520 is a 8-bit microcontroller Manufacturer by Microchip. It has a MIPS architecture CPU that can manage his peripherals. Thanks to adc: ADC, it can be used in mixed signal systems.

    The pin nomenclature is shown in following picture, in which the order of pin and peripheral I/O can be shown:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 80 of 124

  • Vese1 root

    ReferencesType Value

    URL http://it.farnell.com/microchip/pic18f4520-i-pt/ic-mcu-8bit-pic18-40mhz-tqfp44/dp/1212703

    URL http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf

    Tagged ValuesManufacturer

    Value Microchip

    Farnell Code

    Value 1212703

    Manufacturer Code

    Value PIC18F4520-I/PT

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 81 of 124

  • Vese1 rootProgram Memory Size

    Value 32KB

    RAM Memory Size

    Value 1.5KB

    CPU Speed Max

    Value 40 MHz

    Number of I/O

    Value 36

    Case Style

    Value TQFP

    Number of Pins

    Value 44

    Embedded Interface Type

    Value EUSART, I2C, PSP, SPI

    Supply Voltage Min

    Value 4.2V

    Supply Voltage Max

    Value 5.5V

    Core Size

    Value 8bit

    EEPROM Memory Size

    Value 256Byte

    Value 0.5mm

    Number of ADC Inputs

    Value 13

    Number of PWM Channels

    Value 5

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 82 of 124

  • Vese1 rootNumber of Timers

    Value 4

    Number of bit ADC

    Value 10

    Operating Temperature Max

    Value 85C

    Operating Temperature Min

    Value -40C

    AttributesSignature

    -PortA : ParallelPortA

    -PortB : ParallelPortB

    -PortC : ParallelPortC

    -PortD : ParallelPortD

    -PortE : ParallelPortE

    -adc : ADC

    -I2C : I2C_Port_Master

    OperationsSignature: fix()MicroPIC_18F4520 has to be fixed on the surface of PCB as shown in figure:

    In which the distance are:

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 83 of 124

  • Vese1 root

    Class - Automatic_Watering_SystemAttributes

    Signature Documentation

    -AutoStatus : unsigned char It's the variable which indicates if the Automatic_Watering_System is in active status or not. If:

    equal to 0, Automatic system OFF; equal to 1, Automatic system ON.

    -HumidityTH : unsigned char This attribute indicates the value of moisture threshold. If the humidity of soil is lower than HumidityTH: unsigned char, the Automatic_Watering_System has to start the irrigation at given hour. Otherwise the Automatic_Watering_System is stalled.

    -Minutes_Alarm_On : unsigned char

    -Minutes_Alarm_Off : unsigned char

    -Hours_Alarm_On : unsigned char

    -Hours_Alarm_Off : unsigned char

    OperationsSignature: main() : voidThis function is the core of whole system. It's implements the finite state machine which allows the User to control the Automatic_Watering_SystemCode Body: //variableunsigned char key = 20;float moisture = 0;unsigned char TempHours1 = 20; //contains the temp value of hour's tensunsigned char TempHours2 = 20; //contains the temp value of hour's unitunsigned char TempMinutes1 = 20; //contains the temp value of minute's tensunsigned char TempMinutes2 = 20; //contains the temp value of minute's tensunsigned char TempHumidity1 = 20;//contains the temp value of humidity's tensunsigned char TempHumidity2 = 20;//contains the temp value of humidity's tens

    //I impost the direction of each pin driverIn_PortA(0xFF);driverIn_PortB(0x8F);driverIn_PortC(0x7F);driverIn_PortD(0x8F);driverIn_PortE(0xFF);

    //ADC initializationinit_ADC();TurnON_ADC();

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 84 of 124

  • Vese1 root

    //LCD initializationOpen_LCD();Clear_LCD();

    //Enable PortB interruptenableInterrupt_PortB();

    //I2C initializationOpenI2C();

    //Turn-on the alarm generated by RTCCenableAlarm_RTCC();//Turn-on the displayOpen_LCD();WriteString_LCD("Welcome to");Line_LCD(2);WriteString_LCD("Automatic Watering");Line_LCD(3);WriteString_LCD("Systems");

    __delay_ms(250);__delay_ms(250);__delay_ms(250);__delay_ms(250);

    int stato = 0

    while(1){

    switch(stato){

    case 0 : /* Show the Home*/Clear_LCD();WriteString_LCD("A : Start Watering");Line_LCD(2);WriteString_LCD("B : Stop Watering");Line_LCD(3);WriteString_LCD("C : View Menu");Line_LCD(4);WriteString_LCD("D : Show T/H");key = readPressedButton();while (key == 20){

    key = readPressedButton();}switch(key()){

    case 10 ://If I press A (10) then the irrigation is activatedstato = 1;break;

    case 11 ://If I press B (11) then the irrigation is deactivatedstato = 2;break;

    case 12 ://If I press C (12) then I'll see the control menustato = 3;break;

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 85 of 124

  • Vese1 root

    case 13 ://If I press D (13) then I'll see the humidity vale and temperature onestato = 4;break;

    default ://se non premo nulla o altro resto nel mio stato inizialestato = 0;break;

    }

    case 1 ://Avvio il sistema di irrigazione, nel display nulla cambia, solo il//led della rete di condizionamento del relay si accendeif(!readStatus_Relay()) //prima controllo che il sistema sia spento

    changeState_Relay(); //se spento lo accendostato = 0; //ritorno allo stato di partenzabreak;

    case 2://Spegnimento del sistema di irrigazione, nel display nulla cambia, solo il//led della rete di condizionamento del relay si spegneif(readStatus_Relay()) //prima controllo che il sistema sia acceso

    changeState_Relay(); //se acceso lo spengostato = 0; //ritorno allo stato di partenzabreak;

    case 3://Sono nel sistema che controlla l'irrigazione automaticaClear_LCD();WriteString_LCD("A : Set Time");Line_LCD(2);WriteString_LCD("B : Auto. Sys. OnOff");Line_LCD(3);WriteString_LCD("C : Settings");Line_LCD(4);WriteString_LCD("D : Moisture Th");key = readPressedButton();while (key == 20){

    key = readPressedButton();}switch(key()){

    case 10 ://se premo A (10) allora si passa al setting del timestato = 5;break;

    case 11 ://se premo B (11) allora si spegne o si accende il sistema di irrigazione

    automaticostato = 6;break;

    case 12 ://se premo C (12) allora vado a visualizzare il menu delle impostazionistato = 7;break;

    case 13 ://se premo D (13) allora vado set humidity th.stato = 8;

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 86 of 124

  • Vese1 rootbreak;

    case 15 ://se premo il cancelletto (15) allora torno al menu di homestato = 0;break;

    default ://se non premo nulla o altro resto nel mio stato stato = 3;break;

    }

    case 4://Vado a visualizzare l'umidit e la temperaturaClear_LCD(); //pulisco l'LCDWriteString_LCD("Moisture :");Line_LCD(2);moisture = readMoisture();WriteString_LCD(Moisture);Line_LCD(3);WriteString_LCD("Temperature :");Line_LCD(4);ShowTemperature_DS18B20();key = readPressedButton();while (key == 20){

    key = readPressedButton();}//Controllo che sia stato o meno premuto il cancelletto (15)if(key() = 15)

    stato = 0;else

    stato = 4;break;

    case 5://setting del timeClear_LCD();WriteString_LCD("Setting Time");Line_LCD(2);WriteString_LCD("HH:MM");Line_LCD(2); //shift the cursor to the begin of the rowTempHours1 = readPressedButton();while(TempHours1 == 20) //ciclo while serve per aspettare che l'utente{ //scriva qualche numero, nota, la funzione di

    read torna TempHours1 = readPressedButton(); //20 quando non si preme nulla

    }if(TempHours1 == 15) //controllo che non sia stato cliccato il cancelletto{

    stato = 3;break;

    }WritheChar_LCD(TempHours1);TempHours2 = readPressedButton();while(TempHours2 == 20){

    TempHours2 = readPressedButton();}if(TempHours2 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 3;break;

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 87 of 124

  • Vese1 root}WritheChar_LCD(TempHours2);TempMinutes1 = readPressedButton();while(TempMinutes1 == 20){

    TempMinutes1 = readPressedButton();}if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 3;break;

    }WritheChar_LCD(TempMinutes1);TempMinutes2 = readPressedButton();while(TempMinutes2 == 20){

    TempMinutes2 = readPressedButton();}if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 3;break;

    }WritheChar_LCD(TempMinutes2);// una volta ricevuti i dati vado a settare l'ora e i minutiTempHours1 = (TempHours1

  • Vese1 rootcase 15 :

    stato = 3;break;

    default :stato = 6;break;

    }case 7:

    //menu delle impostazioniClear_LCD();WriteString_LCD("A :Watering Time");Line_LCD(2);WriteString_LCD("B :Watering Duration");key = readPressedButton();while (key == 20){

    key = readPressedButton();}switch(key()){

    case 10 :stato = 11;break;

    case 11 :stato = 12;break;

    case 15 :stato = 3;break;

    default :stato = 7;break;

    }

    case 8://set humidity th.Clear_LCD();WriteString_LCD("Setting Moisture");Line_LCD(2);WriteString_LCD("HH %");Line_LCD(2); //shift the cursor to the begin of the rowTempHumidity1 = readPressedButton();while(TempHumidity1 == 20) //ciclo while serve per aspettare che l'utente{ //scriva qualche numero, nota, la funzione di

    read torna TempHumidity1 = readPressedButton(); //20 quando non si preme nulla

    }if(TempHumidity1 == 15) //controllo che non sia stato cliccato il cancelletto{

    stato = 3;break;

    }WritheChar_LCD(TempHumidity1);TempHumidity2 = readPressedButton();while(TempHumidity2 == 20){

    TempHumidity2 = readPressedButton();}if(TempHumidity2 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 3;break;

    }

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 89 of 124

  • Vese1 rootWritheChar_LCD(TempHumidity2);TempHumidity1 = (TempHumidity1 > 4) * 10) + (TempHumidity1 & 0x0F); // now humidity

    threshold is stored in HumidityTH in decimal formLine_LCD(4);WriteString_LCD("Set! ");WriteInt_LCD(HumidityTH,2);WriteChar_LCD('%');while(readPressedButton()!=15);stato = 3;break;

    case 9://attivo il sistema automaticoAutoStatus = 1;Line_LCD(4);WriteString_LCD("Status ON");__delay_ms(250); //one second of delay __delay_ms(250);__delay_ms(250);__delay_ms(250);stato = 6;break;

    case 10://disattivo il sistema automaticoAutoStatus = 0;Line_LCD(4);WriteString_LCD("Status OFF");__delay_ms(250); //one second of delay__delay_ms(250);__delay_ms(250);__delay_ms(250);stato = 6;break;

    case 11://Set Watering TimeClear_LCD();WriteString_LCD("Watering Time");Line_LCD(2);WriteString_LCD("HH:MM");Line_LCD(2); //shift the cursor to the begin of the rowTempHours1 = readPressedButton();while(TempHours1 == 20) //ciclo while serve per aspettare che l'utente{ //scriva qualche numero, nota, la funzione di

    read torna TempHours1 = readPressedButton(); //20 quando non si preme nulla

    }if(TempHours1 == 15) //controllo che non sia stato cliccato il cancelletto{

    stato = 7;break;

    }WritheChar_LCD(TempHours1);TempHours2 = readPressedButton();while(TempHours2 == 20){

    TempHours2 = readPressedButton();}if(TempHours2 == 15) //controllo che non sia stato premuto il cancelletto

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 90 of 124

  • Vese1 root{

    stato = 7;break;

    }WritheChar_LCD(TempHours2);TempMinutes1 = readPressedButton();while(TempMinutes1 == 20){

    TempMinutes1 = readPressedButton();}if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 7;break;

    }WritheChar_LCD(TempMinutes1);TempMinutes2 = readPressedButton();while(TempMinutes2 == 20){

    TempMinutes2 = readPressedButton();}if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 7;break;

    }WritheChar_LCD(TempMinutes2);// una volta ricevuti i dati vado a settare l'ora e i minutiHours_Alarm_On = (TempHours1

  • Vese1 root{

    stato = 7;break;

    }WritheChar_LCD(TempHours2);TempMinutes1 = readPressedButton();while(TempMinutes1 == 20){

    TempMinutes1 = readPressedButton();}if(TempMinutes1 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 7;break;

    }WritheChar_LCD(TempMinutes1);TempMinutes2 = readPressedButton();while(TempMinutes2 == 20){

    TempMinutes2 = readPressedButton();}if(TempMinutes2 == 15) //controllo che non sia stato premuto il cancelletto{

    stato = 7;break;

    }WritheChar_LCD(TempMinutes2);// una volta ricevuti i dati vado a settare l'ora e i minutiHours_Alarm_Off = (TempHours1

  • Vese1 rootif(moisture < ((float) HumidityTH) //if it is lower than TH{

    changeState_Relay(); //turn-on the irrigationsetHours_Alarm_RTCC(Hours_Alarm_Off);setMinutes_Alarm_RTCC(Minutes_Alarm_Off);

    }}

    }

    }enableInterrupt_PortB();clearInterrupt_PortB();

    }

    Automatic_Watering_System

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 93 of 124

  • Vese1 root

    MicroPIC_18F4520

    Class - ParallelPortCParallelPortC is a ParallelPort which has the following operations:

    driverIn_PortC(pins: unsigned char): void, to decide the direction of each pin belonging to ParallelPortC itself. read_PortC(pin: unsigned char): unsigned char, to read the logic value provided as an input of a specificpinof ParallelPortC

    itself. write_PortC(pin: unsigned char, pinStatus: unsigned char): void, to write in the specified pin the value indicates by pinStatus

    OperationsSignature: driverIn_PortC(pins : unsigned char) : voidSets pin direction of ParallelPortC to be input. Each bit of argument pins is associated with a pin of the ParallelPortC; bit 0/1/2.. of pins corresponds with bit 0/1/2... of ParallelPortC respectively. The pin is set to input if the corresponding bit of pins is set to 1; outputotherwise.Code Body: TRISC = bits;Signature: read_PortC(pin : unsigned char) : unsigned charReturns 1 (respectively, 0) if the value of the pin, whose index (0 to 7) is given by argument pin, is 1 (respectively 0).Code Body: switch(pin){

    case 0 :return PORTCbits.RC0;break;

    case 1 :Vese1.docx - 2014-02-20 - 1:20 PM Pag. 94 of 124

  • Vese1 rootreturn PORTCbits.RC1;break;

    case 2 :return PORTCbits.RC2;break;

    case 3 :return PORTCbits.RC3;break;

    case 4 :return PORTCbits.RC4;break;

    case 5 :return PORTCbits.RC5;break;

    case 6 :return PORTCbits.RC6;break;

    case 7 :return PORTCbits.RC7;break;

    }Signature: write_PortC(pin : unsigned char, pinStatus : unsigned char) : voidWrite the value of pinStatus on pinCode Body: switch(pin){

    case 0 :PORTCbits.RC0 = pinStatus;break;

    case 1 :PORTCbits.RC1 = pinStatus;break;

    case 2 :PORTCbits.RC2 = pinStatus;;break;

    case 3 :PORTCbits.RC3 = pinStatus;;break;

    case 4 :PORTCbits.RC4 = pinStatus;;break;

    case 5 :PORTCbits.RC5 = pinStatus;;break;

    case 6 :PORTCbits.RC6 = pinStatus;;break;

    case 7 :PORTCbits.RC7 = pinStatus;;break;

    }

    Class - ParallelPortEParallelPortE is a ParallelPort which has the following operations:

    driverIn_PortE(pins: unsigned char): void, to decide the direction of each pin belonging to ParallelPortE itself. read_PortE(pin: unsigned char): unsigned char, to read the logic value provided as an input of a specific pin of ParallelPortE

    itself. write_PortE(pin: unsigned char, pinStatus: unsigned char): void, to write in the specified pin the value indicates by pinStatus

    OperationsSignature: driverIn_PortE(pins : unsigned char) : void

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 95 of 124

  • Vese1 rootSets pin direction of ParallelPortE to be input. Each bit of argument pins is associated with a pin of the ParallelPortE; bit 0/1/2.. of pins corresponds with bit 0/1/2... of ParallelPortE respectively. The pin is set to input if the corresponding bit of pins is set to 1; outputotherwise.Code Body: TRISE = bits;Signature: read_PortE(pin : unsigned char) : unsigned charReturns 1 (respectively, 0) if the value of the pin, whose index (0 to 7) is given by argument pin, is 1 (respectively 0).Code Body: switch(pin){

    case 0 :return PORTEbits.RE0;break;

    case 1 :return PORTEbits.RE1;break;

    case 2 :return PORTEbits.RE2;break;

    case 3 :return PORTEbits.RE3;break;

    case 4 :return PORTEbits.RE4;break;

    case 5 :return PORTEbits.RE5;break;

    case 6 :return PORTEbits.RE6;break;

    case 7 :ereturn PORTEbits.RE7;break;

    }Signature: write_PortE(pin : unsigned char, pinStatus : unsigned char) : voidWrite the value of pinStatus on pinCode Body: switch(pin){

    case 0 :PORTEbits.RE0 = pinStatus;break;

    case 1 :PORTEbits.RE1 = pinStatus;break;

    case 2 :PORTEbits.RE2 = pinStatus;;break;

    case 3 :PORTEbits.RE3 = pinStatus;;break;

    case 4 :PORTEbits.RE4 = pinStatus;;break;

    case 5 :PORTEbits.RE5 = pinStatus;;break;

    case 6 :PORTEbits.RE6 = pinStatus;;break;

    case 7 :PORTEbits.RE7 = pinStatus;;break;

    }

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 96 of 124

  • Vese1 rootClass - ParallelPortDParallelPortD is a ParallelPort which has the following operations:

    driverIn_PortD(pins: unsigned char): void, to decide the direction of each pin belonging to ParallelPortD itself. read_PortD(pin: unsigned char): unsigned char, to read the logic value provided as an input of a specific pin of ParallelPortD

    itself. write_PortD(pin: unsigned char, pinStatus: unsigned char): void, to write in the specified pin the value indicates by pinStatus

    OperationsSignature: driverIn_PortD(pins : unsigned char) : voidSets pin direction of ParallelPortD to be input. Each bit of argument pins is associated with a pin of the ParallelPortD; bit 0/1/2.. of pins corresponds with bit 0/1/2... of ParallelPortD respectively. The pin is set to input if the corresponding bit of pins is set to 1; outputotherwise.Code Body: TRISD = bits;Signature: read_PortD(pin : unsigned char) : unsigned charReturns 1 (respectively, 0) if the value of the pin, whose index (0 to 7) is given by argument pin, is 1 (respectively 0).Code Body: switch(pin){

    case 0 :return PORTDbits.RD0;break;

    case 1 :return PORTDbits.RD1;break;

    case 2 :return PORTDbits.RD2;break;

    case 3 :return PORTDbits.RD3;break;

    case 4 :return PORTDbits.RD4;break;

    case 5 :return PORTDbits.RD5;break;

    case 6 :return PORTDbits.RD6;break;

    case 7 :return PORTDbits.RD7;break;

    }Signature: write_PortD(pin : unsigned char, pinStatus : unsigned char) : voidWrite the value of pinStatus on pinCode Body: switch(pin){

    case 0 :PORTDbits.RD0 = pinStatus;break;

    case 1 :PORTDbits.RD1 = pinStatus;break;

    case 2 :PORTDbits.RD2 = pinStatus;;break;

    case 3 :PORTDbits.RD3 = pinStatus;;break;

    case 4 :PORTDbits.RD4 = pinStatus;;break;

    case 5 :

    Vese1.docx - 2014-02-20 - 1:20 PM Pag. 97 of 124

  • Vese1 rootPORTDbits.RD5 = pinStatus;;break;

    case 6 :PORTDbits.RD6 = pinStatus;;break;

    case 7 :PORTDbits.RD7 = pinStatus;;break;

    }

    Class - ParallelPortAParallelPortA is a ParallelPort which has the following operations:

    driverIn_PortA(pins: unsigned char): void, to decide the direction of each pin belonging to ParallelPortA itself. read_PortA(pin: unsigned char): unsigned char, to read the logic value provided as an input of a specific pin of ParallelPortA

    itself. write_PortA(pin: unsigned char, pinStatus: unsigned char): void, to write in the specified pin the value indicates by pinStatus

    OperationsSignature: dr