Use The RESET PIN On Attiny85 As Input With Voltage Divider

9 min read Oct 02, 2024
Use The RESET PIN On Attiny85 As Input With Voltage Divider

The Attiny85 is a popular microcontroller for hobbyists and makers due to its compact size, low power consumption, and affordability. Its versatility allows for a wide range of applications, from simple blinking LEDs to more complex projects involving sensors and actuators. One unique aspect of the Attiny85 is the ability to repurpose the RESET pin as a general-purpose input pin, which can be useful for specific projects where you require an extra input, and the RESET functionality is not needed. This can be achieved using a voltage divider circuit, which effectively lowers the voltage at the RESET pin below the threshold required to trigger a reset. This article explores the concept of using the RESET pin as an input, the practical considerations involved, and a step-by-step guide for its implementation.

Utilizing the RESET Pin as an Input on Attiny85

The RESET pin on the Attiny85 is typically used to restart the microcontroller. When this pin receives a low logic level (typically 0V), it triggers a reset. However, by carefully manipulating the voltage level at the RESET pin, we can use it as a general-purpose input for our project.

Understanding the Voltage Divider

A voltage divider is a simple circuit that consists of two resistors connected in series, with the input voltage applied across both resistors. The voltage at the junction between the two resistors is the output voltage, which is a fraction of the input voltage determined by the ratio of the resistors.

The output voltage (Vout) can be calculated using the following formula:

Vout = Vin * (R2 / (R1 + R2))

Where:

  • Vin is the input voltage
  • R1 is the resistance of the first resistor
  • R2 is the resistance of the second resistor

Repurposing the RESET Pin

To use the RESET pin as an input, we need to ensure that the voltage at the RESET pin remains above the reset threshold, which is typically around 0.3V for the Attiny85. This is achieved by using a voltage divider circuit to lower the input voltage to a safe level.

How to Use a Voltage Divider for the RESET Pin:

  1. Connect a Resistor: Connect one end of the first resistor (R1) to the input signal (the source providing the signal to be read) and the other end to the RESET pin of the Attiny85.

  2. Connect the Second Resistor: Connect one end of the second resistor (R2) to the RESET pin and the other end to ground (GND).

  3. Select Resistor Values: Choose resistor values that ensure the voltage at the RESET pin is always above the reset threshold. You can use a calculator or online tools to determine the appropriate resistor values.

Implementing the Circuit

To implement the circuit, you will need the following components:

  • Attiny85 microcontroller
  • Two resistors (values depend on the input voltage level)
  • Breadboard (optional)
  • Jumper wires
  • Input Signal Source: A switch, a sensor, or any other signal source that provides a voltage level that can be safely divided.

Circuit Diagram:

Input Signal ----- R1 ----- RESET pin (Attiny85) ----- R2 ----- GND

Code Example (Arduino IDE):

#define RESET_PIN 4 // Assuming the RESET pin is connected to pin 4 on the Attiny85 
int inputValue = 0; // Variable to store the input value

void setup() {
  // Configure the RESET pin as an input
  pinMode(RESET_PIN, INPUT);
}

void loop() {
  // Read the input value from the RESET pin
  inputValue = digitalRead(RESET_PIN);

  // Take action based on the input value
  if (inputValue == HIGH) {
    // Do something if the input is HIGH
  } else if (inputValue == LOW) {
    // Do something if the input is LOW
  }
}

Note: This code example uses the digitalRead() function to read the state of the RESET pin. It is important to ensure that the RESET pin is configured as an input using the pinMode() function before using it.

Important Considerations:

  • Input Voltage: The input voltage must be carefully chosen to avoid damaging the Attiny85. It is recommended to keep the input voltage below 5V to avoid exceeding the maximum input voltage tolerance of the Attiny85.
  • Resistor Values: The resistor values used in the voltage divider circuit play a critical role in determining the voltage at the RESET pin. Choosing appropriate values is essential to ensure that the voltage remains above the reset threshold while also providing an adequate input signal for the microcontroller.
  • Debouncing: If the input signal is prone to bouncing (rapid changes in voltage), it is essential to implement a debouncing technique to prevent false readings. This can be achieved using a capacitor in parallel with the switch or by using debouncing routines in software.
  • Reset Functionality: When using the RESET pin as an input, the microcontroller's reset functionality is disabled. This is because the voltage divider will prevent the pin from receiving the low logic level required to trigger a reset.

Conclusion

Repurposing the RESET pin as an input on the Attiny85 provides an opportunity to expand the microcontroller's capabilities and create more complex projects. By carefully considering the input voltage, resistor values, and other factors, it is possible to safely and reliably use the RESET pin as an input for your project. This method can be particularly useful when you require an extra input pin on your Attiny85 and the reset functionality is not required. Remember to always prioritize safety and follow good practices when working with electronic components.