-2

I'm completely new to Arduino or even micro-controllers, I'm not even good in physics.

First of all, I'll explain what I am trying to build:

I have an Arduino Nano, for a university project (computer science) I'm trying to make an alternative controller(HID). This controller will be a simple glove, which contains conductive yarn from the Arduino to each finger. If two fingers connect their conductive yarn, I know which fingers are connected and I map this to an input for the computer, which I connected to the Arduino.

For example, if the thumb touches the index finger, it means an X on the computer.

To get the code done is not the problem I guess.

enter image description here

Since I'm completely new, I have some pretty basic questions:

1) Can I use the circuit diagram I created or won't it work? Imagine the switches are my hand, which works like a switch.

2) Does my circuit need a connection to 5V and ground, or can one of the pins be a GROUND / 5V?

3) To know if a switch is active, do I have to watch for changes on the pin? For example, the pin is LOW, is it HIGH after the circuit is "closed"?

If you guys can provide me further information for my project or nice tutorials to get in touch with micro-controllers, I would really appreciate it.

Thank you in advance!

  • 1
    That is not even close to what almost every switch input tutorial explains. – Ignacio Vazquez-Abrams May 3 '17 at 22:29
  • Are both hands independent or would it be possible to e.g. contact left thumb with right index? – jfpoilpret May 20 '17 at 8:32
1

1) Can i use the circuit diagram i created or wont it work?

It won't work. The reason is when the switches are open the input pins are floating and that means they could be HIGHor LOW or flipping back and forth. You want the pins to be always in a specific state whether the switch is open or closed. To do this a pull-up or pull-down resistor is used. This resistor sets the pin to HIGH or LOW respectively when the switch is open but the value of the resistor is chosen so that when the switch is closed it overpowers the resistor and the pin reads the opposite state. Since you have your switches connected between the input pin and 5 V you would need to add a pull-down resistor to every pin. That's easy enough but there is an even easier way. The microcontroller on your Nano has internal pull-up resistors you can turn on by doing this:

pinMode(inputPin, INPUT_PULLUP);

See: https://www.arduino.cc/en/Reference/PinMode

So using the internal pull-ups meas you wouldn't need to add any extra components. But a pull-up isn't helpful if you have your switches connected to 5 V because that would make the pin read HIGH whether the switch is opened or closed. So you would need to connect the switches to GND instead. This would mean that the input pin will read HIGH when the switch is open and LOW when the switch is closed.

3) To know if a switch is active do i have to watch for changes on the Pin?

Of course. The easiest way to do this is with digitalRead().

See: https://www.arduino.cc/en/Reference/DigitalRead

You need to make sure your code is non-blocking. When blocking code like delay() is used the microcontroller will not be able to check the state of the input pins and so you could miss touches or have the controller not be responsive enough.

0

When you're dealing with switches, you need to watch out for 'bounce'. This means that a switch is never perfect and when it changes state from ON to OFF or vice versa, usually there are several fluctuations that take place before the switch settles on a final ON/OFF value.

You could debounce your switches by either hardware or software. If you're debouncing your switches by software basically you run a check on each switch to see if it's digital value has stabilised over some finite time period (usually a few milliseconds) and take action on the switch value only AFTER its value has stabilised.

Hardware debouncing makes use of capacitors in your circuit that prevent high frequency fluctuations in the line from reaching your digital pin. Put simply, the capacitor acts like a channel to 'drain' away variations in voltage. If you are implementing hardware debouncing, you can just do a digitalRead() to read your pin.

http://dduino.blogspot.in/2012/03/arduino-button-debouncing.html

  • You can also buy ICs that debounce switches. They are supposed to be for reset switches on microprocessors. – Code Gorilla May 4 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.