ATTiny2313 microcontroller is heating up

Hello, I am facing one issue while connecting the GND pin with digital pin of ATTiny2313, the microcontroller chip is start heating up like hot surface. I followed the below schematic to connect the pins and relay module. The relay module is working fine if I connect GND pin with specific digital pin but the microcontroller is getting too hot which means something wrong form my end.

please help me on this

In the above example, I connected the PIN#2 with GND of MC

code:

#include <digitalWriteFast.h>

#define SW1 2
#define RELAY_PIN  11
#define BLINK_LED_PIN 13

const byte opened = HIGH;
const byte closed = LOW;

void setup() {

  digitalWriteFast(SW1, closed);
  digitalWriteFast(RELAY_PIN, opened); // Initialize relay to off state

  pinMode(RELAY_PIN, OUTPUT);
  pinMode(SW1, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

  digitalWriteFast(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWriteFast(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

  int SWOut = digitalReadFast(SW1);
  if (SWOut == 1) {
    digitalWriteFast(RELAY_PIN, opened);
  }
  else{
     digitalWriteFast(RELAY_PIN, closed);
  }
}

The above code is working as expected but not sure why if I connect GND wire with digital pin is burning the microcontroller. When I disconnect this then the mc is getting normal. I cross checked my connections and there is no short circuit.

Where is the ATTiny2313 in your diagram?

Why are you using this library?

Why would you do this?

If the pin is set to be an input, it will only ever read LOW, which would be pointless.

If the pin it set to be an output, and you set it to HIGH, this would cause a damaging short circuit which would cause the Arduino to heat up and then burn.

Sorry. Here is the updated One.

So do you mean the problem with coding?

Do not change your posts in a way that makes the replies you receive sound crazy. Anyone reading this thread will ask themselves why I could not see the ATTiny2313 in your diagram. They will think I am crazy. Do you want people to think I am crazy?

Yup understood. By mistake I uploaded wrong image. BTW, what you suggest to resolve this issue?

Perhaps you could answer my questions.

Yup understood. By mistake I uploaded wrong image. BTW, what you suggest to resolve this issue?

Now I wonder if you are crazy! :wink:

To switch the relay, digitalWrite PD6 HIGH or LOW. Remove the connection to PD0.

When PD6 is HIGH then the relay is switching ON.

Is that not what you want? Does the relay module have a HIGH / LOW jumper?

The relay module doesn't have any jumper to set HIGH or LOW. But from code if I set to HIGH then the relay is ON.

What do you want the relay to do?

To control the buld

Sorry, I don't understand, good luck.

What are trying to do with this? Are you trying to use some sort of input to signal the controller to turn the relay on?
What was the purpose of P0 supposed to be?
please clarify what you're trying to do and you'll get better help.

Maybe you shoild hage a look at this:
https://www.getmicros.net/amp/program-your-attiny2313-with-an-arduino.php
The pin numbering in software is not the same as the pin numbering in your drawing...
Your pin2 is the rx pin...
It is best not to use tx and rx for anything else..

After waiting 2 times 1000ms it does not make sense to use fast digital read and write....

It's a 2313 with only 2k of program memory. fastdigitalwrite is also small.

Check to make sure the arduino pin numbers used in your sketch match the pins on the chip. It's pretty uncommon for them to exactly match the chip pin numbers. (what "core" are you using, anyway? ATtinyCore says PD6 is pin 8, and PD0 is 0.) (Make sure your digitalWriteFast pin numbers match the pinMode pin numbers.

Set all unused pins to INPUT_PULLUP to prevent floating levels...

I'd be very tempted to skip the Arduino functions for this sort of app, and use direct port writes for everything. The whole "pin" abstraction loses a lot of its attractiveness in the absence of a standardized "board" with numbered pins.