The input circuitry still won't work. First, we don't know his sensor characteristics, and second, the input voltage range of the LMV331 does not extend to the positive supply voltage. Even if it did, a comparator output is indeterminate when the inputs are equal.See attached:
Close to GND isn't the problem. LMV331 inputs can go 0.1V below GND, but it will only work when the inputs are more than 0.8V below the positive rail.I didn't look up the part, I thought he was literally using a switch with a low-power opamp that could go close to GND.
For a comparator, check the datasheet (or other) application circuits and use hysteresis.
Look at the datasheet of the comparator. It has an open collector output. You need a pullup resistor.the sensor i'm going to use is for soil moisture, when the voltage comes from the sensor less than the v+ which i don't know what is the right moisture in other word the right voltage range to set for the circuit to send High signal.
ok, here what i have done so far!
i did a voltage divider, and connected the power supply to 5v instead of 12v.
and it still doesn't work!! am i using the right relay!!
This is how you do it if you don't need any hysteresis. I suspect you will need hysteresis if you build hardware, which means you will need some changes.How to construct the pull-up resistor!