confused !

I have Arduino UNO

In my project .. I need 20 I/O pins !

I can solve this problem using only UNO ?

or buy Arduino Mega ?

the same program on UNO will run on Mega without editing ?

The general answer to your question is to employ one or more 74HC595 shift register/ latch chips - three pins to interface becomes 8, 16, 24 outputs and so on. Another chip for digital inputs. Look it up in the examples.

ealkhteeb:
the same program on UNO will run on Mega without editing ?

Generally not insofar as if you cannot solve the program on a Uno, then you do not have a working program to port to the Mega. :smiley:

If you do port it however, there are differences in port allocations and secondary functions which will need to be edited.

ealkhteeb:
I have Arduino UNO

In my project .. I need 20 I/O pins !

The UNO have D0 to D13 and A0 to A5, total of 20 pins, all can be digital I/O pins.

Another choice to increase the number of digital I/O pins is the I2C expander. The advantage with I2C expanders is that, unlike the 74HC595, the pins can be set to either input or output.

ealkhteeb:
In my project .. I need 20 I/O pins !

Tne Arduino Uno has exactly 20 I/O pins, but that includes the serial port for interfacing to the host PC via USB, and you will probably want to use the output side of that interface for debugging via Serial.print. That leaves you with 19 usable pins.

What do you intend to use the 20 I/O pins for? It is often possible to share some of the pins between different I/O devices.

You might also consider using the Arduino Leonardo. That has a separate USB interface, so you get 20 pins (plus two separate pins for interfacing with I2C devices), and you can use all of them and still debug via Serial.print.

Also if you have input switches to monitor it is possible to use resistors and a single analogue input to look at several switches over the one input.

Generally not insofar as if you cannot solve the program on a Uno, then you do not have a working program to port to the Mega. smiley-grin

Yes - if you stay away from the use of the ports and stick to digitalRead/Write then going up from the Uno is no problem. Of course you can't go from the mega to the Uno as the mega has pins that the Uno does not.

Mark

thanks all :slight_smile: