Detecting a voltage spike from a analogRead

I’m wanting to use Spark to detect a voltage reading from an alarm system. The alarm will put out 12 volts via its spec and when I put on a volt meter, around 13.95 for a period of 3 seconds, and then goes back to zero.

I’ve put a voltage regulator (3.3V 250mA - L4931) in line to drop the voltage down below 3.3. When I test the voltage with a volt meter on the other side of the voltage regulator, it will consistently put out 1.16 for 3 seconds.

What I’m trying to do is in the loop(), detect when voltage shows up. When using analogRead() I continually get 1.6 to 1.7 volts and it won’t detect a reading.

How best should I approach this as it seems it should be a simple task.

Thanks!

I don’t know why your regulator doesn’t work. Maybe grounding or ref issues.

However I would suggest you use an opto isolator to detect the voltage instead of reading it directly. This will be more safe since the opto isolators isolate one voltage from the logic electronics.

I will fetch for a schematic I posted here, and include it in this thread later.

2 Likes

Here’s a schematic that I used in a project, however in your case it will go the other way around… Instead of controlling from the Spark side you will receive. It acts like a switch.

Hope it gives you a fast start.

Additionally to @frlobo’s hardware advise, you might also try to detect your spike via an interrupt rather than polling.

Doesn’t address your current priblem, but just to show off :wink:

2 Likes

I second @ScruffR suggestion.

The extra work will make for a far better design. More reliable…

1 Like

@rwetzeler, both @frlobo and @ScruffR are dead on with their recommendations. Using a voltage regulator for level shifting a “logic” signal is not good practice. However, using a voltage divider and an opto-isolator creates an isolation between the high voltage and the Core. What if the regulator shorts and you get 13.95v to the Cores pin!!!

Following the interrupt idea would allows to detect the voltage “event” and if you need to measure the 3 seconds, you could do that part in loop(). :smiley:

2 Likes