Trouble sensing current flow using Arduino Duemila

Hello, I am trying to sense current flow using a CR 9321-NPN that I bought from Digikey.
Wired direct to 5V and D2 pins without anything else (no resistors, etc.).
Using project board to sense VDC flowing and confirmed ranges of 0.078VDC when powered off, and 0.489VDC to 0.496VDC when powered on.

Just monitoring a table lamp right now but will eventually plug my sump pump into this!

I am trying to sense when the lamp turns on and when it turns off using this code. It is not sensing any change to the state of the lamp.

BTW, I tried sensing this on the A0 analog pin, but the numbers were so random i was not able to accurately sense when the current was flowing and when it was not.

My ultimate goal is simply to track when the current starts (appliance turned on), when the current stops (appliance turned off) and elapsed duration. This will then feed a monitoring program to track date, time, and appliance lifetime run duration.

You can probably tell that I started with the digitalStateChange example.

Thanks in advance for any help.

//CODE BELOW

// this constant won't change:
const int buttonPin = 2;
const int ledPin = 13;

// Variables will change:

int buttonState = 0;
int lastButtonState = 0;

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}

void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

if (buttonState != lastButtonState)
{
Serial.print ("button state changed. ");
Serial.print ("Current state is " );
if ( buttonState == HIGH ) {
Serial.println ( "HIGH" ); }
else {
Serial.println ( "LOW" ); }
lastButtonState = buttonState;
}
}

Wired direct to 5V and D2 pins without anything else (no resistors, etc.).
Using project board to sense VDC flowing and confirmed ranges of 0.078VDC when powered off, and 0.489VDC to 0.496VDC when powered on.

This doesn't sound like the right wiring. Try this:

  • Enable pullup resistor on D2 (digitalWrite(2, HIGH))
  • Connect D2 to RED terminal of current sensor
  • Connect BLACK terminal of current sensor to GND
  • call the digitalRead() function on D2 to sense current state

--
Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Do you have the complete cable flex of the lamp running through the sensor device. If so then the current flowing to the lamp is equal to the current flowing from it so the nett current being sensed is zero.

You need to have only the live or the neutral core running through the sensor so's it measures the single line current.

jack

It should work when you connect:

  • to 5V
  • (black) to ground
    (red) to digital input

The input should be HIGH if current < 300mA an LOW if current > 350 mA
http://www.jimdgrayassoc.com/CR9321.pdf

Thank you for such quick response!

@jackrae - yes, I am only running the live wire through the CR9321 sensor. I made my own pigtail extension cord with the CR9321 taped over the black cable. This way I can plug in any appliance to determine how often it runs. It is designed for my sump pump however.

@deSilva - the CR9321 has only two leads - red and black. I don't understand how to connect to 5V?

@RuggedCircuits - this worked! Thank you for helping and I am now onto the next phase in this project.