Atmega 328P pin 0 as input errors

Hi all,
I write a program for the 328p, and i use it stand alone. I ordered some 328P from china, but i have some problems with this. First of all it has not got bootloader, so i have to burn. I solved this. But the main problem is that i cant use pin 0 on these new microcontrollers. The old one is working correctly with the same program. What can i do now?
I produced 30 PCB for my project with pin 0, because it was good. But only with the old controller.
I dont know, how can i fix it.
Thanks for your help.

szeba:
I dont know, how can i fix it.

Well neither do we because you haven't given us any details to work from. Perhaps you coded something wrong. Perhaps you wired something wrong. Nobody but you can know because you're the only one who can see those things.

You've brought us a description of the symptom, but you didn't bring us the patient. It's nearly impossible to diagnose the disease that way.

Sorry, you are right.
Here are the details about my project:
I'm using pin 0 as input. I wired 10k pull up resistor on this pin. When i switch GND to it, it would be on LOW. When nothing is on pin0, it would be on HIGH.
I have an while cycle. But the program is only run in while, when the pin 0 is LOW.
On the old atmega its working fine. I have problem only with the new controllers.

Here are my declarations:

void setup() {
  SPI.begin();
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(7, INPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(3, HIGH);
  digitalWrite(0, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(8, LOW);  
  rfid.PCD_Init();
  backtime = millis();
}

I hope, i give you enough information about my problem. Thank you for your help.

So you think the problem is in the setup function? If you know where the problem is then fix it. If you don't know where the problem is then don't pretend that you do. Post the whole thing, all the code and a wiring schematic.

So before you didn't bring us the patient. This time you brought in the patients hat but still not the body that is sick. Is this really so hard for you to imagine that a person would need to be able to see the thing in order to help you fix it? Think about this for a minute please and don't waste anymore of our time by leaving important parts out.

string ID;
void setup() {
  SPI.begin();
  pinMode(0, INPUT);
  pinMode(7, INPUT);
  pinMode(8, OUTPUT);
  digitalWrite(0, HIGH);
  digitalWrite(8, LOW);  
  rfid.PCD_Init();
  backtime = millis();
}
void loop() {
	if(digitalRead(0)==LOW && strID==ID){
		digitalWrite(8, HIGH);
	}
 if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial() && azonositas==true){return;}
  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10) +
      String(rfid.uid.uidByte[i])
      ;
  }

  strID.toUpperCase();

photo:
IMG_20170929_190022.jpg - Google Drive

In your picture, the pull-up resistor should be on the other side of the switch. As drawn, when you close the switch you short 5V to Ground.

Why don't you use the built-in pull-up resistors on the chip?

Yes, the reaistor is in the other side. I tried with the builtin, but nothing changed. The pin0 still not working.

void loop() {
	if(digitalRead(0)==LOW && strID==ID){
		digitalWrite(8, HIGH);
	}
 if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial() && azonositas==true){return;}
  String strID = "";

There's gotta be more to it. Here you are using strID before you've defined it. Do you have two variables names strID in this scope? That's a really really bad idea to give to variables in the same scope the same name.

Are you sure strID holds what you think it does? How would you know the pin wasn't being read if strID was not right?

Have you tried this with a simple program that maybe just turns on or off an LED in response to the switch? That would narrow it down to hardware vs. software.

By the way:

(rfid.uid.uidByte[i] < 0x10) +
      String(rfid.uid.uidByte[i])
      ;

Beware of the String class and especially its + operator on memory limited environments with no garbage collection. This will end up shooting the heap full of holes and can eventually crash a program. Much better to stick with c-style strings instead of the String class on a microcontroller.

I don’t think this is the cause of your current problem, but it is a bug waiting to bite you later. Best to fix it now before the code gets bigger.

The software is definitly good, because if i upload it the original microcontroller, its work. I have problem with the other controllers. If i change to an other(none original) this program not work because the pin 0.

Delta_G:
Have you tried this with a simple program that maybe just turns on or off an LED in response to the switch? That would narrow it down to hardware vs. software.

szeba:
The software is definitly good, because if i upload it the original microcontroller, its work. I have problem with the other controllers. If i change to an other(none original) this program not work because the pin 0.

OK, don't test it then. But I'm not going any further to help you if you won't. That's the quickest and easiest way to see if there's indeed something wrong with the pin. If you just refuse to take that step then you're on your own.

I'm also not going any further with this if you insist on forcing me to try to debug it without being able to see the whole thing. Either post the complete code or let us know that you don't want any more help.

I tried with led. But ive got the same result: one is good, others not. I also tried this: if(digitalRead(0)==LOW) without any rfid parts. But nothing.

But you’re not going to show us any of that? You’re still not going to post complete code? I give up. Good luck to you dude.

If only there was a sticky reminding people to post the full code (or attach the sketch file) and also include schematic or picture of the setup. We're not going to steal your code or something but if you're going to ask for help you need to open up more.

Ok, but...
I only have problem, with the microcontroller. I think, if i cant use pin 0 with an easy wireing, for example with an LED on pin13 and a button on 0, not the software is wrong. I mean.
So the program is not the main part of this problem.
Because if i use an original arduino microcontroller, everything is good. But when i use the chinese one, the pin 0 stay HIGH. HIGH in every time. If i wire it to GND also stay HIGH, but the original gone LOW.
That is the problem. So i dont think, we have to debugging the full (very big) program. Because the problem is not this.
Tell me if i was wrong.

Could be. I've never heard of "china AVR clone works fine expect for PortD0 bit", though...

it has not got bootloader, so i have to burn.

Which bootloader did you burn? "Digital pin 0" on an Arduino is the Serial RX, so one possible explanation is that the uart has been left enabled somehow (perhaps by the bootloader), and trying to read that pin while the uart is enabled always yields HIGH. Or even "clone chip behaves differently reading D0 when UART is enabled."

Tell me if i was wrong.

The thing is we see all sorts of people all the time who think their board is broken, no way it could be in the code. And when we finally get them to post it we find the issue in the code. I'm looking at you and I'm thinking, here's a guy who isn't smart enough to stop and read "How To Use This Forum" before he starts using the forum so I should probably verify things for myself. So I'm wanting to be able to see it all for myself. I don't want to just take your word for it because you might be full of it and I don't want to waste my time chasing a problem over bad information. So even if you're 100% sure it's not the code, post the damned code so I can be sure too.

Or stick with wanting to dictate the terms of how you get your FREE VOLUNTEER help and you can wait for someone willing to help with half the picture or possibly get no help at all. I don't care. It's not my project. I don't care if you get it working or not. So if you want to be difficult be difficult and see if that makes people want to help you more or less.

I've got a new result. If i use the 328p in the uno, the pin is good. But in stand alone not working. I write a program for it. If the 0 is on ground, the LED is turn on.
For standalone i use this wiring:

The difference between my solution and this is that i put a 10k resistor to reset.