This is running off 4.5v batteries / 5v USB, the voltage regulator section is removed and IC2 is an LM324. ICB2 output (pin 7) connects directly to the Arduino interrupt pin via CONN 1-5.
I've got this sensor board sending a normal HIGH signal (~3.7v), triggered LOW (~0.7v) to my sleeping Arduino interrupt from the LM324 (ICB2) output. The problem I'm having is the interrupt is being triggered and waking the Arduino from sleep continuously. The sensor board seems to be working properly and keeping a steady output while the Arduino is awake, so I'm confused to why the Arduino keeps detecting a low signal upon sleep. Is the logic voltage too sloppy? Am I missing some hardware between the IC and Arduino?
For the unused op-amp, connect the output to it's inverting (-) input, and connect the non-inverting (+) input to to +V or GND. This makes the spare amplifier into a unity-gain voltage follower ... the existing method could be a source of noise.
The LM324 is not rail to rail. The 3.7V to 0.7V output levels are wasting 2V of noise immunity ... check the DC characteristics of Arduino's MCU to see how much is left.
Try a strong external pull-up (i.e.330 ohm) on the interrupt.
You should put the output of the opamp through a schmitt-trigger like a 74HC14 which
has a decent amount of hysteresis really - the ATmega chips have only a small amount.
A 'scope is needed to debug analog circuitry like this really...
I'm seeing a blip on my voltmeter while measuring between the signal output (from the LM324 pin 7) to ground at the moment I put the Arduino to sleep. Maybe it is a power issue.
Tom: I read through the datasheet as you suggested, but I may have missed your point. Are you suggesting power supply interference between the analog and digital circuits? I didn't design this circuit myself. I borrowed it from a magazine hoping to get it working with Arduino using my very limited knowledge of electronics, so you might have to dumb things down for me. Sorry.
dlloyd: I tried an external pullup resistor to no effect. On +5v USB power, my HIGH coming off the LM324 is 4.0v. I think this is within the Arduino's range, but I'll wire up a pot and test. If I send the signal through the last opamp on the LM324, I won't get any wider voltage range right? You're saying it might clean up the signal though. If you know of a low power rail-to-rail equivalent I can drop in, maybe that would fix things.
MarkT: I think I have a 74HC14 laying around here somewhere. I'll try to breadboard it up and see what happens.
I'm seeing a blip on my voltmeter while measuring between the signal output (from the LM324 pin 7) to ground at the moment I put the Arduino to sleep. Maybe it is a power issue.
This is the main problem. Unless you can track it down elsewhere, I think the blip could be because both unused terminals of the spare op-amp on the same IC are connected to ground. Any very slight voltage difference on these terminals could cause its respective output to randomly oscillate. Try connecting it as a voltage follower.
EDIT:
Voltage follower connections:
Connect the unused + pin to any of the other op-amp outputs.
Connect the unused - pin to the unused output pin
You seem to be putting an amplified signal out on the same connector
as the input signal came in on - a recipe for unwanted feedback and oscillation
I fear. How much gain does the circuit have?
The sensor board is for a magnetic coil used to detect vehicles for driveway alarms and automatic gate openers.
Ok, I've got the unused opamp terminated properly and checked the logic levels. The interrupt is being triggered immediately after I put Arduino to sleep, otherwise, the signal and logic are sound. I just can't get it to stay asleep. Now I'm just not sure if it's a hardware or software issue. I'll post my code if I'm still having issues after trimming it down to the minimum.
You seem to be putting an amplified signal out on the same connector
as the input signal came in on - a recipe for unwanted feedback and oscillation
I fear. How much gain does the circuit have?
The connector is basically a terminal block, but I get your point. I'll look into it. The article I got the project from states the amplification can be up to 500,000x.
Ok, it's definitely a hardware issue. If I disconnect the input signal to the arduino interrupt before entering sleep and then reconnecting the input a second later, everything works normally.
Is there a relatively simple hardware solution to do this?
YES it is a hardware problem.
The LM324 are an old bipolar konstruktion with an NPN PNP output, teoreticly the output voltage can not go under 0,7 volts. In practise not under 1 volt.
On the schematic there are a ICL 7641 witch are rail2rail and can pull down to almost 0 volt
Try a PULLDOWN ( not pullup as dlloyd suggest) as low as 1 kOhm, perhaps some testing about the value.
Change components without checking the data sheets can cause problems.
Pelleplutt: The original schematic did call for an LM324. When I drew up the schematic in Eagle, I couldn't find the LM324 in the library, so I used another chip with the same pinouts. Sorry for the confusion.
TomGeorge: It seems to make no difference if the coil is hooked up or not. Using battery or USB power gives the same results.
I have a script for testing the sensor that simply Serial.prints a message when the coil is triggered. Using this script, it appears the hardware works perfectly, either by waving some metal over the coil, or using the test button on the board. No false signals. It's just that one blip on the sensor wire at the moment I put the arduino to sleep, looping the wakeup via interrupt that's driving me crazy. Ugh, it's maddening. It's probably something obvious and stupid too. I'm over my head here, and I fully appreciate the help, guys.
That second-to-the-last Op Amp should be a comparator. There are many reasons why it is a bad idea to use an Op Amp as a comparator. One, as has been pointed out, is that this particular Op Amp cannot pull all the way down to the negative supply rail (ground, in this case).
I think the blip is just inherent to the sensor circuit design. Note that the power supply range of the LM324 is 3-32V. During power down, as the voltage drops below 3V (out of range) is probably when the blip is created. Note that the the output of the LM324 (CONN1-5) never goes high impedance during power off. It is never switched out so the pullup configuration of Arduino pin 2 can never take over.
Perhaps adding an analog switch like this could resolve the problem.
dlloyd: I don't think I'm understanding you. The sensor board never powers down. What voltage is dropping below 3V?
If I did use an analog switch to turn off the signal using an output from the arduino before sleeping, how would I get it to switch back a set amount of time after sleep? Timer? RC charging?