Community
OpenEnergyMonitor

Community

emonTH reading external analog sensor (TCRT5000), signal on unexpected pin

Tags: #<Tag:0x00007f6e138fa1a0> #<Tag:0x00007f6e138fa060>

I am working with the TCRT5000 sensor and an emonTH 1.5 to measure my gas meter (it has a small mirror on the last digit reel, so trying to detect that).

In my first attempt, I tried connecting the sensor to screw terminals 2,3 and 4 (digital input) as done with the optical pulse sensor sold in the shop. This works, but is extremely tricky to get good results as you have to find the “sweet spot” of the sensor, i.e. placing it at the right position on the meter to get get a digital positive reading when the mirror passes by, and a negative reading if the mirror is not in sight.

Therefore, I decided to try to hook the sensor to an analog input, so that I can calibrate it in software. I connected the signal wire to screw terminal 5. According to the wiki page, this should be ADC5 (dig 18), so I tried reading from A5, but got no signal.

Now my confusion starts, as I used the following sketch to see whats going on. I read all inputs:

void setup(){

  pinMode(A3, INPUT_PULLUP); //Experiment, setting it as input
  pinMode(A5, INPUT_PULLUP); 

   
  Serial.begin(9600);

}

void loop(){
  
  printPinAndAnalogRead(A1);
  printPinAndAnalogRead(A2);
  printPinAndAnalogRead(A3);
  printPinAndAnalogRead(A4);
  printPinAndAnalogRead(A5);

  Serial.println();
 
  delay(100);

  
}

void printPinAndAnalogRead(int inputPin) {
    
  int value = analogRead(inputPin);        
  Serial.print(inputPin);
  Serial.print("=");
  Serial.print(value);
  Serial.print("  ");
  
}

Using this code, I get a very clear signal on input A3, i.e. pin 17. However, this does not correspond with the documentation and schematic (which suggest ADC5 / pin 18) and sketch emonTH_DHT22_DS18B20_RFM69CW_Pulse.ino (which suggests pin 18).

Can someone explain this? Would reading from this analog input work if I modify the original sketch by removing all temperature sensor reading code?

How long have you had the emonTH?

Are you sure it’s a v1.5?

I think you have a v2!

Because the new humidity sensor is I²C and the hardware I²C is on D18(A4) and D19(A5) on an ATmega328p so the 6way connector changed from using D19(A5) to D17(A3) for 1wire on the v2.

The Sketch you mention has DHT22 in the file name so it is for a v1.5 and therefore ADC5 / D19 would be correct (your references to ADC5 / D18 are confused as ADC pin numbers are the Digital pin -14),.

You are right, I have a v2. I got it two weeks ago (20/12/2016). Knowing this, I also found the blog post containing the v2 announcement and description. Have been looking at the wiki which does not contain the v2 yet…

The schematic, pcb layout and firmware are on GitHub (via Resources, but the User Guide still points back to the emonTH V1 version because it still refers only to the DHT22).

For sake of completeness: I have the emonTH v2 running in production. It has a TCRT5000 sensor connected which connects pulses on my gas meter (mirror in the last digit reel). On every pulse of the sensor it will send its pulse count to an emonBase. In addition, included the temperature/humidity of the built-in SI7021 sensor in the datagram.

I wired the TCRT5000 sensor is wired as:
http://blog.huntgang.com/2014/06/17/arduino-tcrt5000-build-ir-sensor/

In attachment the updated
src.ino (14.2 KB). I removed all the external sensor stuff I don’t need for clarity. I am actively reading the analog sensor value every 200ms. When my central heating is running, I get a pulse every 27 seconds.

Hints to improve power efficiency are welcome :slight_smile: . Would it be possible to connect the power source to the Dig5 output and in software only enable this output when sampling the light sensor?

I have been setting up a monitor on my gas meter today, I have noticed there is a mirror spot on the “6” of the 3rd decimal (0.001) but I do not use use it, I have found there is also a magnet in the tumbler and have set up a hall sensor as mentioned in the "Hall sensor possibility for Gas Measurment?" thread. Although power consumption is not a primary concern for me as it’s not battery powered, the using an interrupt rather than constantly reading means the unit could be asleep most of the time.

