Declaring pins

Hi, I was going over the examples that come in the arduino software.

I was trying to write my own code that does the following:

-read analog inputs from 5 channels (pins 19/23/24/25/26), read the inputs from SCL/SDA IMU and then transmit those over to a radio receiver thats plugged into the board.

The problem as I was reading the analog.read(), is that in the example on the software it never declares each pin as an INPUT pin, but as I read other tutorials it says to declare them in the setup.void() part as either input/output pins.

My question is, should I declare them or will this be done automatically with the analog.read() function?

read analog inputs from 5 channels (pins 19/23/24/25/26)

There are no Arduinos that have 26 analog pins.

The problem as I was reading the analog.read(), is that in the example on the software it never declares each pin as an INPUT pin

Why would you need to define the mode of an input only pin? It's useless to try to set an input-only pin to output.

My question is, should I declare them or will this be done automatically with the analog.read() function?

No and no.

PaulS:

read analog inputs from 5 channels (pins 19/23/24/25/26)

There are no Arduinos that have 26 analog pins.

The problem as I was reading the analog.read(), is that in the example on the software it never declares each pin as an INPUT pin

Why would you need to define the mode of an input only pin? It’s useless to try to set an input-only pin to output.

My question is, should I declare them or will this be done automatically with the analog.read() function?

No and no.

Iknow there are no arduinos with 26 analog pins, but the ATMega328 has plenty of pins, which according to the schematic the channels I connected to it are on the pins I listed. (ADC0-ADC-4).

Again, I dont know if I need to define a pin as input or not, I am new to this and I was following this example (included int he arduino software Examples > Analog > AnalogInput.

[quote= example from Arduino:
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().

The circuit:

  • Potentiometer attached to analog input 0

  • center pin of the potentiometer to the analog pin

  • one side pin (either one) to ground

  • the other side pin to +5V

  • LED anode (long leg) attached to digital output 13

  • LED cathode (short leg) attached to ground

  • Note: because most Arduinos have a built-in LED attached
    to pin 13 on the board, the LED is optional.

Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe

This example code is in the public domain.

*/

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

[/quote]
[/quote]
as you can see in the previous example the code declares a pin as output, but doesnt declare any pin as input. ergo my question about declaring pins

The analogRead() function takes an analog pin number as an argument. The analog pin numbers start at zero. The values 19/23/24/25/26 are not valid analog pin numbers.

All I/O pins default as digital INPUT and LOW. Yeah, the ‘analog pins’ also work as digital pins.
The names of the analog pins on the UNO are A0, A1, etc.
You can find the numbers easily enough but it’s better to use the names.

byte analogPins[ 6 ] = { A0, A1, A2, A3, A4, A5 };

void setup( void )
{
  Serial.begin( 9600 );
  
  for ( byte i = 0; i < 6; i++ )
  {
    Serial.println( analogPins[ i ] );
  }
}

void loop( void )
{
}

Quick_questions:
-read analog inputs from 5 channels (pins 19/23/24/25/26), read the inputs from SCL/SDA IMU and then transmit those over to a radio receiver thats plugged into the board.

We never use hardware pin numbers at all in the software because they differ
between different packages of the very same chip. The Arduino software uses
virtual pin numbers for everything, including the analog pins which have
two distinct numbering schemes, from zero (just for analogRead()), and A0..A7
(which are #defines for 14..21 in fact) which work with all pin-related calls.

pins default to INPUT, so no need to set them as inputs. You can if you want to
"declare" their use as inputs using pinMode() - it helps document your project in
fact - but normally the #defines you use to give your symbolic names to the pins
are enough for that

MarkT:

Quick_questions:
-read analog inputs from 5 channels (pins 19/23/24/25/26), read the inputs from SCL/SDA IMU and then transmit those over to a radio receiver thats plugged into the board.

We never use hardware pin numbers at all in the software because they differ
between different packages of the very same chip. The Arduino software uses
virtual pin numbers for everything, including the analog pins which have
two distinct numbering schemes, from zero (just for analogRead()), and A0..A7
(which are #defines for 14..21 in fact) which work with all pin-related calls.

pins default to INPUT, so no need to set them as inputs. You can if you want to
"declare" their use as inputs using pinMode() - it helps document your project in
fact - but normally the #defines you use to give your symbolic names to the pins
are enough for that

thank you! that was helpful, I am wondering the analog inputs are A0-A7? or AD0-AD3? (I have arduino Mini)

cause the eagle schematic say ADC0-ADC3, the "picture" says AD0-AD3, and you are saying A0-A4?

http://arduino.cc/en/Main/ArduinoBoardMini#.UwhP7Egz3jI

Analog Input Pins 8 (of which 4 are broken out onto pins)