What do you want to connect them to? Post a link to the device you want to connect to the Arduino (and not some useless e-bay advertisement).
If there are only 2 wires, it is likely that one is ground and the other is digital or analog (HIGH or LOW when a pulse happens, or ramping up and down quickly around the pulse).
Then you need to post a link to the device. I am not going to tell you to connect the red wire to pin 7 and the black wire to ground, and then have you complain about all the smoke and sparks, without seeing just what it is you want to connect, and what the voltage and amperage are likely to be.
That is not the sort of datasheet that we need. It does not explain the electrical characteristics of the device or whether it can be connected to any microprocessor or if it needs a specialized proprietary reading device.
xelot:
For this purpose i have purchased a WMT030C1D0 water meter with pulse-output. There are 2 wires (black and red).
Since you have purchased it, hopefully you have done so with more knowledge than is given on the datasheet you have given us. By two wires, I guess the meter has a reed switch, as I understand they are common for this. I don't suppose there is any point in asking what the hall sensor programme you are currently using does, but you may possibly find that it is adaptable with no more than changing the count factor to suit. All you need is a better understanding of it.
Nick_Pyner:
Since you have purchased it, hopefully you have done so with more knowledge than is given on the datasheet you have given us.
Not really, i figured it was a simple counter of a LOW/HIGH on a digital pin.
Nick_Pyner:
By two wires, I guess the meter has a reed switch, as I understand they are common for this. I don't suppose there is any point in asking what the hall sensor programme you are currently using does, but you may possibly find that it is adaptable with no more than changing the count factor to suit. All you need is a better understanding of it.
My meaning is to measure how many litres that have been collected for each use.
OK, so i found out that this is indeed a Reed sensor. When i blow through the meter with a multimeter on it, there is 4 pulses per litre.
So now i have written a small program:
//Detect how much water has passed the meter.
//Reed sensor water meter with red wire (+) and black (-)
//Connected to Arduino uno pin 2 and pin 6
#define give 2
#define recieve 6
int counter=0;
int val=0;
int liter=0;
void setup() {
pinMode(give, OUTPUT);
//pinMode(recieve, INPUT);
Serial.begin(9600);
digitalWrite(give, HIGH);
Serial.println("Ready for data");
}
void loop() {
val=digitalRead(recieve);
// put your main code here, to run repeatedly:
if(val==1){
counter++;
}
liter=counter/4;
if(counter %4 ==0){
Serial.print(liter);
Serial.println(" liter");
}
delay(500);
}
I need something in my program to check if the reed sensor is moving. If i start the system, and the reed sensor is side by side to the magnet, it will count on and on. Is there a "onchange" state i can use ?
xelot:
I need something in my program to check if the reed sensor is moving. If i start the system, and the reed sensor is side by side to the magnet, it will count on and on. Is there a “onchange” state i can use ?
You want to detect and track change in pin state over time rather than “always now” pin state.
I use 1 byte per pin. For the no-bounce reed switch I only need 2 bits to track current and previous states as a number I can make a switch-case statement for.
#include “Arduino.h”
const byte switchPin = 7; // these could be arrays to loop through many pins.
byte switchState = 3; // starts as current and previous states are HIGH, with pins moded INPUT_PULLUP, is no press.
…
void loop()
{
…
switchState = switchState & 1; // all the bits except bit 0, last read’s current state bit, get cleared.
switchState = switchState << 1; // shifts the bits in switchState up 1. Last current state in moved into previous state bit.
switchState += digitalRead( switchPin ); // and now bit 0 is current read and bit 1 is previous read
…
switch ( switchState )
{
case 0 : // current and previous states are LOW — no change, switch closed
// code
break;
case 1 : // current state is HIGH and previous state is LOW — change detected, switch opened
// code
break;
case 2 : // current state is LOW and previous state is HIGH — change detected, switch closed
// code
break;
case 3 : // current and previous states are HIGH — no change, switch open
// code
break;
}
…
}
I only need 1 variable for 2 states and I can compare them by the value they make.
If you get into bit logic you can work with many bits together very fast. An unsigned long will let you work 32 T/F values at once. http://playground.arduino.cc/Code/BitMath
Robin2:
Your code needs to check that there is a LOW before recognizing and counting a HIGH.
Something like this
prevVal = val;
val = digitalRead(receive);
if (val != prevVal && val == HIGH) {
counter ++;
}
...R
Works great, but when the sensor is side by side to the magnet, it just counts on and on. My first thought was to time how many millis(); the pin is HIGH, and then somehow prevent more counts until the pin has changed. But i cant seem to figure it out.
If val is zero, you will increment counter on every pass through loop. You need to increment it only when val becomes one. Look at the state change example or try: