AVR Solar Tracker

Thread Starter

domino89

Joined Sep 24, 2013
22
Hello iam trying to make a solar tracker based on avr microcontroller (Atmega8).
It will be using 2 LDR's to compare light intensity and then send decision to motor driver L293d. I am kinda new to avr's... I know how to run one ADC from for example Potentiometer. I know i cant make two adc reads at one time. How should i read two ADC inputs, "save" them and then compare those two values.
I would be grateful for any advices.
 

Shagas

Joined May 13, 2013
804
Actually you can read two adc reads at one time , not really at one time but good enough for your purposes.
Atmega 8 has eight adc channels . What happens is your read one channel , then you immediately after read the second channel . There is a slight delay in the order of microseconds between the readings (according to the speed that you set your adc up) but for your purposes you can consider it as "instant"

Read the datasheet on the ADC section .
The ADMUX register has the 'MUX' bits which basically operate a multiplexer which selects input 0-7 of the adc . You need to set the ADMUX before you take a reading for the right channel to be enabled .
As default the MUX bits are set to zero which configures your ADC input as channel 0 (pin 40) , if you want to use the other channels (pins 33-39) then you will have to configure the MUX bits


This guy has a tutorial on the avr ADC:

http://maxembedded.com/2011/06/20/the-adc-of-the-avr/


When you set the adc to read a value , the 10 bit value comes out in the ADC register so you can put :

Rich (BB code):
int LDR1 = ADC;
then take another reading and make

Rich (BB code):
int LDR2 = ADC;  // (the ADC register will now have the value of the latest reading)
and then compare them
 

THE_RB

Joined Feb 11, 2008
5,438
Why not put the two LDR's in series, between +5v and ground?

The middle point between the two LDRs can go to a single ADC input, which will be 2.5v when both LDRs match, or higher/lower etc if one LDR is illuminated more than the other.

Then you have a single ADC reading that tells you if the sun is ahead or behind your panel tracking.
 

Art

Joined Sep 10, 2007
806
Long time no see :)

This is why you are Sir RB!


Why not put the two LDR's in series, between +5v and ground?

The middle point between the two LDRs can go to a single ADC input, which will be 2.5v when both LDRs match, or higher/lower etc if one LDR is illuminated more than the other.

Then you have a single ADC reading that tells you if the sun is ahead or behind your panel tracking.
 

THE_RB

Joined Feb 11, 2008
5,438
Nah, my knighthood hasn't come through yet. The Queen is too busy giving them to comedians and TV personalities... ;)
 

Art

Joined Sep 10, 2007
806
Nah, my knighthood hasn't come through yet. The Queen is too busy giving them to comedians and TV personalities... ;)
It's exactly what I needed, I have two cells in a box where the top comes off
like an iPad box, I want to check if the lid has been opened properly by sensing light at both ends.
 

ftsolutions

Joined Nov 21, 2009
48
Personally, I think that I'd still go with the (2) separate LDR inputs/readings - that way, one can also diagnose issues, such as if 1 LDR sensor is damaged, or if you need to calibrate for nonlinearities or unbalanced offset between the two. But either way can work.
 

ErnieM

Joined Apr 24, 2011
8,377
Personally, I think that I'd still go with the (2) separate LDR inputs/readings - that way, one can also diagnose issues, such as if 1 LDR sensor is damaged, or if you need to calibrate for nonlinearities or unbalanced offset between the two. But either way can work.
It looks like the Atmega8 (I've never worked with one) is a 32 pin device with 6 or 8 analog inputs, an ample set of pins for this task.

Thus it is senseless and probably counterproductive to go cheap and combine pins. You may still get left/right info for the sun but you loose overall intensity, so you need other ways to detect night (it's dark!) to keep from chasing fireflies all night long.
 
Top