Pins of microcontroller can be used as inputs or as outputs.

 

Input on a microcontroller (Arduino):

 

  • We use as input the pin of a microcontroller, when we want to trigger - information from external peripheral.
  • The input can be either analog or digital be specific the pins of microcontrollers that can be used as analog inputs or analog outputs or can combine both possibilities at the same pin, all these possibilities mentioned in datasheet of each microcontroller.   
  • Digital Input characterized when external trigger is binary 0 or binary 1. In the microcontroller (when supplied with 5 volts) command is transferred with voltage, ie binary 0 (0 volt) and binary 1 (5 volts).
    • For the analog input, is embedded converter "adc - analog to digital converter" that converts voltage values to integer numbers that when the external trigger is only 0 or 5 volts other gets and intermediate values via the converter to numbers 0 " 0 volt "to 255" 5 volts "(8 bit adc) or 0" 0 volt "until 1023" 5 volts "(10 bit adc) etc.
    • The more bits resolution has converter pin, the greater the accuracy of the measurement.

 

  • If you want to connect a button - switch use the pin to digital input, when the button is pressed the microcontroller following procedure we defined when programming.
    • Depending on the wiring of the button to the microcontroller, we can give when pressing the buttons binary 1 (5 volts) or binary 0 (0 volts).
    • When you connect button we use (pull up or pull down) resistors to be clear mandate (the trigger) to the microcontroller, the value of these resistors is typically 10kohms.

 

  • Binary 1 to microcontroller input.
  • Pull Down called resistor connected to ground, and permanently holding the state of the input of the microcontroller to the binary 0 (0 volts) when the button is pressed is transferred "clear" binary 1 (5 volts) to microcontroller input.

 

 

  • Binary 0 to microcontroller input.
  • Pull Up called resistance connected to 5 volts and permanently holding the state of the input of the microcontroller to a binary 1 (5 volts) when the button is pressed is transferred "clear" the binary 0 (0 volts) to microcontroller input.

 

 

  • If you want to connect a sensor (brightness, temperature etc.) We use the pin as analog input (input with adc) and implement wiring voltage divider circuit.
    • For analog peripherals use circuit voltage divider, to have the correct values when it changes the voltage from the sensor (typically gives a reference voltage to the microcontroller to "understand" the changes of the voltage from the sensor something like "for analog triggering" with above example with digital commands).
  •  
    • In brightness sensor example (photoresistor ldr) substantially comes to a resistance that changes value when changing the brightness of the environment, of which one end is connected to 5 volts, the other end to one end of the photoresist and other end of the photoresist connected to ground (0 volt),above connection called "in series" connection.
  •  
    • Analog voltage (measuring) we get from where the resistance connected to the photoresistor and connect to microcontroller (this description is the voltage divider circuit).