[SOLVED] PIC Design, State of Madness, Mayhem, Trauma

Status
Not open for further replies.
Well,,

Last night i had spent it all soldering this circuit
This is the second or third time i do solder
An open wire circuit for such system is very mutable

Here ive been told to do soldering from betinning but i handt fot
The guts to do it


When finished it worked at first attempt
The system is more livable than it was
It was dying and tend to freeZe and resets


Now it is very ok working all up


The sensors reading to light and moisture are accurate and changes
When input changes

The only problem left is reading from lm35dz
It gives values of temp from 124 to 230 as maximum

Here the temperature is of 23 degree C

I just need to correct temp reading
Also the voltage residue from adc channels is still a problem
Because when i increase only light also the temperature
Increases and light increases too

When i increase moisture by placing soil moisture sensor inside a cup of water other variables increases too


Ive made a delay between reading from channel to another

Should i increase that delay (of 1 mS)
Or ?

- - - Updated - - -

Here is the pre-final circuit

- - - Updated - - -

To note: i am connecting a 1k resistor with the lm35dz output
 

Attachments

  • image.jpg
    1.9 MB · Views: 152

Nice job man. The picture looks very clean. There is a difference between PCBs and breadboards. Ohhhhhh snap.... were you using an external osc on a bread board. I dont recommend that unless you hate yourself or just looking for a really bad time. The capacitance in the bread board can cause a crazy drift in the frequencies. (From what I am told. My guess is it depends on the breadboard.) PICs do not like frequency changes, they can take small variation every now and then. But overall it causes...problems.

The LM35 outputs 10mV per degree of Celsius. A +5V system with 10 bit adc would mean:
((5/1024)*(reading))/0.01 or (0.00488*(reading))/0.01 or 0.488*(reading)

so 124 = 60.5 and 230 = 112.2

I am not sure why you have the 1K resistor, have you tried it without it? Try increasing your TAD multiplier.
 
I suggested 100 Ohms in series with the LM35 output in conjunction with 100nF to work as an LPF while the long wiring was in use, 1K is probably OK but pushing the limit before the ADC gets starved of input current.

The inputs interacting with each other can only be two things - either the voltages really are changing outside the PIC or the ADC S/H isn't adapting fast enough inside the PIC. I would go with the ADC timing as most likely. Can you post the code for the ADC channel selection and the ADC routine please.

.... and congratulations on getting 99% of the way there!

