Input Devices

Interfacing magnetic Sensor to control LED

Assignments

  • To interface a sensor with the microcontroller


  • For this week I will be interfacing a magnetic sensor with microcontroller


    I planned to interface it on the door of the machine so machine can be turned off whenever its lead it open or user safety is at risk.

    The sensor is normally open and whenever magnet is brought in its vicinity it switches to normally close.

    Below is the image of magnetic sensor which I would be using.


    Designing circuit diagram and board using Eagle

  • Magnetic sensor will be connected on the 2 pin MVC connector provided on board


  • Magnetic sensor will be connected on the 2 pin MVC connector provided on board


  • Have modified the circuit diagram a bit for interfacing magnetic sensor. LED will be used as indication for magnetic sensor.


  • Adding frame


  • Switching to board layout






  • Milling and soldering the board

  • Using fabmodule .rml file was generated and board was milled.


  • Stuffing the board


  • Wring C code using Atmel Studio.

    /* * Amol_Input_device * * Created: 27-April-17 8:28:27 AM * Author : Amol Wadkar */ //#defines #define F_CPU 1000000 //Define clock speed as 1Mhz //Include Header #include //Import header file required for AVR microcontroller #include //Import header file required for delay function int main(void) { DDRA = 0b10000000; //set PA7as output & all other pins as input while (1) //Repeat the below actions continuously { if((PINA & (1<<3))==0b00000000) //When magnetic sensor is in NC PORTA |= (1<<7);// Set PA7 high (Make LED ON) else PORTA &= ~(1<<7);// Set PA7 low (Make LED OFF) } }

    Program the board using Arduino.


    Working : Whenever magnet is in vicinity of magnetic sensor onboard LED glows and whenever it is moved away LED is turned off.






    Output files

  • Board Schematic
  • Board layout
  • C code