Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Hot answers tagged

50

A common way to expand the set of available output pins on the Arduino is to use shift registers like the 74HC595 IC (link to datasheet). You need 3 pins to control these chips: Clock Latch Data In a program, you pass on the data one bit at a time to the shift register using the shiftOut() command, like so: shiftOut(dataPin, clockPin, data); With that ...


30

AREF: This is the voltage reference analog-to-digital converter (ADC). It can be used instead of the standard 5V reference for the top end of the analog spectrum – for example, if you wanted to use the ADC to monitor a signal that had a 0-1.5 volt range you could get the full scale of the ADC by connect AREF to a 1.5V signal. DO NOT CONNECT A SIGNAL OUTSIDE ...


27

There are two ways you can get more pins out of an arduino. The first way is by using the Analog pins as digital output pins, which is really easy to do. All you need to do is refer to A0-A5 as pins 14,15,16,17,18,19. For example to write high to pin A0 just use digitalWrite(14, HIGH). The other way to get more pins out of the Arduino is by using a Shift ...


26

You can do this using external interrupts. Most Arduinos only support this on a limited number of pins though. For full details, see the documentation on attachInterrupt(). Assuming you're using an Uno, you could do it like this: void pinChanged() { //... } void setup() { pinMode(2, INPUT); attachInterrupt(0, pinChanged, CHANGE); } void loop()...


22

The problem is specifically pins 0 and 1. Although they can be used as regular digital IO pins, they also serve as the RX and TX pins for the Uno's serial port. The USB connection (for uploading sketches etc.) is routed to the same pins internally. Unfortunately that means anything connected on pins 0 and 1 can interfere with the serial connection, ...


18

If you want to drive LEDs, then you can also use a MAX7219 that can drive 64 LEDs, without extra circuitry (no need for transistor to amplify signal). Driving a MAX7219 requires only 3 output pins on Arduino. Also, you can find a few Arduino libraries for it. You can also chain several of them if you need to power more than 64 LEDs. I have used it ...


18

From page 411 of the ATmega328P data sheet, we have a graph of the output current vs voltage. We can see over the the 20mA range of output currents, we drop ~0.5V, giving an approximate internal resistance of 25Ω. A typical LED has a forward voltage of about 2V. Therefore, we end up in the situation where we will drop 3V over the 25Ω internal resistance ...


17

You can use Charlieplexing. With this technique you can directly drive n*(n-1) LED's from n pins. So with 3 pins you can drive 6 LED's, 4 pins - 12 LED's, 5 pins - 20 LED's and so on. Exemple: Six LED's on 3 Pins PINS LEDS 0 1 2 1 2 3 4 5 6 0 0 0 0 0 0 0 0 0 0 1 Z 1 0 0 0 0 0 1 0 Z 0 1 0 0 0 0 Z 0 1 0 0 1 0 0 0 Z 1 0 0 0 0 1 0 0 0 Z 1 ...


16

To make explicit the implicit parasitic capacitance on the pin.


16

The VIN pin is directly connected to the USB's 5V supply. Which means that when the board is powered by USB you can take 5V out of that pin. You cannot control that voltage. It is always on, and always 5V (or whatever your USB port happens to provide - 4.75v - 5.25v). You must never ever connect VIN to a power source and connect the USB socket. That can ...


13

To drive such high currents, you may have to cascade several transistors (you can also use a Darlington transistor). There are arrays of Darlingtons mounted in a chip (e.g. the ULN2803A has 8 darlington transistors, but is limited to 500mA). You probably will have to deal with higher power transistors; as an example I have found STMicroelectronics TIP110 ...


13

I2C (Wire) You can use the I2C protocol (Wire library) to connect to other devices such as port-expanders. For example, the MCP23017. I used one of those chips to connect to an LCD board. The MCP23017 has 16 ports, which can be configured as inputs or outputs. As inputs they can raise interrupts if desired. Example of connecting 13 of those 16 to the LCD:...


12

Concerning the AREF pin, you have to remember that the Arduino comes with a 10bit ADC (Analog-Digital-Converter), which converts incoming voltages between 0V and 5V to integer values between 0 and 1023. This results in a resolution of roughly 4.8 mV. If a sensor only delivers a lower maximum voltage, it is resonable to apply this voltage to the AREF pin, ...


12

am I going to fry my board? Pretty likely outcome. Here's why: The Arduino Uno uses the atMEGA328 microcontroller, which has an absolute maximum rating of 40 mA source or sink per GPIO. Also, the total current through the supply or ground rails (i.e. the total of all current OP wants the GPIO pins to sink, or source) is rated to a maximum of 150 200 mA. ...


12

