Picking up invisible fence cable with Arduino

ijourneaux:
To hook the pro micro to capture the log data on the com port, I am assuming you hook it up via USB but with the battery removed?

You've got 2 choices. Connect the battery- to the pro micro gnd and **[u]DO NOT[/u]** connect the battery+ to the pro micro at all. Plug in the USB and power the pro micro off itself off the USB power. Then run the Hall and cap sensors off the battery. In effect it's like the original diagram minus 1 wire, the one connecting the battery+ to the pro micro Vcc pin/hole.

Or remove the battery and run both the Hall and cap sensors off the 3.3v regulated voltage output. That’s the pin/hole labelled “Vcc”. That wire should already be part of the testbed wiring.

Both are OK to do. The 2’nd is easier, you just remove the battery and the wiring remains the same. The offset voltage of the Hall sensor will be different (who cares) and the gain a bit lower too (it’s also “ratiometric”). At this point that doesn’t matter either. Just always remember to remove the battery when running off USB power to run the whole testbed. Having the battery connected to Vcc with USB power at the same time … a baaad thing ! (that’s why I remove the battery instead of just opening up the switch. Do both as a precaution)

I now see the logging to the com port. Unfortunately enough to know the hall sensor is not working I get a constant raw hall reading of 889-890 and a field strength of 2-3.

I assume no change w/a magnet, no matter how you orient wrt the sensor ?

Unfortunately yes. my soldering skills with a smd package that small leave a lot to be desired. I used wire wrapping wire to make the connections which should have worded but no go. I am going to make another attempt tonight.

I would check 2 things and if they don’t pan out, it’s dead Jim.

Make sure the gnd wire is good. Manually tap/hold another to the gnd pin if needed. See if the DC offset changes.

Make sure the package isn’t flipped and you’ve got pins 2 & 3 swapped.

If you want to, use one of the less sensitive sensors. IIRC the ADC of the 32U4 MCU has a pre-amp built-in. We can use it to get back some sensitivity (if needed).

Soldered up a second A1304. I had ordered 5 of them. It works.

Here is some values as a function of distance. Each value is the average of 8 measurements.

Dist(cm) Raw Hall Field Strength

0 825.56 315.56

1 587.11 77.11

2 543.78 33.78

3 526.78 16.78

4 523.00 13.00

What is the maximum raw hall sensor value? It seems like the magnetic strength is not as strong as I expected. The Hall sensor in a handle is 2-3 cm above the ice> The magnetic strip is another 2-5mm below the surface of the ice.

The std dev of the measurements

0 12.5

1 11.6

2 3.0

3 1.3

4 0.7

5 0.5

To make it a little easier to work with the log file, I would recommend adding commas so we can read the data into Excel as a CSV file

Serial.print("raw Hall reading, ");

magReading = analogRead(hallPin);

Serial.print(magReading);

Serial.print(“,”);

magReading = abs(magReading - magOffset);

Serial.print(" Field strength, ");

Serial.println(magReading);

I also ordered up a 10 pack of the SS49E.

This was not setup on a handle yet. I have to machine the stem so I can mount the hall sensor at the correct location. When the hall sensor is mounted at the correct position, it will be about 2-3cm from the ice surface. about 2/3 of that distance is a steel bolt that screws into the stem and holds the handle to the stone.

I suppose it is possible that the bolt will shape the magnetic field making it easier to detect.

Fantastic ! I would recommend some perfunctory tests to confirm what we think we know.

With no magnets around verify the calibration of the offset works by comparing the reported offset with an average taken from the readings later reported. Do a set with the sensor oriented wrt the Earth ;

  • up

  • down

  • north

  • east

  • south

  • west (to see if the local magnetic field is even measurable).

The you can check how sensitive the sensor is to “off axis” fields. I don’t know how you oriented the magnetic wrt the sensor for your tests above. Pick a distance (2-3 cm) and hold the magnet (after the offset calibration) “inline” with the sensor’s “top” face and see what you get for readings when the magnets ;

  • N pole is facing the sensor

  • S pole is facing the sensor (should get the same magnitude as N but opposite sense in raw readings)

  • N pole is facing 90 degrees from the sensor, aimed north (assumes sensor is held vertically)

  • N pole is facing 90 degrees from the sensor, aimed south

  • N pole is facing 90 degrees from the sensor, aimed east

  • N pole is facing 90 degrees from the sensor, aimed west

The N/E/S/W aimings above only need to be approximate. I’m more interested in that they be 90 deg +/- 10 deg different from each other.

I don’t know what you’re using for a magnet. It could be a lot weaker that the one(s) used in the ice. So no panic … yet. And even then it appears there’s a good S/N ratio from your data above. Good job !

ijourneaux:
To make it a little easier to work with the log file, I would recommend adding commas so we can read the data into Excel as a CSV file

Good idea. Done (and a bit more)
//very 1st cut at Curling testbed code
//put includes here