Brian.
 

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
BSF ADCON2,ADFM
        CLRF R0L
        CALL A001
        MOVF ADRESL,W
        MOVWF 0x047
        MOVF ADRESH,W
        MOVWF 0x048
        CLRF 0x049
        CLRF 0x04A
        MOVF 0x047,W
        MOVWF AARGB3
        MOVF 0x048,W
        MOVWF AARGB2
        MOVF 0x049,W
        MOVWF AARGB1
        MOVF 0x04A,W
        MOVWF AARGB0
        CALL FLO3232
        MOVF AARGB2,W
        MOVWF 0x053
        MOVF AARGB1,W
        MOVWF 0x054
        MOVF AARGB0,W
        MOVWF 0x055
        MOVF AEXP,W
        MOVWF 0x056
        CLRF BARGB2
        CLRF BARGB1
        MOVLW 0x20
        MOVWF BARGB0
        MOVLW 0x81
        MOVWF BEXP
        MOVF 0x053,W
        MOVWF AARGB2
        MOVF 0x054,W
        MOVWF AARGB1
        MOVF 0x055,W
        MOVWF AARGB0
        MOVF 0x056,W
        MOVWF AEXP
        CALL FPM32
        MOVF AARGB2,W
        MOVWF 0x03B
        MOVF AARGB1,W
        MOVWF 0x03C
        MOVF AARGB0,W
        MOVWF 0x03D
        MOVF AEXP,W
        MOVWF 0x03E
        CLRF BARGB2
        MOVLW 0xC0
        MOVWF BARGB1
        MOVLW 0x7F
        MOVWF BARGB0
        MOVLW 0x88
        MOVWF BEXP
        MOVF 0x03B,W
        MOVWF AARGB2
        MOVF 0x03C,W
        MOVWF AARGB1
        MOVF 0x03D,W
        MOVWF AARGB0
        MOVF 0x03E,W
        MOVWF AEXP
        CALL FPD32
        MOVF AARGB2,W
        MOVWF 0x03B
        MOVF AARGB1,W
        MOVWF 0x03C
        MOVF AARGB0,W
        MOVWF 0x03D
        MOVF AEXP,W
        MOVWF 0x03E
        MOVF 0x03B,W
        MOVWF 0x057
        MOVF 0x03C,W
        MOVWF 0x058
        MOVF 0x03D,W
        MOVWF 0x059
        MOVF 0x03E,W
        MOVWF 0x05A
        CLRF BARGB2
        CLRF BARGB1
        MOVLW 0x48
        MOVWF BARGB0
        MOVLW 0x85
        MOVWF BEXP
        MOVF 0x057,W
        MOVWF AARGB2
        MOVF 0x058,W
        MOVWF AARGB1
        MOVF 0x059,W
        MOVWF AARGB0
        MOVF 0x05A,W
        MOVWF AEXP
        CALL FPM32
        MOVF AARGB2,W
        MOVWF 0x035
        MOVF AARGB1,W
        MOVWF 0x036
        MOVF AARGB0,W
        MOVWF 0x037
        MOVF AEXP,W
        MOVWF 0x038
        CLRF BARGB2
        CLRF BARGB1
        CLRF BARGB0
        MOVLW 0x80
        MOVWF BEXP
        MOVF 0x035,W
        MOVWF AARGB2
        MOVF 0x036,W
        MOVWF AARGB1
        MOVF 0x037,W
        MOVWF AARGB0
        MOVF 0x038,W
        MOVWF AEXP
        CALL FPD32
        MOVF AARGB2,W
        MOVWF 0x035
        MOVF AARGB1,W
        MOVWF 0x036
        MOVF AARGB0,W
        MOVWF 0x037
        MOVF AEXP,W
        MOVWF 0x038
        CLRF BARGB2
        CLRF BARGB1
        MOVLW 0x20
        MOVWF BARGB0
        MOVLW 0x83
        MOVWF BEXP
        MOVF 0x035,W
        MOVWF AARGB2
        MOVF 0x036,W
        MOVWF AARGB1
        MOVF 0x037,W
        MOVWF AARGB0
        MOVF 0x038,W
        MOVWF AEXP
        CALL FPS32
        MOVF AARGB2,W
        MOVWF 0x035
        MOVF AARGB1,W
        MOVWF 0x036
        MOVF AARGB0,W
        MOVWF 0x037
        MOVF AEXP,W
        MOVWF 0x038





such that the adc input routine to the pic goes like:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
RLCF R0L,F
        RLCF R0L,F
        MOVLW 0x80
        ANDWF ADCON2,F
        MOVLW 0x3C
        ANDWF R0L,W
        IORLW 0x01
        MOVWF ADCON0
        MOVLW 0x03
        IORWF ADCON2,F
        MOVLW 0x12
        MOVWF R4L
        RCALL DL01
        BSF ADCON0,GO
A002:   BTFSC ADCON0,GO
        BRA A002
        BCF PIR1,ADIF
        BCF ADCON0,ADON
        RETURN




