adjusting digital HIGH/LOW threshold

hi:
Does anyone know how to change the threshold for digital pins to determine if a signal is HIGH or LOW? I remember reading that the threshold is 1000, can this be lowered?

Best,
-n

Hi Nima,

I think the logic threshold for the digital pins is set within the chip's architecture... it's not software alterable, as far as I know.

Normally in this case you would just put a comparator on the input..something like this 741 circuit.

comparator diagram

Try using a 741 or similar op amp.

Just put a 100K potentiometer on the op-amp's non-inverting input. That pot becomes your threshold setting.

This way you can change the threshold at the comparator's input, and have this decision come out as 0/5V.

D

Greetings,
The MEGA8 and 168 chips have an internal comparator.

Check out the data sheet
The comparator can be set a number of different ways:
internal reference voltage – OR – ref voltage on pin AIN0 (Arduino Digital 6)
Measure the voltage on AIN1 (Arduino Digital 7) – OR – via the A2D multiplexer

Here is an excerpt from my code.
This is for a MEGA8 the register names may or may not be the same for the 168.

I am using the default method comparing AIN0 (Arduino Digital 6) with AIN1 (Arduino Digital 7)
The output goes to the ACO bit of the ACSR register.
You can also set up an interupt based on changes to ACO

void setupComparator(){
SFIOR &= ~_BV(ACME); // clear ACME - set comparator to have AIN1 - this is the default anyway
ACSR &= ~_BV(ACD); // turn comparator on
}

byte comparatorBowl(){
return(ACSR & _BV(ACO)); //led is set if ACO is set
}

I hope this helps
Kirk
PS you could just use analogRead

You can raise the whole signal voltage by connecting the signal ground (from the source you want to measure) to the voltage reference (voltage regulator of your choice). For example if you want to raise your threshold by 1.8v, you could use BA18BC0T voltage regulator. Similarly you could lower your threshold using negative voltage source. Connect VCC to 5v usb power, ground to arduino ground, and 1.5v to the signal ground

This approach would be the easiest if you want to change all of your digital input threshold. It requires an additional voltage regulator but it's much easier than connecting a comparator IC (LM339N) for every single channel.

You can raise the whole signal voltage by connecting the signal ground

No this gives you all sorts of problems, please don't attempt this you will blow up your Arduino.

Another option for a voltage comparator chip is the TLC3704. I've used it with a Hall-effect sensor and the Arduino.

can anyone provide more info on KirkCharles comparator trick, specifically for the 328P?

See section 22 of the data sheet page 242. It is a single comparator in the analogue input circuitry using two of the analogue input pins.

From the introduction it says:-

The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set. The comparator's output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparator output rise, fall or toggle.

Thanks Grumpy. Just recently learning my way around the datasheet. Will try this later.