imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,492
#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 ldr = analogRead(A0);
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
}
Hi,
use a comparator IC.
Klaus
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?There are compound parts available whioch have a Vref and a
comparator in one package.
MAX954 Ultra-Low-Power, Single-Supply Op Amp + Comparator + Reference | Maxim Integrated
The MAX951–MAX954 feature combinations of a micropower operational amplifier, comparator, and reference in an 8-pin package. In the MAX951 and MAX952, the comparator's inverting input is connected to an internal 1.2V ±2% bandgap reference. The MAX953www.maximintegrated.com
Regards, Dana.
it is a comparator.Can I use LM393
Yes use for Arduino UNO external interrupt trigger at certain voltage level set by me and full code is available in first postit 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
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
Ok, I have to find one which is VSupply - (less than 1.5) means 1 or 0.5 but 0.5 is better.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
If I change Power Supply to 3.3V instead of 5V.Will it within range? For LM393.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??
I don´t think so.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
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!
I just focussed on section "2.7 Phase Reversal".I dont think so -
I am very thankful to you Dana, you give a very important information. I will do it.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.
**broken link removed**
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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?