# Which microcontroller pins should i use with this project?

I have some knowledge about Arduino, but it's my first time using solo microcontrollers and this sort of thing, i have no idea of what i should do in this case.

I'm following a guide that users ATTiny13 with a Led and an LDR sensor, but i don't have that microcontroller, so i'm using a ATmega328P-PU, which has a slightly different pinout.

I searched a lot and found many important stuff, but i can't figure out what to do here.

The project i'm doing uses this guide.

The code is commented with the three pins: LDR sensor, LED and some other pin with a resistor, or something like that.

// use PB2 for led, pin 7
#define LED_BIT 2
// use PB3 to enable ldr, pin 2
// use ADC2, PB4, pin 3
#define CHANNEL 2


The ATmega datasheet shows PB, PC and PD pins, but ATtiny has only PB, i don't know what i should do and which ports are equal to each other.

Basically, i need to know which pins on ATmega i should use as an alternative to the ones on ATtiny13 in the code.

• You do realize you'll need to change the entire code too, right? You can't take code written for one uC and expect it to run directly on a completely different one – DerStrom8 Sep 16 '15 at 19:18
• If the program uses Port B (PB), then you may as well use Port B on the ATMega, but you could use any port or pins, as long as you change the code to suit. I don't know if the ATTiny and ATMega are code-compatible. If not, you may have to make some software changes to make the code compile for the ATMega. – Peter Bennett Sep 16 '15 at 19:43
• @derstrom8 the changes between a tiny and a mega for simple code would be minimal, mostly just pin/port changes for the most part. In this case, I dont even think the ADC code needs much changes tbh. – Passerby Sep 17 '15 at 4:06
• Thanks @Passerby. I was not sure how the two uCs differed. In my experience with other micros the code has to be changed completely. If the registers are similar, though, I expect it would require less effort – DerStrom8 Sep 17 '15 at 15:50
• @derstrom8 actually, i didn't until i read the above answers. As i said, i'm totally new to this. PeterBennett thanks for the help. In general, i think i'll switch to the suggested microcontroller, since it's cheaper, easier and a lot simpler to use. Thank you all. – George Sep 17 '15 at 16:02

You can use PB5 for you ADC channel. PB2 for enable and PB1 for led.