# need help with solar tracking system

Status
Not open for further replies.

#### norhankhaled

##### Newbie level 1
hey guys
i am new in programming micro controllers , and i was trying to make solar tracking using pic 16f877a , 2 LDR and a stepper motor
but my code doesn't work , can someone help me with this please

Code C - [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
unsigned int v1;                        //LDR1
unsigned int v2;                        //LDR2
void main() {
TRISA=0xFF;
TRISC=0x00;
while(1)

if (v1 > v2)
{
PORTC=0b00000001;
delay_ms(1000);
}

if (v2 > v1 )
{
PORTC=0b00001000;
delay_ms(1000);

}

if (v1 = v2)
{
}

}
}

Last edited by a moderator:

#### KlausST

##### Super Moderator
Staff member
Hi,

"doesn't work" is not a very detailed description.

Write what you expect from the code to do. And what happens instead.

Klaus

#### norhankhaled

##### Newbie level 1
it was supposed a solar tracking system
if LDR in AR0 sensed light more than the other LDR the stepper will move clockwise 45 degree and if the other LDR sensed light more the stepper will move 45 degree anticlock wise
but when i connected the circuit nothing happened ( the motor didn't move )

#### KlausST

##### Super Moderator
Staff member
Hi,

I can't see how you want a stepper motor to move.
You just control two outputs: pc0 and pc3.
If one channel is higher, them pc0 is ON and pc3 is OFF.
When the other is higher, the, pc0 is OFF and pc3 is ON.
If both are the same, then it repeats the previous state.

But with this you can't control a stepper. Read on how to control stepper motors.

You could connect pc0 and pc3 to two halfbridges and drive ad dc motor. But with your program the motor never stops...

Klaus

#### norhankhaled

##### Newbie level 1
I want the stepper motor to move towards the LDR with higher value and it will keep doing it
there is a relay uln2003a between the pic and the stepper motor connected at pins c0, c1, c2, c3

Status
Not open for further replies.