Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help with solar tracking system

Status
Not open for further replies.

norhankhaled

Newbie level 1
Joined
Mar 28, 2015
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
21
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 :D :D

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)
 {   ADCON0=0b10000101;
     v1 = read_adc();
      ADCON0=0b10001101;
      v2 =read_adc();
 
   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
Joined
Apr 17, 2014
Messages
20,771
Helped
4,486
Reputation
8,984
Reaction score
4,546
Trophy points
1,393
Activity points
137,139
Hi,

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

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

Also add debugging code to get more information.

Klaus
 

norhankhaled

Newbie level 1
Joined
Mar 28, 2015
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
21
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
Joined
Apr 17, 2014
Messages
20,771
Helped
4,486
Reputation
8,984
Reaction score
4,546
Trophy points
1,393
Activity points
137,139
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
Joined
Mar 28, 2015
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
21
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top