Hot answers tagged

23

You're getting noise pickup on the input pin when the button is not pressed. You need a pull-down resistor, about 10 kΩ to ground, to quiet the noise when the switch is open. Or even easier, use the built-in pull-up resistor in the Arduino, which is ~10 kΩ to +5 V, wire your button to ground instead of +5 V, and reverse the if tests to test for logic LOW ...


6

You can measure a single "pure" frequency by counting the number of times that the pin changes, by using the inbuilt timers. Here is a sketch from my page about timers that accomplishes that: // Timer and Counter example // Author: Nick Gammon // Date: 17th January 2012 // Input: Pin D5 // these are checked for in the main program volatile unsigned long ...


6

40.0mA. The Arduino UNO Digital IO pins are connected directly to the IO pins on the ATMEGA328P processor. From page 299 of the data sheet for that processor... Note that there is also a total current limit for all output pins combined, and that the voltage starts to drop as the current goes up.


6

In your code you would use a 16 bit unsigned integer as your variable. As there is no such thing as a 9 bit type. If the pins correspond to different ports on your micro, you basically do this: Read the pin value from the port register, and bit shift to the right bit position then OR with the variable. Say you had 8 of the LEDS on PORTB (pin 0 - 7 )and ...


6

You have set Pin 2 to HIGH, which is 5V. You have set Pin 4 to INPUT_PULLUP, which means if no signal is driving it, it will be HIGH. You have connected a button between Pins 2 and 4. So, if you don't press the button, the input is pulled HIGH. And if you do press the button, Pin 2 is driving it HIGH.


5

Yes you can use them as ordinary digital io pins. PWM is essentially a normal digital output pin that is repeatedly turned on and off at a high rate. The magic is that the turning off and on is done in the hardware according to the duty cycle (I.e. there is no need for software to perform the on/off operations) . This is why only some pins can do h/w PWM, ...


5

If all switches have one input grounded, you cannot use matrixing. In any case, the best you could do would be a 2 * 3 matrix, which uses 5 signals, the same as individual switching (though you may be able to share the strobes with other signals e.g. display strobes) If you are allowed to use an analog input you can pull the input high with one resistor, ...


5

Michel Keijzers pointed out the issues you have in your code. But then there is also an issue with your circuit: if you press any of the push buttons, the analog input pin gets connected to one of the nodes of the resistor ladder, and you get a well defined voltage reading. Good. However, if none of the buttons is pressed, the input is not connected to ...


5

Like often, the answer is: It depends. Generally it is non-blocking programming, when you do only short things on each loop. What exactly can be considered short depends on the situation, meaning, what else you want to do. For example: You are reading an analog value on every loop. The analogRead() will take about 100us (reference). I assume, that your ...


4

I ran across this post and thought that a more in depth explanation should be given on why when using digital inputs that more times than not you will need to use the pull-up resistors. When you define one of the pins to be a input the chip measures the voltage on the pins, if the voltage measures more than half of the VCC voltage the input is off. What ...


4

Check the datasheet, probably just search for "internal" or "pullup" I believe there are little more pins/ports as portB, so they should all have internal pull ups.


4

The standard Arduino way of doing this is to use pinMode(). It's not fast, but it's easy to understand, especially for beginners. And it's portable across architectures. If you want to go fast, then you should skip the Arduino functions and use port manipulation, and avr-libc. The standard avr-libc way of doing what you want is: DDRF = _BV(PF2) // set ...


4

If your signal is a pure 1 kHz tone, then you should use Nick Gammon's counting method, as it is the most straight-forward solution. If, however, you are picking the signal through a microphone, chances are you will also get some background noise, and this can make the counting method unreliable. In such a case, you will have to use some kind of ...


4

What will happen is you will damage your LED and/or your Arduino since you haven't mentioned a current-limiting resistor (220 ohms could well be suitable). However the general concept is perfectly sound. You could, for example, have two LEDs, wired in opposite directions. By bringing one pin LOW and the other HIGH, one LED would light up, and by reversing ...


4

A6 and A7 are special on the nano. They are the only pins that can't be used for digital. They are only analog inputs.


