# Set voltage level external interrupt Arduino UNO

#### imranahmed

Please let me know I connected a LDR to Arduino UNO at pin A0 analog pin and Arduino UNOs sleep and wake instructions are programmed. But only external interrupt is available for wake up of microcontroller cpu. I want to wake up microcontroller at a certain voltage level defined by me. Do we set external interrupt voltage to trigger at pre-defined level?

Full working code is below but voltage level to trigger external interrupt at pin2 is want to know?

Code:
#include <avr/sleep.h>
#define interruptPin 2
unsigned long lastTimeOut = 0;
unsigned long timeOut = 5000;
const int LDR_PIN = A0;

void Sleep(){
sleep_enable(); // Enable sleep mode
attachInterrupt(0,wakeUp, LOW); //Attach interrupt to pin 2
set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Full Sleep mode
delay(1000);
digitalWrite(LED_BUILTIN, LOW);// LED OFF
//delay(1000);
sleep_cpu();
Serial.println("Just Woke Up");
digitalWrite(LED_BUILTIN, HIGH);// LED ON
}
void setup() {
Serial.begin(9600);
pinMode(interruptPin, INPUT_PULLUP);
pinMode(LDR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
lastTimeOut = millis();

}

void loop() {
int v = (5*ldr)/1023;
Serial.println(v);
if((millis() - lastTimeOut) > timeOut){
lastTimeOut = millis();
Sleep();
}
//   delay(1000);
}
void wakeUp(){
Serial.println("Interrupt Fired");// message to serial port
sleep_disable();// Disable sleep mode
detachInterrupt(0);// remove interrupt from pin 2
}`

#### KlausST

##### Super Moderator
Staff member
Hi,

use a comparator IC.

Klaus

imranahmed

### imranahmed

points: 2

#### imranahmed

Hi,

use a comparator IC.

Klaus

Yes you are right, LM741 in non-inverting mode.

#### betwixt

##### Super Moderator
Staff member
A comparator would be far better than a 741 and you wouldn't need to give it a higher supply voltage.

Brian.

imranahmed

### imranahmed

points: 2

There are compound parts available whioch have a Vref and a
comparator in one package.

Regards, Dana.

imranahmed

### imranahmed

points: 2

#### imranahmed

There are compound parts available whioch have a Vref and a
comparator in one package.

Regards, Dana.
Can I use LM393 because it is only available here and if I would like to buy MAX954 or TLV3011 it will take some time to reach but I need urgently?

#### KlausST

##### Super Moderator
Staff member
Can I use LM393
it is a comparator.
Whether you can use it in your application depends on: power supply requirements, input signal requirements, ouput signal requirements, timing...
Did you give any electrical requirement or information?

Klaus

#### imranahmed

it is a comparator.
Whether you can use it in your application depends on: power supply requirements, input signal requirements, ouput signal requirements, timing...
Did you give any electrical requirement or information?

Klaus
Yes use for Arduino UNO external interrupt trigger at certain voltage level set by me and full code is available in first post

#### KlausST

##### Super Moderator
Staff member
Hi,

I did a search on the datasheet for "no power supply" and "certain voltage level" --> no results.
Let´s blame it on a bad datasheet. ;-)

Klaus

#### imranahmed

Hi,

I did a search on the datasheet for "no power supply" and "certain voltage level" --> no results.
Let´s blame it on a bad datasheet. ;-)

Klaus

Power supply is 5V and interrupt trigger voltage is 4V.

#### KlausST

##### Super Moderator
Staff member
Hi,

* datasheet on first page says LM393 has a supply voltage range of 2.0V ... 36V.
--> There is no doubt that 5V is within this range.

* datasheet says "input common mode voltage range" is 0V ... VSupply - 1.5V. So if supply voltage is 5v then the upper limit is 5V -1.5V = 3.5V.
--> 4V is not operational, but it will cause no damage.

Don´t expect that I read all datasheets for you.

Klaus

#### imranahmed

Hi,

* datasheet on first page says LM393 has a supply voltage range of 2.0V ... 36V.
--> There is no doubt that 5V is within this range.

* datasheet says "input common mode voltage range" is 0V ... VSupply - 1.5V. So if supply voltage is 5v then the upper limit is 5V -1.5V = 3.5V.
--> 4V is not operational, but it will cause no damage.

Don´t expect that I read all datasheets for you.

Klaus
Ok, I have to find one which is VSupply - (less than 1.5) means 1 or 0.5 but 0.5 is better.
0V.......VSupply - 0.5 = 5V-0.5V=4.5V??
--- Updated ---

Ok, I have to find one which is VSupply - (less than 1.5) means 1 or 0.5 but 0.5 is better.
0V.......VSupply - 0.5 = 5V-0.5V=4.5V??
If I change Power Supply to 3.3V instead of 5V.Will it within range? For LM393.
One more thing I want to add I can change detection level not necessary 4V 2.5V is good for 5V power supply.

Last edited:

You can use LM393 with its Vcc = 5V and a 2.5 V reference voltage, derived
from 5V or whatever.

However if the Vin to the comparator exceeds, over temp, Vcc - 2V phase reversal
will occur because your input exceeds 3V (Vcc of 5V - 2V limit on common mode
over temp). See ap note on this.

Note in ap note an LM339 (not LM393) can have one input, say Vref, in the CM range and if other
input goes outside CM range (within absolute max specs) no phase reversal will occur.

Either scale the Vin low enough with an R divider and use a low Vref, say a 1V for trip level
(same as Vref) or get a comparator, single supply, that common mode rail to rail on
input. Even a R-R OpAmp could be used in comparator mode (if you do not need open collector
output). Or use a zener on input to clamp it to stay in CM range.

Don't forget to put some hysteresis around it to handle noise suppression.

Regards, Dana.

Last edited:
imranahmed

### imranahmed

points: 2

#### KlausST

##### Super Moderator
Staff member
phase reversal
will occur because your input exceeds 3V
I don´t think so.

AN says: phase reversal, occurs when the input of the comparator violates the negative common-mode voltage range.

Klaus

I don´t think so.

AN says: phase reversal, occurs when the input of the comparator violates the negative common-mode voltage range.

Klaus
I dont think so -

The range between 3.5 V and 4 V is the gray zone, where the device appears to still function at 25°C and
above, but critical specifications are deteriorating, such as offset voltage, bias current and particularly
propagation delay as the input stage is gradually cut off. These effects may not be immediately apparent.
Operating at low temperatures will cause failures. Operation in this zone must be avoided.
Between 4 V and 5 V, and even up to 36 V, the input stage is cut off and input bias current is falls to zero.
The actual cut-off threshold depends on temperature. Comparator operation ceases. DO NOT operate in
this area!
" Comparator operation ceases. DO NOT operate in this area!" If comparator operation ceases what is the output ?
I would say undefined, and could be phase reversed.

Regards, Dana.

#### KlausST

##### Super Moderator
Staff member
I dont think so -
I just focussed on section "2.7 Phase Reversal".
But I have to admit that "non functional" may include phase reversal.

Klaus

#### imranahmed

You can use LM393 with its Vcc = 5V and a 2.5 V reference voltage, derived
from 5V or whatever.

However if the Vin to the comparator exceeds, over temp, Vcc - 2V phase reversal
will occur because your input exceeds 3V (Vcc of 5V - 2V limit on common mode
over temp). See ap note on this.

Note in ap note an LM339 (not LM393) can have one input, say Vref, in the CM range and if other
input goes outside CM range (within absolute max specs) no phase reversal will occur.

Either scale the Vin low enough with an R divider and use a low Vref, say a 1V for trip level
(same as Vref) or get a comparator, single supply, that common mode rail to rail on
input. Even a R-R OpAmp could be used in comparator mode (if you do not need open collector
output). Or use a zener on input to clamp it to stay in CM range.

Don't forget to put some hysteresis around it to handle noise suppression.

Regards, Dana.
I am very thankful to you Dana, you give a very important information. I will do it.