2023-02-03 03:12 AM
Hello.
Find the attached circuit diagram for my IR sensor. The trigger is built in such a way that when it's off the IR transmitter is off and we get the sunlight values and when it's on we get sunlight + IR value and when we subtract the two we get the resultant. But my code doesn't dsiplay any value when the IR transmitter is on. Here's my code. Please help. When I add a breakpoint it never gets triggered by the if loop where the trigger or pin 9 is set.
HAL_TIM_Base_Start_IT(&htim3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_9);
HAL_Delay(1000);
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET){
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 100);
ir = HAL_ADC_GetValue(&hadc1);}
else if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_RESET){
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 100);
sunlight = HAL_ADC_GetValue(&hadc1);}
res = ir - sunlight;
2023-02-03 03:40 AM
Are you trying to read and write from the same GPIO?
How did you configured gpio A-9, output or input?
I recommend this for you https://www.youtube.com/watch?v=vdY0VN21ZOI
2023-02-03 05:05 AM
I'll be surprised if it works. Normally the photodiode has much too small current to be sampled by ADC, unless you direct a laser light onto it. For light intensity sensing without an amplifier use phototransistor or LDR. For IR remote reception - use a dedicated circuit, like TSOP1836.