Skip to main content
18 votes
Accepted

What's the difference between analogWrite and digitalWrite?

digitalWrite will set the specified pin to one of two states - HIGH/LOW, which equate to 5v (3.3v on some boards) and ground respectively. analogWrite can vary by the type of output used. If applied ...
TanyaV's user avatar
  • 586
9 votes

What's the difference between analogWrite and digitalWrite?

analogWrite(): The analogWrite() method sets the value of a PWM output pin. The analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and ...
Hasan's user avatar
  • 1,476
7 votes

What's the difference between analogWrite and digitalWrite?

digitalWrite sets the output pin to either LOW or HIGH (where those voltages depend on the Vcc of the processor. For a Uno or Mega that would be 0V or 5V (or close to it). Here's a screenshot of ...
Nick Gammon's user avatar
  • 38.4k
7 votes

Digital Pins Question

The digital pins of the Arduino are rated to reliably deliver up to 20 mA. Their absolute maximum rating is 40 mA. Anything above that risks destroying the microcontroller. If your device is supposed ...
Edgar Bonet's user avatar
  • 43.3k
6 votes
Accepted

digitalRead keeps giving 1

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'...
jose can u c's user avatar
  • 6,974
5 votes

UNO's digital pin continue to read 1 for a while

Digital inputs should either be low or high. In this image acceptable input voltages on the left represent common TTL voltages based on a 0 to 5 volt range: It is bad practice to leave a digital ...
st2000's user avatar
  • 7,340
5 votes
Accepted

Digital I/O threshold voltages for ATmega32u4

LVTTL is Low Voltage Transistor-Transistor Logic. In general, the term "TTL" is used for a digital signal. The "Low Voltage" part is special, the ATmega32U4 switches from low to high (and vice versa) ...
Jot's user avatar
  • 3,246
5 votes
Accepted

Unable to use analog pins as digital inputs

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.
Majenko's user avatar
  • 105k
5 votes

Digital Pins Question

The most common solution is to use the digital output to turn on a MOSFET that supplies separate power to a high-current device that needs more current than the 20 mA that an ATmega328 microcontroller ...
RedGrittyBrick's user avatar
4 votes
Accepted

Interfacing Digital clock with Uno

It is likely that the alarm clock does not provide any voltage level (I mean GND) to the buzzer when it does not have to ring, the circuit is just left "open" then; it will provide a voltage level (...
jfpoilpret's user avatar
  • 9,132
4 votes

manual square wave period is off

From Arduino reference on delayMicroseonds: Currently, the largest value that will produce an accurate delay is 16383. This could change in future Arduino releases. For delays longer than a few ...
jfpoilpret's user avatar
  • 9,132
4 votes

Fool Proofing My Arduino IC Checker

I would connect each of the IC's IO pins to both a digital output and a digital (or analog) input of the Arduino, like this: simulate this circuit – Schematic created using CircuitLab Drive ...
Edgar Bonet's user avatar
  • 43.3k
4 votes
Accepted

Digital selection for gain control not working instead showing 0

pinMode( K1, INPUT ); with if(K1 == LOW && K2 == LOW) makes no sense. K1 is a pin number. LOW is a macro for 0 (HIGH for 1). You are comparing a static pin number against a static ...
Maximilian Gerhardt's user avatar
4 votes
Accepted

`LOW` being defined as `0` and `HIGH` being defined as `1` - is this a part of external specification?

The underlying reason for this question is to figure out whether code like digitalWrite(some_pin, true); digitalWrite(some_other_pin, !digitalRead(some_other_pin)); is a good programming ...
Majenko's user avatar
  • 105k
4 votes
Accepted

Plug in analog sensor into digital pin

According to SAMD21 the digital input pin detects HIGH if the voltage on pin is higher than 0.55 of supply voltage. So at 3.3 V it is 1.8 V. The input pin detects LOW if the voltage is lower than 0.3 ...
Juraj's user avatar
  • 18k
4 votes

Plug in analog sensor into digital pin

Yes. If you read the datasheet you will find a set of voltage specifications. The ones you are interested in are VIH and VIL. Most MCUs use a "Schmitt Trigger" for the inputs. This means ...
Majenko's user avatar
  • 105k
4 votes

If Arduino digital pins can be used as power supply pins then why do we need VCC pins?

Digital IO pins and Vcc are very different. When using the digital IO functionality of a pin, the pin is connected to the digital IO hardware inside the microcontroller. This hardware is a driver, ...
chrisl's user avatar
  • 16.3k
3 votes

How do you configure ADC7 on the Arduino Pro Mini as a digital output?

This may be a little left field, but I use the ADC6 and ADC7 inputs to detect switches. I just don't use the digitalRead() function, but instead use analogRead() function. Using a resistor network ...
Gordon Waldmann's user avatar
3 votes
Accepted

Trying to explain strange behavior when attempting to do a digitalWrite to A7 on a pro mini?

You are calling digitalWrite and digitalRead with argument A7. According to the file pins_arduino.h, A7 is defined as 21. Now, the two functions are defined in file wiring_digital.c, and the most ...
frarugi87's user avatar
  • 2,721
3 votes

What's the difference between analogWrite and digitalWrite?

digitalWrite sets the pin to an high or low value that remains at exactly that value until digitalWrite is called for that pin again. analogWrite sets the pin to have an oscillating value which has a ...
Code Gorilla's user avatar
  • 5,637
3 votes
Accepted

Not being able to use pushbutton

You seem to be suffering from three problems here: A lack of understanding how the button's pins are configured A lack of understanding of how breadboard works A strange notion (that I have seen ...
Majenko's user avatar
  • 105k
3 votes
Accepted

How can I get analog-in reading from Digital-PWM-out on the same board?

You are fine by doing that, but you won't get what you expect. A PWM signal isn't an analog value. It's a series of pulses, the duration of those pulses is set by the (not accurately called) ...
Gerben's user avatar
  • 11.3k
3 votes
Accepted

Arduino-based mains frequency monitor

I understand Arduino should be somewhat simpler [than PIC]. The whole Arduino platform (boards, core library and IDE) makes it super easy to get started and do simple things. However, if you want to “...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

Arduino-based mains frequency monitor follow-up

You should remove the capacitor. It won't remove any DC offset because there can be no DC offset. From where would the DC offset be relative? There is only two points in the circuit, and both of them ...
Majenko's user avatar
  • 105k
3 votes

Why would digital outputs on Arduino Due be less than 3.3V?

The output impedance for the MCU used in the Due is about 46ohm. Along with the relay's impedance this forms a voltage divider that results in a final voltage that is lower than the unloaded voltage ...
Ignacio Vazquez-Abrams's user avatar
3 votes

digitalRead keeps giving 1

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 ...
Juraj's user avatar
  • 18k
3 votes
Accepted

Fool Proofing My Arduino IC Checker

The simplest way to "fool proof" your system (i.e., to prevent damage by a fool, not make it so it always works right even with a fool) is to add a resistor to each connection. The resistor should be ...
Majenko's user avatar
  • 105k
3 votes

4x4 matrix keypad - Multiple inputs cause extra readings

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 ...
Nick Gammon's user avatar
  • 38.4k
3 votes

Digital Band pass filter arduino 1100-1300 Hz

You cannot use ^ as mathematical power symbol in C. Ini C it means the exclusive-or bit operation (hence the error showing it is a bit operation). For the mathematical power function, you should use ...
Michel Keijzers's user avatar
3 votes
Accepted

Analog vs Digital Accelerometers - pro's and con's?

The biggest difference is where the measurement (the conversion to digital) is done. On the digital accelerometer, it is done in the accelerometer itself. On the analog one it is done at the MCU. ...
Majenko's user avatar
  • 105k

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