Hello, newbie post - in short, i have had a problem where someone has been stealing copper cabling. I thought it would be easy enough to put a device on the end of the earth cable - as far from earth point as possible, once someone cuts the earth cable - a pin triggers an alarm. I used this tutorial
-- thinking instead of using onboard GND to pin 8, i could use my home earth in pin 8.
But it constantly triggers alarm - i am assuming this is because the home earth has a potential difference(voltage) on it compared to the onboard GND?
How do i make home earth/GND on pin 8 trigger a change when it is removed from pin8?
Any thoughts or ideas?
I have tried the following parameters from the attachInterrupt() method.
LOW to trigger the interrupt whenever the pin is low,
CHANGE to trigger the interrupt whenever the pin changes value
RISING to trigger when the pin goes from low to high,
FALLING for when the pin goes from high to low.
The Due, Zero and MKR1000 boards allow also:
HIGH to trigger the interrupt whenever the pin is high.
Without seeing how you have it wired up it's hard to comment constructively. I can see possible problems with what you are trying to do but they would be speculation without knowing exactly how you have wired things. Please produce a schematic, hand drawn and photographed is fine if that's what you need to do. Please post it following these instructions: How to post an image
I am particularly interested to know how the cable you are monitoring is connected and how it is grounded, and how your monitoring circuit, including Arduino or other electronics is grounded.
Whatever you try, interrupt is not the correct tool for this job.
Such a system as the OP proposes will never work reliably because of all the changes in voltages caused by ground currents, as he has discovered.
The only reliable way to sense what he is trying is to feed a known current through his wire and back through his house ground, if that really exists. That current must be larger and in the polarity to mask any of the stray currents in the wire/ground.
Take a look at [u]this exmple[/u]. If you bypass the switch and hard-wire D2 to ground, you can detect when the ground wire is cut. Of course that's a connection to the Arduino's ground so you'll have to figure out the wiring and maybe make a "wiring loop".
This is looking like a bigger challenge than i thought - i have posted the below photos.
In 'home GND and Board GND connected together' - i have home GND and Board GND connected via PIN 8 and PIN 8 doesn't change when i disconnect home GND. I am assuming PIN 8 doesn't change as in this case all GND are 'common' when connected like this.
In second photo I just have home GND to pin 8 and the sketch continuously triggers until i pull it off. I was thinking i could have sketch say while 'falling' send alarm - but it still triggers alarm while home GND is connected. I think its voltage is varying enough compared to board GND which triggers alarm.
My thoughts - can i make PIN 8 with home GND only connected, always high? then when cut - it falls to zero
Or is there a way to calibrate home GND on PIN 8 to only alarm when voltage is zero...therefore, home GND cut = zero voltage/current.
I guess i am trying to have the sketch look for voltage, voltage present = no alarm, if zero volts on pin 8 = send alarm.
If that seems feasible - can it be done while in deep sleep?
#include <ArduinoLowPower.h>
// Blink sequence number
// Declare it volatile since it's incremented inside an interrupt
volatile int repetitions = 1;
// Pin used to trigger a wakeup
const int pin = 8;
void setup() {
Serial.begin(9600); // Start the serial terminal
pinMode(LED_BUILTIN, OUTPUT);
// Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up
LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE);
}
void loop() {
for (int i = 0; i < repetitions; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
Serial.println("+++++sending 10 Alarms++++++");
}
// Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources)
// The power consumption of the chip will drop consistently
LowPower.sleep();
}
void repetitionsIncrease() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
//repetitions ++;
repetitions = 10;
}
For informed help, you really need to draw a schematic of what you are trying and then display here in your thread. Just writing about what you are doing really confuses me.
Another part of your project would be to use an oscilloscope to study the voltages produced between your grounded wire and the mains ground for your house.
Unless a fault arises there should be no current in the earth conductor. And earthed equipment should be protected by a fault detector (RCCB). So potentially you could measure the resistance by passing a big DC current through the earth conductor (which should not upset the RCCD).
But as Perry says, it depends
how the cable you are monitoring is connected and how it is grounded, and how your monitoring circuit, including Arduino or other electronics is grounded.
rossdem699
Will you please read reply #1 again and follow the instructions for posting code; please edit your reply #4 to include code tags </>, and the instructions for posting images. Your photos are useless for helping do what you want, we need the schematic I mentioned.
You are more likely to get help if you provide what we ask for.
The links in the first post didn't work but i think i have now added code as per </> and added photo of basic sketch of the circuit and what i am trying to achieve. Hope that makes more sense now.
#include <ArduinoLowPower.h>
// Blink sequence number
// Declare it volatile since it's incremented inside an interrupt
volatile int repetitions = 1;
// Pin used to trigger a wakeup
const int pin = 8;
void setup() {
Serial.begin(9600); // Start the serial terminal
pinMode(LED_BUILTIN, OUTPUT);
// Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up
LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE);
}
void loop() {
for (int i = 0; i < repetitions; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
Serial.println("+++++sending 10 Alarms++++++");
}
// Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources)
// The power consumption of the chip will drop consistently
LowPower.sleep();
}
void repetitionsIncrease() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
//repetitions ++;
repetitions = 10;
}
I was hoping for something that showed the context, I imagine the wire is more than a few tens of millimetres long. How does the earth from the wire get back to the MKR1500?
TBH, the simplest, and probably most reliable way to do this would be a power supply and a relay so that the relay is operated as long as the wire is not cut. Connect the alarm to the relay contacts.