Shift registers have been mentioned in other answers, and they are definitely an excellent choice for many projects. They are cheap, simple, moderately fast, and can typically be chained together to add more outputs. However, they have the downside that they usually need exclusive use of several pins (between 2 and 4, depending on how you set them up). An ...


12

Any floating pin will act as an antenna, and may interfere with values around it, this is one of the major disadvantages of using analog. To get the most accurate readings with minimal amount of interference, you can pull all unused inputs to ground. The accuracy will not change, as the accuracy is determined by the sensor itself. However it will reduce ...


12

Leaving series resistors out will definitely greatly (exponentially) shorten lifetime of both the controller and the LED. Absolute maximum ratings for most AVRs are (a.o.): max. 40mA per GPIO pin max. 200mA per package. A new Arduino sets you back $20 or more, a fist full 220 ohm resistors sets you back 1$. When treated within spec, an Arduino (and LEDs ...


11

There are three things you can do: Remove the bootloader entirely and program the board with a hardware programmer (USB-ASP, Another Arduino, etc). Edit the bootloader source, recompile, and reinstall it to the board using a hardware programmer (as in option 1). Just don't use pin 13 for the relay. Of the three options the third one is by far the simplest.


11

You have your parameters the wrong way round: analogWrite(2, 100); analogWrite(6, 200); However: pin 2 on the Uno cannot do PWM, so you will have to pick a different pin. Look for the pins marked with ~ - they are the PWM pins. On the Uno that is pins 3, 5, 6, 9, 10 and 11.


10

SVG = Signal, Voltage, Ground. The Signal pin will carry the actual output, which may be high or low at any given time. It's basically just a male version of the corresponding standard GPIO pin. The Voltage pin will always be high (which can be 5v or 3.3v on this board, depending on the output level switch). The Ground pin is exactly what the name suggests -...


10

Contact Bounce This is known as contact bounce and happens when the metal contacts in the button or switch bounce against each other when you push it. The microcontroller is fast enough to pick up these bounces and, as far as it's concerned, you're toggling the switch many times in as much as 10 milliseconds of time. Different switches and buttons will ...


10

These are the In System Programming (ISP) pins. They are used to program the microcontroller without using the bootloader. The bootloader is a program already loaded into the flash of the microcontroller that allows the program to be loaded into the microcontroller through the Tx & Rx serial lines and hence not requiring a programming device. Using ...


10

It is quite easy actually: Serial.print("number of digital pins: "); Serial.println(NUM_DIGITAL_PINS); Serial.print("number of analog inputs: "); Serial.println(NUM_ANALOG_INPUTS); Note that these are compile-time constants defined as macros in a file named pins_arduino.h. There is one such file for every board supported by the Arduino environment. Just to ...


10

ICSP stands for In Circuit Serial Programming, which represents one of the several methods available for programming Arduino boards. Ordinarily, an Arduino bootloader program is used to program an Arduino board, but if the bootloader is missing or damaged, ICSP can be used instead. ICSP can be used to restore a missing or damaged bootloader. A typical ...


10

No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons: The Arduino data pins can't source (neither sink) enough current for that to work. The inductive kickback of the motor could fry Arduino pins. The right way to do what you want to do is using an H-bridge controlled by your Arduino data pins. There are lots ...


9

Your first snippet is the correct solution. pinMode(pinnumber,OUTPUT) digitalWrite(pinnumber,LOW) Be careful though, you can only sink up to 6mA or 9mA per pin (as per the documentation ["Input and Output" section], I never tried more). If you need more current, use a transistor (this looks like a good example, you just need to invert the output pin to ...


9

The link you provide looks rather old and I don't think it applies to UNO Revision 3 as it has more pins than on the diagram you show. I suggest you rather take a look at this Arduino UNO link which contains uptodate information about the UNO; in there you will see that for R3, the "power rail" has been extended and has the following pins, left to right: 1 ...


9

It is possible to use the LED on pin 13 again by disabling the SPI bus that is used by the SD library to read/write data to/from the SD card. To disable the SPI bus, simply call SPI.end() after closing the file on the SD card.


8

In addition to Ricardo's answer, what Wikipedia states on shift registers: One of the most common uses of a shift register is to convert between serial and parallel interfaces. [...] SIPO registers are commonly attached to the output of microprocessors when more General Purpose Input/Output pins are required than are available. This allows several binary ...


8

For a 5V logic output to a 3V3 logic input, you can use a resistive divider to lower the voltage. When unloaded, a 3V3 logic output is just enough to drive a 5V logic input. Check the AVR datasheet for the exact voltages (0.6 × Vcc = 3V, found under DC Characteristics in the datasheet). In other words, with a little bit of special care it may just work. To ...


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