//define constants used
const int capPin = 2;      //pin for cap sensor input
const int hallPin = A0;    //pin for Hall sensor input
const int grnLEDpin = 5;   //pin for green LED output
const int redLEDpin = 6;   //pin for red LED output
const int magThrsh = 15;   //magnitude of Hall reading needed to trip red LED
const unsigned long looptime = 500;  //loop time

//define variables used
int magOffset = 0;          //offset from Hall sensor
int magReading = 0;         //magnitude of raw Hall reading with offset removed
float magSum = 0.0;         //sum used in computing offset

void setup(){
  Serial.begin(9600);
  pinMode(capPin, INPUT_PULLUP);
  pinMode(redLEDpin, OUTPUT);
  pinMode(grnLEDpin, OUTPUT);
  digitalWrite(redLEDpin, LOW);
  digitalWrite(grnLEDpin, LOW);
  delay(6000);
  //send a message re calibration
  Serial.println("Place the sensor down flat, going to perform offset calibration");
  delay(3000);              //wait 3 secs
  Serial.println("Performing offset calibration");
  delay(3000);              //wait 3 secs
  //take 20 A/D readings spaced 1 msec apart
  for(int i = 0; i < 20; i++){
    magSum += analogRead(hallPin);
    delay(1);
  }
  //now compute average
  magOffset = int(magSum/20.0);
  Serial.println("Done");
  Serial.print("Offset is ");
  Serial.print(",");
  Serial.println(magOffset);
  Serial.println("Now place testbed near magnet to be measured");
}

void loop(){
  Serial.print("raw Hall reading is ");
  magReading = analogRead(hallPin);
  Serial.print(",");
  Serial.print(magReading);
  Serial.print(",");
  magReading = abs(magReading - magOffset);
  Serial.print(" Feild strength is ");
  Serial.print(",");
  Serial.println(magReading);
  //turn on off red LED
  if(magReading > magThrsh){
    digitalWrite(redLEDpin, HIGH);
  }
  else{
    digitalWrite(redLEDpin, LOW);
  }
  //turn on off green LED
  digitalWrite(grnLEDpin, digitalRead(capPin));
  delay(looptime);
}

With no magnet in the vicinity, the reading vary in the 509-512 in all 6 directions. The values facing up and facing west may be 1-2 points higher than facing down and east. I am not sure it is significant.

I am not sure which pole is North but If “This Side Up” is North then North it is.

All measurements with the magnet surface 1 cm away for sensor. A1304 sensor face facing south

North side facing sensor: 633

South side facing sensor: 388

North side along sensor E side: 545

North side along sensor W side: 515

This magentic strip is nowhere near as strong as I thought. I tried one of the stronger fridge magnets and it read 315 1cm away from the sensor. This compares to 388 with the magnetic strip.

Touching the sensor, magnetic strip 172, fridge magnet 15

So I take away the following from your data;

  • as expected the Earth’s magnetic field is weak enough (~1 count) to not matter

  • the sensor works N/S as expected, getting the same magnitude (122) just opposite sign

  • the sensor is relatively insensitive to off-axis fields though the magnitude of 35 is a bit more than I would expect

  • the embedded magnet is much weaker than I had hoped for.

RE: the last point … I was hoping for 100 counts at the expected distance. We might see 10 ?? Any chance that the magnet you have has been beat up enough that it’s lost it’s magnetism vs one’s buried in the ice ? In any case a pulse of 10 counts is detectable above noise. Perhaps this hints at the false alarm problem … that the sensor presently used has to be uber sensitive and so is also prone to picking up stray weak fields. But it’s also discouraging me when I think about finding a “signature” signal when crossing the hogline. I had hoped to sense the weaker reverse field as the sensor approached the hogline. Then see the sense change and see a big field as the sensor was above the hogline. To be followed by the weaker reverse field as the sensor departed from the hogline. That seems too much to hope for now. I’ll also look more into using the 32U4’s built-in amp. IIRC it’s a differential amp so one input could be Vcc/2 (attained by two 10k resistors in a voltage divider) and one input could be the sensor output. The gain could be either 10x or 40x but we only get 8 bits (not 10) this way so the effective gain (volts to ADC counts) is really only 10/4 = 2.5x and 10x and probably some increase in noise too. Still it may be worth a try.

Meanwhile I will use the data above and retweak the next data collect code, the code intended to collected “on ice” data from a toss past a hogline and store it in EEPROM.

If you’re curious you might be able to simulate such a toss (throw, ??? what’s the correct curling term ?) by clamping what you have for the sensor below a non-metallic surface that you can slide the magnet on. Try a spacing of 1 cm below the surface to see the data and then try the 6 cm that’s more representative of the real life condition. Set the loopdelay to 0 and recompile the code. Start up the serial monitor and slide the magnet across the the sensor, starting perhaps a foot or so away and ending up the same amount past the sensor. Put the good parts of the data in a text file and post it (them). Use the fridge magnet too if you want.

