I'm trying to get some sort of signal to Arduino. For example, I'm trying to send the voltage reading across the LED to Arduino. I checked these points (clouded) directly with my multimeter. If there is no detection from the detector, I'm reading 0.5V and if there is detection I will get 2.5V (both approx.) So taking this to Arduino analog pin should be OK as it is less than 5V.
Now, by reading analogRead() reference page, and browsing the examples on the forum and elsewhere, I understand that the issue here is that my "ground" is not actually a ground and I have a second analog pin to work with. I'm struggling to understand how to use analogRead() for this purpose. analogRead() is typically used after one analog pin is set and using GND for the other wire. Should I define two analog pins in the code and then read the difference between them? Or is analogRead() the appropriate method for my case at all?
Just for reference, if I connect just one wire to A0 and try the basic code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 0
// outside leads to ground and +5V
int val = 0; // variable to store the value read
void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}
I will get the same reading as when nothing is connected, which make sense.
If I connect the "-" side of the LED to GND on Arduino and "+" side to A0, I do get the readings but they are 0.07V (no detection) and 0.49V. I'm not that much of an electronics guy so I'm confused by what this might be. Is my code wrong or is the connection incorrect? Or am I affecting the circuit by taking readings on Arduino instead of multimeter?
Or perhaps there is a better way to do this. Any assistance would be much appreciated.
Thank you for the reply. It makes sense after further checking. It gives me the same 0.5V between two sensor probes as for what I tried previously.
I also tried measuring current through the diode. It reduces 5 times when I connect the "+" and "-" of the diode to Arduino to read the signals. This is the same factor as for voltage drop. So I assume connecting these two to Arduino somehow alters the circuit.
I wonder if there is a way to do it passively though, but that's more of a question for an electronics forum, not Arduino.
Using a NPN like the 2N3904 as a switch like you are doing that is not a very good configuration. You may want to move a few things and make it look like this.
What is the base signal from your sensor?
In the circuit I posted measure the collector voltage. You are using the transistor as a switch placing the transistor in saturation. When the transistor is On (saturated) it makes a path to ground and the LED illuminates. Your 9V battery Ground and Arduino Ground, as mentioned should be the same ground.
Your circuit will definitely work, it is what is called an emitter follower circuit. the voltage you get on the emitter will be about 0.7 volts below the base voltage. You get the Hfe as the transistor gain. Ron_Blain's circuit will also work and it gives you a reasonable ground with about 0.7 volt offset. The best way would be to use his circuit but use a MOSFET in place of the transistor. Get something with reasonably low RDSon. The voltage drop across the MOSFET will be considerably lower then a transistor. That is one of the reasons why they are so popular in power circuits.
I'm trying to detect the water in a porous material by closing the circuit via what I labeled as "water sensing probes". So if I put these two probes together the LED will light up, if I disconnect them LED will go dark. I also tried this with both water and the porous material and placing "water sensing probes" in water is lighting up the LED (i.e. closing circuit) but doing the same with porous material is giving me no readings. So this is ideal for what I want to do. Two connections before and after the LED are additional so I can try and obtain analog signal with Arduino and monitor the changes over time. Considering what you wrote, what are the issues with my schematic? Am I at risk of damaging some components or...?
gilshultz,
I've been reading on this as I'm not an expert, and from what I understand if I get some current flowing throught B and E of a transistor I also open it for a larger current to flow through C and E (NPN type). That made sense to me and apparently works for my application. I will look into MOSFETs next. The confusing part for me are different voltage readings I'm getting across the LED if I connect the two additional lines to Arduino, vs. if they are not connected. But at least I have consistency between what I'm measuring when the lines are connected to Arduino. Measuring voltage across A0/GND connections on Arduino pins and measuring it directly on the PCB will give me approx. 0.5V in both cases. If I don't connect these probes to Arduino, I'm getting approx. 2.0V across LED (measured directly on PCB) so I'm trying to figure out where the difference is coming from.
Another interesting thing. When additional probes are connected and when voltage across LED drops to 0.5V, LED will not light up any more. I guess there is a minimum current that needs to flow through it for it to be able to light up.
dougp,
I'm trying to get analog signal so I can continuously monitor voltage increase/drop, together with timestamps.
Thank you all for taking the time to read and respond. I'm very interested to understand if there is a better way to do this with Arduino.
I'm trying to detect the water in a porous material by closing the circuit via what I labeled as "water sensing probes". So if I put these two probes together the LED will light up, if I disconnect them LED will go dark. I also tried this with both water and the porous material and placing "water sensing probes" in water is lighting up the LED (i.e. closing circuit) but doing the same with porous material is giving me no readings. So this is ideal for what I want to do. Two connections before and after the LED are additional so I can try and obtain analog signal with Arduino and monitor the changes over time. Considering what you wrote, what are the issues with my schematic? Am I at risk of damaging some components or...?
Ah, OK it's really good to know what the objective is. Tell you what I would do. I would measure the resistance between the probes since that will be a key player. If you don't have a simple DMM (Digital Multi Meter) you should really think about investing in one. They have become very inexpensive and for general purpose enthusiast projects they are indispensable. Measure the resistance across your probe with your porous material at various saturation points you anticipate in real life use.
Once you know those numbers it becomes easier to have a LED turn on or any number of things happen. With the scheme I posted the base voltage of the transistor needs to be about 0.7 volts above ground to turn on the transistor. No I doubt you will damage anything including your Arduino as long as nothing excessive gets to an input.
Something I was going to wait on mentioning but see MarkT got it below is if the sensor probe is left in place, especially using DC on it electrolysis starts to happen which is a nice way of saying crud forms on the sensor or corrosion making constant cleaning to maintain accuracy necessary. There are probes which use AC as a work around and that helps. All depends on the probe and if it is left in place.
IoT_hobbyist:
If you connect GND of 9V power source to Arduino 's GND, your "ground" is actually a ground. You do not need to use the second analog pin
That only works if the Arduino ground is completely floating w.r.t. the moisture probes - if the Arduino
ground is mains earth, then its likely the water leak will also be at earth potential and you'll be creating
an electrolysis cell using the 9V source...
Well, to answer both regarding the concern on corrosion and electrolysis, as I was thinking about it I have had these probes made as removable wire extensions. So they are meant to be disposable. What I'm actually measuring is the penetration depth by inserting these deeper or shallower into the material. Duration of the experiment would be only until the detection. That would get logged and the whole thing should be over in matter of hours, if not minutes. I would then dry or completely remove the probes. So it's not a permanent setup to, say, monitor water leak in the basement or something.
Ron_Blain,
I will need to study your schematic more, as I mentioned electronics are not my forte. I understand what you noted on measuring resistance rather than current or voltage across the probes. I just need to figure out how to close the sample circuit you sketched, where to place measuring and sensing probes, etc. Another reason I'm using this schematic is because 9V DC is convenient - it's the same power supply we use for Arduino, so we have them laying around in the lab. Just soldered some DC jacks to the PCB and I'm ready.
EDIT: Apologies, I forgot to note that all the measurements I mentioned earlier were taken by a digital multimeter, so I do have one.
OK, nice to know a bunch more information. The reason I am curious as to the resistance for different moisture content is because knowing that it can be built around. Also nice to know it is just a one time lab test project.