# Digital Input producing non 0/1

**URL:** <https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301>\
**Category:** Programming\
**Created:** [July 22, 2025, 7:04pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301 "2025-07-22T19:04:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmacione](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jmacione/32/1126937_2.png) [@jmacione](https://forum.arduino.cc/u/jmacione)\
**Post date:** [July 22, 2025, 7:04pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/1 "2025-07-22T19:04:30Z")

</div>

PCB has set of 7 switches connected to IO  
Printing them out serially for debugging  
One of them has a IO show up that is a 3 now and then  
The others, show up as 1 as switch depressed

ITs got an ADC on that pin, how to i shut off?

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/8/5/3/85380f13d752318c40f0370b9f2254b5c237796a.png)

```arduino
// E21-003 Collimator Recognition
//Microcontroller being used is Leonardo variant
//polulu astar 3101 https://www.pololu.com/product/3101
//It is reading the configuration of switches off the PCB E33-031 via the E11-033 - Collimator Recognition Cable
//There are 7 switches on the collimator recognition PCB
//The mapping of hte Collimator recogntion Pins, through cable, to the Leo PCB is as follows
// Coll_PCB_SW1-> Cable#1 -> Leo#0
// Coll_PCB_SW2 -> Cable#3 -> Leo#1
// Coll_PCB_SW3 -> Cable#5 -> Leo#4
// Coll_PCB_SW4 -> Cable#7 -> Leo#7
// Coll_PCB_SW5 -> Cable#9 -> Leo#8
// Coll_PCB_SW6 -> Cable#10 -> Leo#18 (or 19)
// Coll_PCB_SW7 -> Cable#8 -> Leo#19 (or 18)

/ ***Definitions*** /
#define Pin0 0
#define Pin1 1
#define Pin4 4
#define Pin7 7
#define Pin8 8
#define Pin18 18   
#define Pin19 19

// ***Constants*** //
byte SwitchArray[7] = {0, 0, 0, 0, 0, 0, 0};
 int arraySize = sizeof(SwitchArray) / sizeof(SwitchArray[0]);

void setup()
{
  Serial.begin(9600);
  pinMode(Pin0,INPUT);
  pinMode(Pin1,INPUT);
  pinMode(Pin4,INPUT);
  pinMode(Pin7,INPUT);
  pinMode(Pin8,INPUT);
  pinMode(Pin18,INPUT);
  pinMode(Pin19,INPUT);
}

void loop()
{
  delay(400);
  SwitchArray[1] = digitalRead(Pin0);
  SwitchArray[2] = digitalRead(Pin1);
  SwitchArray[3] = digitalRead(Pin4);
  SwitchArray[4] = digitalRead(Pin7);
  SwitchArray[5] = digitalRead(Pin8);
  SwitchArray[6] = digitalRead(Pin19);
  SwitchArray[7] = digitalRead(Pin18);

//print the array out, has to be done each element at a time
//then do a println to start a new line to repeat it
  for (int i = 1; i < arraySize+1; i++)
   {
    Serial.print(SwitchArray[i]); // Print the variable and move to the next
   }
    Serial.println(); // create a new line
}

type or paste code here

```

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [July 22, 2025, 7:09pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/2 "2025-07-22T19:09:11Z")

</div>

The bounds of your array are [0..6], not [1..7].

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 22, 2025, 7:09pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/3 "2025-07-22T19:09:48Z")

</div>

```arduino
byte SwitchArray[7] = {0, 0, 0, 0, 0, 0, 0};

```

```arduino
SwitchArray[7] = digitalRead(Pin18);

```

SwitchArray[7] is outside of the array. The index to the array is from 0 to 6

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [July 22, 2025, 7:19pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/4 "2025-07-22T19:19:07Z")

</div>

A little simpler:

```arduino
// E21-003 Collimator Recognition
//Microcontroller being used is Leonardo variant
//polulu astar 3101 https://www.pololu.com/product/3101
//It is reading the configuration of switches off the PCB E33-031 via the E11-033 - Collimator Recognition Cable
//There are 7 switches on the collimator recognition PCB
//The mapping of hte Collimator recogntion Pins, through cable, to the Leo PCB is as follows
// Coll_PCB_SW1-> Cable#1 -> Leo#0
// Coll_PCB_SW2 -> Cable#3 -> Leo#1
// Coll_PCB_SW3 -> Cable#5 -> Leo#4
// Coll_PCB_SW4 -> Cable#7 -> Leo#7
// Coll_PCB_SW5 -> Cable#9 -> Leo#8
// Coll_PCB_SW6 -> Cable#10 -> Leo#18 (or 19)
// Coll_PCB_SW7 -> Cable#8 -> Leo#19 (or 18)

// ***Constants*** //
const byte arraySize = 7;
const byte SwitchArray[arraySize] = {0, 1, 4, 7, 8, 18, 19};

void setup()
{
  Serial.begin(9600);
  //Not necessary to set pins to INPUT because that is the default mode
}

void loop()
{
  delay(400);

  //print the array out, has to be done each element at a time
  //then do a println to start a new line to repeat it
  for (int i = 0; i < arraySize; i++)
  {
    Serial.print(digitalRead(SwitchArray[i])); // Print the variable and move to the next
  }
  Serial.println(); // create a new line
}

```

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [July 22, 2025, 8:05pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/5 "2025-07-22T20:05:36Z")

</div>

> [@](#):
>
> Digital Input producing non 0/1

😃 😃 A million years ago I had a boss that had a saying: _"Stranger than truth"._😃 😃

---

<div class="post-metadata">

**Author:** ![jmacione](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jmacione/32/1126937_2.png) [@jmacione](https://forum.arduino.cc/u/jmacione)\
**Post date:** [July 22, 2025, 8:32pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/6 "2025-07-22T20:32:53Z")

</div>

thanks all

yes, was out of bounds on the array  
very strange indeed, producing numbers that were non 0/1when reading outside the array

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 22, 2025, 8:40pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/7 "2025-07-22T20:40:42Z")

</div>

Not strange at all because you don't know what the memory location is used for in the sketch

For the benefit of anyone finding this topic in the future please post your revised, working sketch in full

---

<div class="post-metadata">

**Author:** ![jmacione](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jmacione/32/1126937_2.png) [@jmacione](https://forum.arduino.cc/u/jmacione)\
**Post date:** [July 23, 2025, 1:07pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/8 "2025-07-23T13:07:44Z")

</div>

```arduino
/ ***Definitions*** /
#define Pin0 0
#define Pin1 1
#define Pin4 4
#define Pin7 7
#define Pin8 8
#define Pin18 18   
#define Pin19 19

// ***Constants*** //
int collimator = 0; //initialize to nonvalid number
int valid_filter = 0; //initialize
byte SwitchArray[7] = {0, 0, 0, 0, 0, 0, 0}; //bounds starts at 0
 int arraySize = sizeof(SwitchArray) / sizeof(SwitchArray[0]);

void setup()
{
  Serial.begin(9600);
  pinMode(Pin0,INPUT);
  pinMode(Pin1,INPUT);
  pinMode(Pin4,INPUT);
  pinMode(Pin7,INPUT);
  pinMode(Pin8,INPUT);
  pinMode(Pin18,INPUT);
  pinMode(Pin19,INPUT);
}

void loop()
{
  delay(400);
  SwitchArray[0] = digitalRead(Pin0);
  SwitchArray[1] = digitalRead(Pin1);
  SwitchArray[2] = digitalRead(Pin4);
  SwitchArray[3] = digitalRead(Pin7);
  SwitchArray[4] = digitalRead(Pin8);
  SwitchArray[5] = digitalRead(Pin19);
  SwitchArray[6] = digitalRead(Pin18);

//print the array out, has to be done each element at a time
//then do a println to start a new line to repeat it
  for (int i = 0; i < arraySize; i++)
   {
    Serial.print(SwitchArray[i]); // Print the variable and move to the next
   }
    Serial.println(); // create a new line
 }

```

---

<div class="post-metadata">

**Author:** ![oqibidipo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oqibidipo/32/221794_2.png) [@oqibidipo](https://forum.arduino.cc/u/oqibidipo)\
**Post date:** [July 24, 2025, 2:36pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/9 "2025-07-24T14:36:20Z")

</div>

Let's see what's in memory:

```arduino
> avr-nm -CSn sketch.ino.elf
...
00800180 00000007 b SwitchArray
00800187 00000001 b timer0_fract
00800188 00000004 b timer0_millis
0080018c 00000004 b timer0_overflow_count

```

So `SwitchArray[7]` is `timer0_fract`; writing to it messes slightly with `millis()` and reading it gives varying results.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 20, 2026, 2:36pm UTC](https://forum.arduino.cc/t/digital-input-producing-non-0-1/1397301/10 "2026-01-20T14:36:53Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