Have you checked for a magnet? they are quite weak, but thier presence can be confirmed with a run of the mill old fashion magnetic orientation compass.

Only if the sensor will operate at 3.3v, a quick look at the page you linked says it is working at 5v but doesn’t seem to confirm if that has to be the case. The emonTh operates at 3.3v so it can only provide 3.3v at D2 despite there being 5v available at the terminal block.

EDIT - found a datasheet for the sensor, but I’m none the wiser :slight_smile: http://www.vishay.com/docs/83760/tcrt5000.pdf

The emonTH V2 portmap & schematic is on the emonTH V2 github page:

Sorry for the confusion, I will update the Wiki.

Update: wiki has been updated.

The sensor is currently working at 3.3v, just not sure whether the ATmega328p can handle the output current of the emitter and that the output rising would not have too much effect on the measurement.

I have tried checking for a rotating magnet with my phone compass and a hall sensor (measuring resistance with a multimeter), but discovered no signal. I have to admit that this could also be caused by the way I measured…
In addition, Google suggested that there is no magnet in my type of meter (at least I could not find a confirmation). I live in an apartment building, and one neighbor has another type of meter that has a notch in the location where the hall sensor is supposed to be installed.

I tried using my phones compass out of curiosity (to save having to carry a compass in my toolkit) and it didn’t work for me and getting the hall sensor positioned was very tricky, I think had I not confirmed the presence of the magnet with a compass beforehand I would have given up and assumed no magnet was present, it was only because I knew there was definitely a magnetic pulse to be had that I persevered with the sensor positioning.

I ordered additional emonTH’s, when they arrive, I will try with my hall effect sensor :slight_smile:. I will leave the current setup running as it was a bit tricky to set up, and I really like the data :smile:

Another good clue that the meter has a magnet is if the printing on the front shows “1 imp= 0.01m”. On my meter the magnet is accessible from under the dial face. I have a reed switch sensor. With the maximum demand of the house I see 1 impulse per 23 seconds. The pulse is a minimum of 2 seconds duration so I pole the contact using an Arduino. I now have an indoor display and a simple web page allowing me to send in meter readings to my utility supplier.
G

Although my gas meter is not branded Elster it looks suspiciously similar, even down to the labelling. I would say they are built by the same company and then branded differently.

I did wonder what that hole was on the right of the display, now I see it’s to support the official sensor. perhaps a little more precise than my blob of sticky s**t (that isn’t a brand name, I just don’t know what it’s called, I’ve had a roll for years and it’s much like the stuff car windscreens are held in with but white, not black) I was only using it to make moving it about easier, but now it is located and the surface is uneven I guess it will remain. it is located in the port I had guessed was for such a device as you have to mate to.

The sensor I used is a Hamlin hall effect sensor, a link to it and the script I tested with is on the thread I previously linked too. That sketch also prints an “on” and “off” as the magnet passes and I confirm the same that a pulse usually lasts no more than a couple of seconds, but I expect that to be much longer if the wheel stops with the magnet in line with the sensor.

I also see a pulse every 23 secs when the boiler is running so it seems we are all getting a similar pulse rate.

But no printing does not mean no magnet! My Actaris meter has nothing to indicate that it has a magnet, but there is both a magnet and a reflective spot on the fastest wheel.

There’s a reed switch (barely visible) clipped between the meter leads:

I’m curious what the above means? I giggled it and found “Imperial gallon to cubic meter” - is this correct?!?

One impulse = 0.01 cubic meters?

That’s what I thought!

Or metres.

As far as I know a metre is a measure of length, and the piece of kit that measures the gas is a meter.

Probably true for everyone outside the US. We spell 'em both meter.
But we don’t speak English. (At least not the variant you do…) :wink:

I’m glad to hear this is not the “1 imp”:

I did notice that but assumed it to be American-English like centre and center, Gallons are different that side of the pond so why not metres too? :slight_smile: