Hello, I am going to create a small project with few buttons and few led's. I want to use 9 pins for buttons as inputs and 12 pins are for LED's as output.
I am confused with the pinout of Atmega8A and I noticed only few pins are direct I/O pins and I don't know how can I use remaining pins as normal digital I/O pins. Please help me on this.
What do you mean only few pins are direct I/O? Almost all are I/O which is the default functionality. There are 23 in PDIP version, if I count correctly.
Take look at the datasheet. There are PB0-7, PC0-6, PD0-7.
Start with the Analog pins, they can be analog in, digital in, digital out depending on your code. If you are using I2C you will lose two of them,A4/A5. Now you should have enough pins.
Use the "pinMode(); in your setup. Before progressing I highly recommend you get and read a copy of the Arduino Cookbook, It will answer the questions asked and even give you examples.
To get 23 IO, you need to use the internal clock to free up the external crystal pins, and reprogram the fuse that allows RESET to be a gpio. In normal Arduino code, you’d only have access to 20ma IO pins (and two of those are normally the serial port used for uploading sketches.)
Fortunately, you don’t really need 9 pins to do 9 buttons, or 12 output pins to control 12 leds
If you don't want to detect multiple buttons at the same time, you can use an analogue pin with a resistor ladder for the buttons. this way you connect all 9 buttons using a single pin.
I want to use 4 pins i.e. 2,3,4,5 as inputs on arduino UNO
whenever I connect the pin#2 with GND pin, I want to turn ON the RED LED on pin #8 like wise
whenever I connect the pin#3 with GND pin, I want to ON the BLUE LED on pin #9
whenever I connect the pin#4 with GND pin, I want to ON the GREEN LED on pin #10
whenever I connect the pin#5 with GND pin, I want to ON the YELLOW LED on pin #11
Note: I connected each LED with respective pin with GND pin on arduino
is there any way to use single pin to control all the LED's for different input pins?
My post is about the buttons. Read the post #8 by @jobitjoseph carefully. It have to be analog pin. Basically, you will read the voltage on input, based on which button is pressed.