Hot answers tagged

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 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

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 ...


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

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

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 ...


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

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 ...


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

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 ...


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

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

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.


3

Don't use Vin as a logic source. Use the +5V pin. Also, disconnecting the pin is not the same as grounding it. It is "floating". For a proper test, connect a +5V to the pin, and follow it with a Gnd. A floating pin has an undefined logic level. What would work in your case is to have a (say) 1k resistor between D2 and Gnd. That way, the moment you ...


3

I suggest this simple circuit: simulate this circuit – Schematic created using CircuitLab Set both inputs to INPUT_PULLUP. If the input reads LOW, that means it has been grounded by the switch. Edit: Per Duncan’s request, here is the alternative circuit with the polarities inverted. With the switch’s common connected to Vcc, the inputs should be set ...


3

You made a few mistakes with the three lines, first one being: if (temp = 340) First, the single '=' is an assignment operator instead of a comparing operator. You want to use '=='. However, you need to check if it is within a range, so you need to use <= (to see if it is smaller or equal). Also you need to put them in the correct order, so you get ...


2

Only the leakage current on the input itself is constantly consumed if there is no external connection. This is usually much less than the waste caused by having the input floating. If a voltage between 0.8 V and 2 V is applied to the input for a prolonged period of time, this situation becomes critical and should not be ignored, especially with higher ...


2

Power is flowing from the analog pin, through the internal clamping diodes, to the Vcc line. Those diodes are however not designed to handle that much current, so don't continue doing this. Either also disconnect the ground wire from the battery, or simply add a resistor between the battery and the analog pin. Something like 10k. That way less than a mA of ...


2

As @KiraSan said, You need something larger than a byte for 9 bits. However: int tally; tally=0; for (char pin=1; pin<=9; pin++) { if (digitalRead(pin)==HIGH) { tally|=1<<(9-pin); } } This is done from memory and is untested, if anyone spots any errors, let me know. Explanation: tally is the sum (you should do something with this ...


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