and such that:



Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
R0L EQU 0x000
        R0H EQU 0x001
        R1L EQU 0x002
        R1H EQU 0x003
        R2L EQU 0x004
        R2H EQU 0x005
        R3L EQU 0x006
        R3H EQU 0x007
        R4L EQU 0x008
        R4H EQU 0x009
        R5L EQU 0x00A
        R5H EQU 0x00B
        R6L EQU 0x00C
        R6H EQU 0x00D
        R7L EQU 0x00E
        R7H EQU 0x00F
        R8H EQU 0x011
        R9L EQU 0x012
        R9H EQU 0x013
        R0HL EQU 0x000
        R1HL EQU 0x002
        R2HL EQU 0x004
        R3HL EQU 0x006
        R4HL EQU 0x008
        R5HL EQU 0x00A
        R6HL EQU 0x00C
        R7HL EQU 0x00E
        R9HL EQU 0x012
        R1HL0HL EQU 0x000
        R3HL2HL EQU 0x004
        R5HL4HL EQU 0x008
        R7HL6HL EQU 0x00C
        AARGB5 EQU 0x014
        AARGB4 EQU 0x015
        AARGB3 EQU 0x016
        AARGB2 EQU 0x017
        AARGB1 EQU 0x018
        AARGB0 EQU 0x019
        AEXP EQU 0x01A
        BARGB3 EQU 0x01B
        BARGB2 EQU 0x01C
        BARGB1 EQU 0x01D
        BARGB0 EQU 0x01E
        BEXP EQU 0x01F
        TEMPB1 EQU 0x020
        TEMPB0 EQU 0x021
        SIGN EQU 0x022
        FPFLAGS EQU 0x023



- - - Updated - - -

note that the LM35DZ, (which is the only sensor that is outputting wrong data) is connected (its output) to 1k, and both of its terminals Vss and Vdd are connected across an electrolytic 0.1 uF
 
Last edited by a moderator:

Try removing the 1K resistor. Also to prevent the bleeding you need to increase the acquisition time this can be done by increasing TAD multiple and/or by selecting a higher clock divider. There is a capacitor that needs to charge to the input channels voltage level. If this capacitor is not fully charged you can get false reading. Since there is only one adc (or one charge capacitor) you current acquisition time may not allow enough time for the voltage in the capacitor to fully stabilize at the current input channels voltage and not the previous input channels voltage.
 
Yes. Not by calling a delay function. You need to tell the adc to wait. The acquisition time is how you talk to it. It looks at the adc clock and TAD multiple. Pick dumb values like 32 for the clock and 20 for the TAD. This will create massive delay. If it works you know you need to recalculate acquisition timing values.
 

But this would make me wait infront of the LCD, in real world, before I can get to read the values, isn't?
 

ok, thanks


any ideas how to desig a template for a poster showing this project before representing it to the committee ????

- - - Updated - - -

I should fill here with some photos, and attractive expressions
 

Attachments

  • Poster.jpg
    29.8 KB · Views: 115

I'm guessing the code you posted isn't written by yourself. It looks to be the output of a compiler, the original source would be far more useful. What language/compiler are your writing it in?

Expanding on what Bluelasers told you, this is the program flow you should folow:

1. select the ADC input
2. delay for a short time <<-- this is a delay you add yourself to allow the ADC input to adapt to the new voltage
3. start the ADC conversion
4. wait for the ADC to signal it has finished <<-- this delay is decided by the clock source to the ADC inside the PIC
5. read the ADC result.

I suspect the delay in step 2 is the problem, if you don't allow long enough, the voltage from the previous analog input will influence the present measurement, in other words one measurement will change the measurment on another which is what you reported.

In step 4, if the ADC clock is too fast, the measurement will be inaccurate but it should not make the inputs influence each other. Making it slower than necessary is not harmful but will slow your program slightly as the wait for the ADC result will take longer. Note that even with a slow ADC clock, the result will still be returned quickly, I doubt it would have any visible effect on the rest of the program.

Brian.
 

how to design its poster

- - - Updated - - -

What is the best topic describing it?
 

I did increase the delay:

Before each and after adc process times two and three and even five time than it was



Same thing, an input affect the other:

Light is maximized: temperature elevates also moisture knowing that there isn't any changes in temperature or moisture..




Should i leave it like this? Or any more trick to make?
 

This should not happen and it looks like a software problem. Can you post the SOURCE code for the ADC routines please - not the assembly listing and show which part of the code you tried changing already.

Brian.
 

Have you changed the acquisition time? Add a delay may not help. You need to change the adc clock and tad multiplier.

What is the processor you are using? What speed is it running at? Are you using PLL?

- - - Updated - - -

Have you checked to make sure there is not a solder bridge?
 

