4

I wanted to know if the reference voltage for the digitalRead() function could be set to a particular voltage, either with an external reference or internally.

In the Arduino reference under the constants heading they have mentioned that they use 3V as reference for the boards I'm using (an Arduino Uno R3). But I want to change it to be a little lower.

Is it possible and if so how?

migrated from electronics.stackexchange.com Feb 4 '15 at 6:58

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

6

You could try not digitalRead, but analogReadVoltage. Analog Read Voltage

From Arduino examples:

/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}
  • @SumanRoy: How does this help (changing the digital reference)? Or are you instead going to measure the voltage and make your own HIGH/LOW decision (in code)? – JRobert Feb 5 '15 at 20:47
  • @JRobert yes, you will have to make few tests, get your reference point ant everything above that point will count as "HIGH". Its up to your imagination :) – Martynas Feb 6 '15 at 6:59
  • @JRobert yeah that's it. Measure the voltage and return a HIGH LOW – Suman Roy Feb 9 '15 at 10:03
0

for a 5 volt Arduino anything over 2.7V will be considered as a digital HIGH whereas anything below 0.4V will be a digital LOW.

  • To stick to ATmega 328 datasheet (atmel.com/images/… p313), I'd say that anythng below 1.5V (0.3 x Vcc) is cnsidered LOW, and anythng above 3.0V (0.6 x Vcc) is considered HIGH. – jfpoilpret Feb 6 '15 at 6:35
  • ... and of course, anything in-between is undetermined, i.e. sometimes HIGH sometimes LOW. – jfpoilpret Feb 6 '15 at 6:35

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.