hey, i build my 50$ robot, my MCU is ATmega168. the servos work fine, but the photoresistor sensor nonworking.
i try next prog code :
#include "SoR_Utils.h" //includes all the technical stuff
int main(void)
{
int sensor_left=0;//left photoresistor
configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_off();//turn LED on
while(1)
{
//store sensor data
sensor_left=a2dConvert8bit(5);
if (sensor_left>125)
LED_on();
delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/
return 0;
}
the LED always off.
i try to change "if (sensor_left>125)" to "if (sensor_left>10)" and now the LED always on. even if i disconnect PHOTORESISTOR from the board the LED work.
anyone have idea what wrong?