3

When the internal pullups are activated, a small amount of current is sourced by the pin's circuitry whenever the input is low. That means that to drive the signal low, an external driver must not only sink current to discharge the capacitance of the internal and external circuitry, but it must continue doing so to dominate the attempt of the internal ...


3

That device (datasheet) puts out 3.3V on the OUT pin, not 5V: ◦ TTL output: 3.3V, 0V The excess cable is most likely picking up EMI and creating spurious pulses on the input. There are two basic ways of combating this: Increase the drive strength (especially the sink capacity) of the output Implement a balanced line communication system You can combine ...


3

You mentioned 2 items: the supply voltage to the Arduino and scaling up to 24V output. If the supply voltage you have available is 24V, then I would suggest you look for a DC-DC converter that scales down to 12V. Or, if you are looking to design your own PCB then perhaps use a 78xx voltage regulator. The 78xx are 3 pin devices and only require 2 caps to ...


3

Something like this: typedef union NUM_9_BITS_t { unsigned int U; struct NUM_9_BITS_FIELD { unsigned int BIT0 : 1; unsigned int BIT1 : 1; unsigned int BIT2 : 1; unsigned int BIT3 : 1; unsigned int BIT4 : 1; unsigned int BIT5 : 1; unsigned int BIT6 : 1; unsigned int BIT7 : 1; ...


3

It seems you haven't connected the circuit ground to the Arduino ground. This is essential to complete the circuit between your breadboard and the Arduino. Without the ground connection the electrons that you send to the Arduino have no way of getting back again. Here's a couple of diagrams that I drew for another question which deals with the Arduino ...


3

.parseInt() reads incoming text up until either it times out or until it reads something that isn't a number. You are sending a number, and most likely a line-ending. If that line-ending is a simple \n then that will trigger the "end of number" and will be discarded and the number returned. However, if you are sending \r\n (i.e., CRLF) then you effectively ...


3

My guess would be that you're getting noise interference on the line and it's too much for the Arduino's little internal pullup. Try adding an external pullup resistor - say 5k-10k (exact value is not critical).


3

Yes it will, try it. This is one of the way to use a LED as a light sensor and light source by connecting it to two different Digital pins. Ref.: https://playground.arduino.cc/Learning/LEDSensor


3

You can test it easily by calling the function twice directly after each other. If the first time a true is returned and the second time a false, the state is internally reset. But probably because after you call the fell function, the internal state is reset, so after the call not a new fell has been happened. So store the return value of the fell and ...


3

https://github.com/thomasfredericks/Bounce2/wiki I'm not familiar with the Bounce(2) library, but looking at the above site, it looks like "fell" is more of an "instant" thing, where it isn't something that maintains state over the Arduino loop. Seeing as we are human, we can't (normally) push buttons at the same exact time. This means that we would ...


3

Solved it, but here is the solution, so there is an answer available for anyone who might encounter the same problem... Quality check your protoboards. This is making me feel stupid. The protoboard I used had a faulty connection on the blue line I was using, causing an inevitable floating input. So relieved I found the problem, and yet so annoyed! Take ...


3

There are to simple options how to connect a simple button. You mixed them. Better option is connect the button between pin with INPUT_PULLUP and ground. The pin is HIGH when the button is open and LOW when the button grounds the pin. This option is better because if you disconnect the button, the pin is still pulled up to HIGH and not floating. If you ...


3

I have a post about keypad matrices which discusses this issue. The issue with keypads is, that if you don't install diodes, if three keys are pressed the current finds its way around those three keys and it looks like a fourth is pressed. If you install diodes, like this, the issue goes away: It can be a little tedious to do, but I managed it the other ...


3

You need to enable the internal pull-up resistors which are designed to prevent undefined input states on unconnected inputs. Change pinMode(5, INPUT); to pinMode(5, INPUT_PULLUP); For more information on this see Arduino digital pins.


3

No. HDMI uses multiple serial data streams at gigabit rates. No Arduino is ever going to do that sort of thing. If you want something programmable to do that kind of thing you need an FPGA.


Only top voted, non community-wiki answers of a minimum length are eligible