I have my nano programmed to read digital HIGH when the resistance is below a fixed value and digital LOW when it is below that value using a voltage divider. I am getting an output voltage of 4.02V at digital HIGH and 270 mV at digital LOW, which would be great for my next step using a timer/relay module.
However, when I hooked up the relay, the digital HIGH reading dropped to .59V, which is not enough voltage to activate the timer/relay and I tried the low and high potential inputs.
any thoughts why the potential dropped so much? I need that higher potential to activate the timer/relay. I read open circuit across the timer/relay input ports.
Yeah, it has that 'basic concepts run horribly amuck' odor. @kfccucumber you really are struggling to communicate your needs. I'm going to try to re-interpret what you've said.
I have my Nano programmed to output a digital HIGH when the voltage of a voltage divider is below a fixed value, and LOW when it is above. I wanted to apply that to the input of this module, but(insert description of voltage levels here).
Your problem is, the input of that relay module is incompatible with an Arduino output. Others can elaborate, and offer alternatives, as I'm out the door right now.
Okay. So your Arduino digital output isn't compatible with whatever the front-end of the timing module is expecting. The way the description reads, it looks like it would be compatible with a contact input(actual sketch of contact input on module). You might get away with a 5V small signal relay on the Arduino output (make sure you protect the Arduino output with a reverse biased diode, unless the relay you choose has one).
There are lots of good reasons for not driving a relay from the Arduino, but if you choose the right relay, you can do it. Just one, and nothing else, mind you. You need a relay which can be driven by 20 mA at 4-ish volts. Not readily come by, though they exist.
OR, you can buy a relay module(the Amazon market is filthy with them), and drive your timer relay with a relay driven by the Arduino.
Not, I'm sure, what you were hoping. But then again, your 'ask' is a bit unusual. Normally, we'd do the timing, adjustment, etc. in the Arduino, and just drive a relay to do whatever your timing relay is doing.
I want to follow up on this. For the sensor "on" signal, I originally used digitalWrite HIGH, but I recently tried analogWrite output 200, which worked! The system sends about 4V to the relay (when lower resistance is measured from the voltage divider) and the timer starts. The voltage now does not decrease when I hook the output to the timer/relay module and it works great. I wanted to update this in case anyone else in the future might want to do this.
In summary, this setup will detect infinite ohms (open circuit) as 0 V output and lesser resistance as 5V output. In my application, my lesser resistance is around 25K ohms.
I am very new to code writing; perhaps others can optimize this or remove unnecessary lines. But it works as is!
RE the device working, I can't tell you why it's working, nor can I tell how long your Arduino output will last before failing, but if you're convinced you've got a solution, go with it.
As for the code, won't touch it. Spend five minutes looking around the forum, you'll realize that's not how to post code if you expect others to work with it.
Have fun!
Oh, and your sensor schematic is messed up. 1 megohm between 5V and GND, and sensor from GND to A0? If that's how you wired it, throw away the resistor.
const int sensorPin = A0; // Analog input pin
int relayPin = A1; // Digital output pin that tiggers relay
int sensorValue = 0; // sensorPin default value
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 1000000; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
void setup() {
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void loop() {
sensorValue = analogRead(sensorPin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
if (sensorValue < 800)
analogWrite(relayPin, 200);
if (sensorValue > 800)
analogWrite(relayPin, 0);
}
Because we have no information about the input circuit characteristics.
Google "ternary operator in C", then consider the following as an alternative:
const int sensorPin = A0; // Analog input pin
const int relayPin = A1; // Digital output pin that triggers relay
int outputValue;
void setup() {
}
void loop() {
outputValue = analogRead(sensorPin) > 800 ? 0 : 200;
analogWrite(relayPin, outputValue);
}
Compiles, should work but I have no way of testing here right now.
Although the two lines in loop() could even be combined into a single line, eliminating the need for outputValue, I wouldn't do that, as it becomes 'dense' code, hard to read at a single glance.