PIC18F4520
I`m using a compiler: PIC18 IDE Basic Simulator

the ADC process, has a keyword of "adcin (number of pin of PORTa),(Variable)"

- - - Updated - - -

the delay in it, has a keyword of:

WaitMs xxxx

so I had increased, it before adcin, and after adcin

- - - Updated - - -

visit www.oshonsoft.com and see the compiler
it is a powerful tool , I do not know if you know it before, but it summarize much work, and has pre-defined functions

- - - Updated - - -

see help section of : ADCIN
 

where is you setup code for the adc? adcin is read function. the problem you are experiencing is more than likely due to the fact the adc is not configured correctly.
 

how to configure it correctly?

i will send you a private email about how, and you post it here, i do not know how to use CODE tags here, i dont want to be banned lol
 

I have licensed copies of all the Oshonsoft compilers here so if you post the source code I can simulate it and see what is wrong. The file we need to see is the .BAS listing not the assembly listing. Either attach the whole .BAS file by clicking on "Manage Attachments" below the message window then uploading it, or highlight the lines in the Oshonsoft BASIC editor window, copy them then paste them into Edaboard's message window.

When in the message window you can either highlight it all again then click on the "#" symbol in the banner above the message or you can manually type the word CODE between [ and ] at the start of the listing and /CODE between [ and ] to end it. For obvious reasons I can't do it in this message because it would switch to code listing mode! Do not leave any spaces between the [ and ] characters and the words CODE and /CODE. Note that you can continue with normal message text after closing the code section.

All the code tags do is stop the message editor from stripping out tabs and extra spaces at the beginnings of the lines so it looks like it did in the original program.

Brian.
 

#
Code:
testing 12 testing 12 testing 12

- - - Updated - - -

#
Code:
ASM:        org 0x800
Define LCD_BITS = 8  'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTD
Define LCD_DBIT = 0  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 3
Define LCD_RWREG = PORTB  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 2  'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
Lcdinit 0  'initialize LCD module; cursor is blinking
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim code As Word

Dim tempdig As Long
Dim tempan As Single

Dim lightdig As Long
Dim lightan As Single

Dim soildig As Long
Dim soilan As Single

Dim k As Single
Dim kk As Single
Dim kkk As Single

Dim k1 As Single
Dim kk1 As Single
Dim kkk1 As Single

Dim k2 As Single
Dim kk2 As Single
Dim kkk2 As Single

Dim i As Byte
Dim accuratetemp As Single
Dim accuratetempp As Single


ConfigPin PORTA = Input
ADCON1 = 0
ADCON2 = 0xbe

main:
		Lcdcmdout LcdClear
		Lcdout "System ACTIVATED"
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdcmdout LcdLine2Home
		Lcdout "System ACTIVATED"
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdcmdout LcdLine1Home
		Lcdout "System ACTIVATED"
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdout "Welcome To The Automated Green House"
		Lcdcmdout LcdLine2Home
		Lcdout "VERSION: 1.0.0"
		WaitMs 2200
		Lcdcmdout LcdClear
		Lcdout "We are controlling three plants: "
		Lcdcmdout LcdLine2Home
		Lcdout "Potatoes / Tomatoes / Gardenia"
		WaitMs 2000
		Lcdcmdout LcdClear
		Lcdout "!!NOTE!!           "
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdout "                 !!NOTE!!           "
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdout "                             !!NOTE!!"
		WaitMs 750
		Lcdcmdout LcdClear
		Lcdout "Press the RED push-button to stop"
		Lcdcmdout LcdLine2Home
		Lcdout "Monitoring and start to Harvest."
		WaitMs 2000
here:
		Lcdcmdout LcdClear
		Lcdout "Please choose from the following menu:"
		Lcdcmdout LcdLine2Home
		Lcdout "1.Potatoes 2.Tomatoes 3.Gardenia"
				
		
idiot:
		If PORTC.3 Then
		High PORTB.0
		Lcdcmdout LcdClear
		Lcdout "You Cannot harvest, unpress push-button"
		WaitMs 750
		Lcdcmdout LcdLine2Home
		Lcdout "To Choose your plant first:"
		WaitMs 750
		Goto idiot
		Else
		Low PORTB.0
		Goto readcode
		Endif
				

readcode:
				WaitMs 1000

				If PORTC.3 Then
				High PORTB.0
				Lcdcmdout LcdClear
				Lcdout "You Cannot harvest, unpress push-button"
				WaitMs 750
				Lcdcmdout LcdLine2Home
				Lcdout "To Choose your plant first:"
				WaitMs 750
				Low PORTB.0
				Goto idiot
				Endif

		High PORTC.0
		
		If PORTC.4 = 1 Then
			Lcdcmdout LcdClear
			Lcdout "Your choice is: 1"
			Lcdcmdout LcdLine2Home
			WaitMs 1500
			Gosub potatoes
			Endif
			
									
			If PORTC.5 = 1 Then
			code = code * 10 + 4
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
			
	
			If PORTC.6 = 1 Then
			code = code * 10 + 7
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 150
			Low PORTB.0
			Goto readcode
			Endif
			
				
			If PORTC.7 = 1 Then
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
		
		Low PORTC.0
		
	
		High PORTC.1
		
			If PORTC.4 = 1 Then
			code = code * 10 + 2
			Lcdcmdout LcdClear
			Lcdout "Your Choice is: 2"
			WaitMs 1500
			Gosub tomatoes
			Endif
		
			If PORTC.5 = 1 Then
			code = code * 10 + 5
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			Low PORTB.0
			WaitMs 1500
			Goto readcode
			Endif
		
			If PORTC.6 = 1 Then
			code = code * 10 + 8
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
		
			If PORTC.7 = 1 Then
			code = code * 10 + 0
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
		
		Low PORTC.1


		High PORTC.2
		
			If PORTC.4 = 1 Then
			code = code * 10 + 3
			Lcdcmdout LcdClear
			Lcdout "Your Choice is: 3"
			WaitMs 1300
			Gosub gardenia
			Endif
						
			If PORTC.5 = 1 Then
			code = code * 10 + 6
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
		
			If PORTC.6 Then
			code = code * 10 + 9
			Lcdcmdout LcdClear
			High PORTB.0
			Lcdout "      !WRONG ENTRY! "
			Lcdcmdout LcdLine2Home
			Lcdout "       TRY AGAIN: "
			WaitMs 1500
			Low PORTB.0
			Goto readcode
			Endif
		
				
		Low PORTC.2
		Goto readcode

		Goto main
End                                               

potatoes:
			If PORTC.3 Then
			Lcdcmdout LcdClear
			Low PORTB.4
			Low PORTB.5
			Low PORTB.6
			Low PORTB.7
			Lcdout "You have chosen to harvest the: POTATOES"
			Lcdcmdout LcdLine2Home
			Lcdout "Choose Another plant(1/2/3), or turn off"
			WaitMs 2000
			Goto here
			Endif
			
		Lcdcmdout LcdClear
		Lcdout "Testing POTATOES Plant..."
		WaitMs 1500
		Lcdcmdout LcdClear
		Lcdout "The POTATOES Plant has the following: "
		Lcdcmdout LcdLine2Home
		Lcdout "(Scanning in Progress...)"
		WaitMs 1300
		

ok1:
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdcmdout LcdClear
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif
				
				
		i = 0
		accuratetemp = 0
		
		acctemp:
		WaitMs 1500
		
		If i < 10 Then
		
		Adcin 0, tempdig
		
		WaitMs 1000
		
		k = tempdig
		tempan = k * 5 / 1023
		kk = tempan
		kkk = kk * 100
		kkk = kkk / 2
		kkk = kkk - 20
		i = i + 1
		accuratetemp = accuratetemp + kkk
		Goto acctemp
		Else
		Endif
		
		accuratetemp = accuratetemp / 10
		accuratetempp = accuratetemp - 30

		WaitMs 2000
		
		Adcin 1, lightdig
		
		WaitMs 1000
		
		k1 = lightdig
		kk1 = k1 / 10
		kkk1 = kk1
		
		WaitMs 2000
		
		Adcin 2, soildig
		
		WaitMs 1000
		
		k2 = soildig
		kk2 = k2 / 10
		kkk2 = kk2 - 10
		
		WaitMs 1000
		
			If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

						
		Lcdcmdout LcdClear
		Lcdout "TEMPERATURE: ", #accuratetempp, "C"
		Lcdcmdout LcdLine2Home
		Lcdout "LIGHT: ", #kkk1, "lux & MOISTURE: ", #kkk2, "%"
		WaitMs 1300
		Lcdcmdout LcdClear
			If accuratetempp = 17 And kkk1 = 70 And kkk2 = 23 Then
			Lcdcmdout LcdClear
			Low PORTB.4
			Low PORTB.5
			Low PORTB.6
			Low PORTB.7
			Lcdout "The Plant is under optimum conditions"
			Lcdcmdout LcdLine2Home
			Lcdout "To Harvest Press the Red Push Button"
			WaitMs 1100
			Goto ok1
			Endif

		Lcdout "The following executions will be taken: "
		Lcdcmdout LcdLine2Home
		WaitMs 1200
				
		If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

			checktemp:
				If accuratetempp < 17 Then
					High PORTB.5
					Low PORTB.4
					Lcdout "HEATER ON "
					WaitMs 1300
					Endif
											
				If accuratetempp = 17 Then
					Low PORTB.5
					Low PORTB.4
					Lcdout "H&C OFF "
					WaitMs 1300
					Endif
												
				If accuratetempp > 17 Then
					High PORTB.4
					Low PORTB.5
					Lcdout "COOLER ON "
					WaitMs 1300
					Endif
					
					
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

					
			checklight:
					If kkk1 < 70 Then
					High PORTB.6
					Lcdout "LIGHTS ON "
					WaitMs 1300
					Else
					Low PORTB.6
					Lcdout "LIGHTS OFF "
					WaitMs 1300
					Endif
	
	
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

			checkhum:
				If kkk2 < 23 Then
					High PORTB.7
					Lcdout "SPRINKLER ON"
					WaitMs 1300
					Else
					Low PORTB.7
					Lcdout "SPRINKLER OFF"
					WaitMs 1300
					Endif
					
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: POTATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

		Goto ok1
		Return
		
		
		
		
tomatoes:
			If PORTC.3 Then
			Lcdcmdout LcdClear
			Low PORTB.4
			Low PORTB.5
			Low PORTB.6
			Low PORTB.7
			Lcdout "You have chosen to harvest the: TOMATOES"
			Lcdcmdout LcdLine2Home
			Lcdout "Choose Another plant(1/2/3), or turn off"
			WaitMs 2000
			Goto here
			Endif
		
			Lcdcmdout LcdClear
			Lcdout "Testing TOMATOES Plant..."
			WaitMs 1300
			Lcdcmdout LcdClear
			Lcdout "The TOMATOES Plant has the following: "
			Lcdcmdout LcdLine2Home
			Lcdout "(Scanning in Progress...)"
			WaitMs 1300

		
ok2: If PORTC.3 Then
			Lcdcmdout LcdClear
			Low PORTB.4
			Low PORTB.5
			Low PORTB.6
			Low PORTB.7
			Lcdout "You have chosen to harvest the: TOMATOES"
			Lcdcmdout LcdLine2Home
			Lcdout "Choose Another plant(1/2/3), or turn off"
			WaitMs 2000
			Goto here
			Endif
			
		i = 0
		accuratetemp = 0
		
		acctemp:
		WaitMs 1500
		
		If i < 10 Then
		
		Adcin 0, tempdig
		
		WaitMs 1000
		
		k = tempdig
		tempan = k * 5 / 1023
		kk = tempan
		kkk = kk * 100
		kkk = kkk / 2
		kkk = kkk - 20
		i = i + 1
		accuratetemp = accuratetemp + kkk
		Goto acctemp
		Else
		Endif
		
		accuratetemp = accuratetemp / 10
		accuratetempp = accuratetemp - 30

		WaitMs 2000

		Adcin 1, lightdig
		
		WaitMs 1000
		
		k1 = lightdig
		kk1 = k1 / 10
		kkk1 = kk1
		
		WaitMs 2000
		
		Adcin 2, soildig
		
		WaitMs 1000
		
		k2 = soildig
		kk2 = k2 / 10
		kkk2 = kk2 - 10
		
		WaitMs 1500
		
		Lcdcmdout LcdClear
		Lcdout "TEMPERATURE: ", #accuratetempp, "C"
		Lcdcmdout LcdLine2Home
		Lcdout "LIGHT: ", #kkk1, "lux & MOISTURE: ", #kkk2, "%"
		WaitMs 1300
		Lcdcmdout LcdClear
			If accuratetempp = 22 And kkk1 = 50 And kkk2 = 46 Then
			Lcdcmdout LcdClear
			Low PORTB.4
			Low PORTB.5
			Low PORTB.6
			Low PORTB.7
			Lcdout "The Plant is under optimum conditions"
			Lcdcmdout LcdLine2Home
			Lcdout "To Harvest Press the Red Push Button"
			WaitMs 1100
			Goto ok2
			Endif

		Lcdout "The following executions will be taken: "
		Lcdcmdout LcdLine2Home
		WaitMs 1100
		
		If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: TOMATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

			checktemp:
				If accuratetempp < 22 Then
					High PORTB.5
					Low PORTB.4
					Lcdout "HEATER ON "
					WaitMs 1300
					Endif

					
				If accuratetempp = 22 Then
					Low PORTB.5
					Low PORTB.4
					Lcdout "H&C OFF "
					WaitMs 1300
					Endif
						
					If accuratetempp > 22 Then
					High PORTB.4
					Low PORTB.5
					Lcdout "COOLER ON "
					WaitMs 1300
					Endif
					
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: TOMATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

					
			checklight:
					If kkk1 < 50 Then
					High PORTB.6
					Lcdout "LIGHTS ON "
					WaitMs 1300
				Else
					Low PORTB.6
					Lcdout "LIGHTS OFF "
					WaitMs 1300
					Endif
					
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: TOMATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

	
			checkhum:
				If kkk2 < 46 Then
					High PORTB.7
					Lcdout "SPRINKLER ON"
					WaitMs 1300
		
				Else
					Low PORTB.7
					Lcdout "SPRINKLER OFF"
					WaitMs 1300
					Endif
					
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: TOMATOES"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif

					
		Goto ok2
		Return
		
		
		
		
gardenia:
				If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
				Lcdout "You have chosen to harvest the: GARDENIA"
				Lcdcmdout LcdLine2Home
				Lcdout "Choose Another plant(1/2/3), or turn off"
				WaitMs 2000
				Goto here
				Endif
		
				Lcdcmdout LcdClear
				Lcdout "Testing GARDENIA Flower..."
				WaitMs 1300
				Lcdcmdout LcdClear
				Lcdout "The GARDENIA Flower has the following: "
				Lcdcmdout LcdLine2Home
				Lcdout "(Scanning in progress...)"
				WaitMs 1300
		
ok3: If PORTC.3 Then
				Lcdcmdout LcdClear
				Low PORTB.4
				Low PORTB.5
				Low PORTB.6
				Low PORTB.7
		Lcdout "You have chosen to harvest the: GARDENIA"
		Lcdcmdout LcdLine2Home
		Lcdout "Choose Another plant(1/2/3), or turn off"
		WaitMs 2000
		Goto here
		Endif
		
		i = 0
		accuratetemp = 0
		
		acctemp:
		WaitMs 1500
		
		If i < 10 Then
		
		Adcin 0, tempdig
		
				
		k = tempdig
		tempan = k * 5 / 1023
		kk = tempan
		kkk = kk * 100
		kkk = kkk / 2
		kkk = kkk - 20
		i = i + 1
		accuratetemp = accuratetemp + kkk
		Goto acctemp
		Else
		Endif
		
		accuratetemp = accuratetemp / 10
		accuratetempp = accuratetemp - 30
				
		WaitMs 2000
		
		Adcin 1, lightdig
		
		
		k1 = lightdig
		kk1 = k1 / 10
		kkk1 = kk1
				
		WaitMs 2000
		
		Adcin 2, soildig
						
		k2 = soildig
		kk2 = k2 / 10
		kkk2 = kk2 - 10
		
		WaitMs 1500
							
		Lcdcmdout LcdClear
		Lcdout "TEMPERATURE: ", #accuratetempp, "C"
		Lcdcmdout LcdLine2Home
		Lcdout "LIGHT: ", #kkk1, "lux & MOISTURE: ", #kkk2, "%"
		WaitMs 1300
				Lcdcmdout LcdClear
		
					If accuratetempp = 30 And kkk1 = 5 And kkk2 = 10 Then
					Lcdcmdout LcdClear
					Low PORTB.4
					Low PORTB.5
					Low PORTB.6
					Low PORTB.7
					Lcdout "The Plant is under optimum conditions"
					Lcdcmdout LcdLine2Home
					Lcdout "To Harvest Press the Push Button"
					WaitMs 1100
					Goto ok3
					Endif

		Lcdout "The following executions will be taken: "
		Lcdcmdout LcdLine2Home
		WaitMs 1100
		
					If PORTC.3 Then
					Lcdcmdout LcdClear
					Low PORTB.4
					Low PORTB.5
					Low PORTB.6
					Low PORTB.7
					Lcdout "You have chosen to harvest the: GARDENIA"
					Lcdcmdout LcdLine2Home
					Lcdout "Choose Another plant(1/2/3), or turn off"
					WaitMs 2000
					Goto here
					Endif

			checktemp:
				If accuratetempp < 30 Then
					High PORTB.5
					Low PORTB.4
					Lcdout "HEATER ON "
					WaitMs 1300
					Endif

					
				If accuratetempp = 30 Then
					Low PORTB.5
					Low PORTB.4
					Lcdout "H&C OFF "
					WaitMs 1300
					Endif
						
				If accuratetempp > 30 Then
					High PORTB.4
					Low PORTB.5
					Lcdout "COOLER ON "
					WaitMs 1300
					Endif
					
				If PORTC.3 Then
					Lcdcmdout LcdClear
					Low PORTB.4
					Low PORTB.5
					Low PORTB.6
					Low PORTB.7
					Lcdout "You have chosen to harvest the: GARDENIA"
					Lcdcmdout LcdLine2Home
					Lcdout "Choose Another plant(1/2/3), or turn off"
					WaitMs 2000
					Goto here
					Endif

					
			checklight:
					If kkk1 < 5 Then
					High PORTB.6
					Lcdout "LIGHTS ON "
					WaitMs 1300
				Else
					Low PORTB.6
					Lcdout "LIGHTS OFF "
					WaitMs 1300
					Endif
					
					
				If PORTC.3 Then
					Lcdcmdout LcdClear
					Low PORTB.4
					Low PORTB.5
					Low PORTB.6
					Low PORTB.7
					Lcdout "You have chosen to harvest the: GARDENIA"
					Lcdcmdout LcdLine2Home
										Lcdout "Choose Another plant(1/2/3), or turn off"
					WaitMs 2000
					Goto here
					Endif

	
			checkhum:
				If kkk2 < 10 Then
					High PORTB.7
					Lcdout "SPRINKLER ON"
					WaitMs 1300
				Else
					Low PORTB.7
					Lcdout "SPRINKLER OFF"
					WaitMs 1300
					Endif
					
					
				If PORTC.3 Then
					Lcdcmdout LcdClear
					Low PORTB.4
					Low PORTB.5
					Low PORTB.6
					Low PORTB.7
					Lcdout "You have chosen to harvest the: GARDENIA"
					Lcdcmdout LcdLine2Home
					Lcdout "Choose Another plant(1/2/3), or turn off"
					WaitMs 2000
					Goto here
					Endif

					
		Goto ok3
		Return

- - - Updated - - -

See the beginning of each type of plant:
i.e potatoes, before the adcin command

- - - Updated - - -

Also please note that, I have used a wall-wart voltage source. Connected to two voltage regulators, and distributed to sensors, and PIC circuit.
For the relays, There is a private 12V battery as a voltage source.
all GND are connected together

- - - Updated - - -

Newest version, this is to show the connection of the wall-wart
 

Attachments

  • photo(21).JPG
    2 MB · Views: 110

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…