From the MCU (32U4) datasheet …

The device also supports 32 differential voltage input combinations, thanks to a differential
amplifier equipped with a programmable gain stage, providing amplification steps of 0 dB (1x),
10 dB (10x), 16dB (40x) or 23dB (200x) on the differential input voltage before the A/D conversion.
Two differential analog input channels share a common negative terminal (ADC0/ADC1),
while any other ADC input can be selected as the positive input terminal. If 1x, 10x or 40x gain is
used, 8-bit resolution can be expected. If 200x gain is used, 7-bit resolution can be expected.

Mee_n_Mac:
But it’s also discouraging me when I think about finding a “signature” signal when crossing the hogline. I had hoped to sense the weaker reverse field as the sensor approached the hogline. Then see the sense change and see a big field as the sensor was above the hogline. To be followed by the weaker reverse field as the sensor departed from the hogline. That seems too much to hope for now.

Here’s an animated GIF to better explain the above. It depicts a bar magnet’s field in green, permeating the ice (gray) and space around it. A sensor (red) moves through the field, which at first crosses through the sensor from it’s top to bottom, then crosses bottom to top and yet later top to bottom again. The resulting field strength and polarity is plotted vs the sensor position.

(click on to open and animate)

Guys

Sorry to but into your conversation, but two things struck me.

Firstly Mee_n_Mac mentioned Kontiki which I thought was a NZ term describing a device to tow fishing lines out to sea.

Being from NZ and being involved in The Shed magazine it struck me …

second was reading this, I was wondering if the bolt and screw are steel (or non ferous)?

If so is there a magnetism effect from the magnetic hogline on the screw and/or metal bolt?

It tends to always pass over the line the same way, which is a method used to magnetise bar steel.

There are a range of magnetometers (and accelerometers) available that may be more sensitive and suit your hog line detector.

This is one that is used in the Freescale Mems Sensor ( http://www.element14.com/community/docs … m-platform ) and appears to be much more sensitive.

( http://www.farnell.com/datasheets/1684415.pdf )

The I2C communication may also be more useful.

so again apologies for butting in, but good luck.

mark

The correct term is “delivery”. Each stone is delivered.

I am leaving on a weeks vacation so would get to this until I get back. I will come up with some way to simulate a stone sliding past the magnet.

The magnetic strip is made of flexible material about 1in wide by .25in thick. I had assumed they would last a long time but they are re used year after year and do take quite a beating.

Ian

Mark

No problem butting in and appreciate the comments,

The stem and bolt are both steel. I don’t have one in hand but given the strength of the magnetic strip, I am not sure it would magnetize the bolt. I can certainly make some measurements to confirm.

ijourneaux

While I appreciate that it may not fully magnetise the parts it may be enough to reduce the reading the sensor can detect.

The Freescale board I linked to is very cheap (even in NZ), low power and might make an ideal test platform, since it includes examples.

If you experience issues with programming it, I can put you in touch with a couple of people that should be able to help.

Cheers

Mark

The bolt and stem don’t need to be out of steel. just need to be out of a material that will allow the handle to be tightened and won’t have a tendency to come lose.

Ian

I’m not sure what effect a stem made of steel, or even iron, would have. An end bolt made of some permeable metal would no doubt help by concentrating the field from a wider area into the smaller area of the sensor.

When you get back from vaca we can worry about whether this sensor (or some other Hall type) is proper or whether a more sensitive compass magnetometer (good idea) is needed. I’d sure like to survey some sheets first and see what we see. While you’re sipping MaiTais by the beach, I will slave away learning assembly for the 32U4 and get the programmable gain amp and differential mode working … in case we want them. :mrgreen:

I could 't resist working on this a bit while on vacation. With the wife out shopping, thank god for WiFi.

Since I am proficient in C programming, I think I got a hold of the basics of programming the arduino. I think I have everything set up (wishful thinking) except for the different blink rate that start after a period of time (5-10) with no hand and no magnetic strip.

I am now exploring the different arduino sleep modes. I realize w may end up with a different controller but it is good practice.

Ok. I am finally getting back to this. It has been more difficult than I thought to get the hall sensor into a position (in the stem) where I could actually make some measurements in the field. You had mentioned logging data when not hooked up to the PC. How would that be accomplished?

Thinking a head alittle, The Allegro SOT hall sensor you proposed is probably the correct foot print for my application but I am going to need to be able to reliably connect up the three wires. For the USCA, I am proposing to create a retrofit kit that would reuse the existing handle and replace the post with the hall sensor and the ciruit board. I would need to design a new board that would fit in the space that would support the LEDs going through the handle and the micro processor (choice tbd). I am struggling to figure out a reliable way to get the hall sensor wired up and installed in the stem so that it is reliable.