Go Down

Topic: Read Binary value from multiple pins at once (Read 129 times) previous topic - next topic


I'm trying to connect my arduino to a coin counter (like the ones in vending machines).
Depending on the coin I put in, the counter will give a binary value spread over 6 output lines.
So now I need to read these values on my Arduino.

Will this work when I use the PIND and connect the counter outputs to my arduino ports 0-6?
Will using the PIND variable in the loop trigger a 'DigitalRead' on all pins at once?

Code: [Select]

void setup(){}

void loop()
  Serial.println(PIND); // will this trigger the read on pins 0-7?


Nov 24, 2016, 01:26 pm Last Edit: Nov 24, 2016, 01:26 pm by groundfungus
Code: [Select]
void setup(){}

Without Serial.begin(BAUD?) in setup() there will be no serial output.


Nov 24, 2016, 01:31 pm Last Edit: Nov 24, 2016, 01:33 pm by J-M-L
Probably better to use Port registers B which maps to digital pin 8 to 13 rather than D (digital pins 0 to 7) because you have the Serial Port in that one so you need to be a bit more carful how you write there (if you need to write). if it's only reading, then indeed D2 to D7 would give you 6 easy pins to read too (as would D8 to D13)

see PortManipulation
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums


Nov 24, 2016, 01:44 pm Last Edit: Nov 24, 2016, 02:12 pm by outsider
Put the coin acceptor lines on pins 2 - 7, then: EDIT: added prntBits()
Code: [Select]

void setup(){
void loop(){
  byte val = PIND >>2;

void prntBits(byte b)
  for(int i = 7; i >= 0; i--)



Nov 24, 2016, 02:01 pm Last Edit: Nov 24, 2016, 02:02 pm by J-M-L
The way I understand the registers by the way, is that they are the pins
While it's a bit of a technical shortcut blasphemy :), you can indeed intellectually picture such a register that way

So when you take a snapshot of the register values, you are actually looking in one go at the values of all the pins at that "instant" (at that cycle of the processor which takes some time, not an infinitely short moment)

Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131