#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define IR_SENSOR_PIN GPIO_NUM_15 // Define the GPIO pin connected to the IR sensor
void app_main(void)
{
// Configure the IR sensor pin as input
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << IR_SENSOR_PIN);
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&io_conf);
// Initialize serial communication
printf("Starting IR sensor interface\n");
while (1)
{
// Read the state of the IR sensor
int ir_state = gpio_get_level(IR_SENSOR_PIN);
// If the IR sensor detects a signal (active LOW)
if (ir_state == 1)
{
printf("IR signal detected!\n");
}
else
{
printf("No IR signal detected.\n");
}
// Add a small delay to avoid flooding the serial monitor
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}