Code Monkey home page Code Monkey logo

interupt-genration-using-sensor-and-visualizing-using-serial-monitor's Introduction

EXPERIMENT--04-INTERUPT-GENRATION-USING-SENSOR-AND-VISUALIZING-USING-SERIAL-MONITOR

Aim:

To Interface a IR Sensor to digital port of iot development board and generate an interrupt and visualize on the serial monitor

Components required:

STM32 CUBE IDE, serial port utility monitor .

Theory :

An infrared (IR) sensor a proximity sensor, or a ‘nearness’ sensor senses whether there is an object near it or not. The IR stands for Infrared sensor. Infrared is the light out of our visible spectrum.

Working of an IR Sensor The white LED here is an IR LED which works as the transmitter and the component next to the IR LED is a photodiode that works as the receiver in the IR sensor.

The IR transmitter continuously emits the IR light and the IR receiver keeps on checking for the reflected light. If the light gets reflected back by hitting any object in front it, the IR receiver receives this light. This way the object is detected in the case of the IR sensor.

The blue knob here is a potentiometer. You can control the range i.e. from how far you want to detect the object by changing the value of the potentiometer.

An IR sensor has two small LED indicators – one for power, which is ON the entire time the sensor is ON; the other is the Signal LED which detects the object. The signal LED has two states or situations:

ON (Active) when it detects an object OFF (Inactive) when it doesn’t detect any object

image Now that we have a little idea about its works, let’s take a look at how to interface it with evive and see it in action.

Connect VCC pin to the +5V pin on evive. Connect GND pin to evive’s GND pin. Connect OUT to any gpio and configure that pin as EXTI mode

Interrupts

Interrupts are asynchronous (i.e. can happen anytime) events that disrupt the normal flow of your program. This allows the microcontroller to focus on a key task and attend to these events (e.g. pressing a button) as they come without needing to wait for them.

With interrupt, we do not need to continuously check the state of the digital input pin. When an interrupt occurs (a change is detected), the processor stops the execution of the main program and a function is called upon known as ISR or the Interrupt Service Routine. The processor then temporarily works on a different task (ISR) and then gets back to the main program after the handling routine has ended.

image The STM32 ARM microcontroller interrupts are generated in the following manner:

The system runs the ISR and then goes back to the main program. The NVIC and EXTI are configured. The Interrupt Service Routine (ISR) also known as the interrupt service routine handler is defined to enable the external interrupts.

Interrupt Lines (EXTI0-EXTI15) The STM32 ARM microcontroller features 23 event sources which are divided into two sections. The first section corresponds t external pins on each port which are P0-P15. The second section corresponds to RTC, ethernet, USB interrupts. Therefore, in the first section, we have 16 lines corresponding to line0 till line15. All of these map to a pin number. image

The diagram below shows how the GPIO pins are connected to the 16 interrupt lines:

Procedure:

  1. click on STM 32 CUBE IDE, the following screen will appear image

  2. click on FILE, click on new stm 32 project image image

  3. select the target to be programmed as shown below and click on next

image

4.select the program name image

  1. corresponding ioc file will be generated automatically image

6.select the appropriate pins as gipo, in or out, USART or required options and configure image image

7.click on cntrl+S , automaticall C program will be generated image image 8. edit the program and as per required image

  1. use project and build all image

  2. once the project is bulild image

  3. click on debug option image

  4. connect the iot board to power supply and usb

  5. After connecting open the STM cube programmer image

  6. click on UART and click on connect image

  7. once it is connected , click on Erasing and programming option image

  8. flash the bin or hex file as shown below by switching the switch to flash mode

image

  1. check for execution of the output by switching the board to run mode
  2. click on the serial port utility image
  3. click on the run to observe the values

STM 32 CUBE PROGRAM :

#include "main.h"
#include "stdio.h"
void HAL_GPIO_EXTI_Callback(uint16_t);
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);

#if defined(__ICCARM__) || defined (__ARMCC__VERSION)
#define PUTCHAR_PROTOYPE int fputc(int ch,FILE *f)
#elif defined(__GNUC__)
#define PUTCHAR_PROTOTYPE int __io__putchar(int ch)
#endif

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  while (1)
  {
	  HAL_GPIO_EXTI_Callback (GPIO_PIN_4);
	  HAL_Delay(1000);
  }
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_4)==0)
{
	 printf("IR ON\n");
}
else
{
	 printf("IR Off\n");
}
}

PUTCHAR_PROTOTYPE
{
	HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
	return ch;
}

Output screen shots of serial port utility :

1

CIRCUIT BOARD:

BEFORE DETECTION OF OBSTACLE:

2

AFTER DETECTION OF OBSTACLE:

3

Result :

Interfacing a IR SENSOR and interrupt is generated using external interrupt mode , visualized on serial port

interupt-genration-using-sensor-and-visualizing-using-serial-monitor's People

Contributors

vasanthkumarch avatar keerthikanagarajan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.