Hi, I am using an atmega328, and i'm trying to measure the resistance of a resistor. The only issue is that the circuit i'm trying to measure is 12V. My supply is a regulated 12V DC supply. I was wondering what is the best way to do this.
I've already managed to measure the resistance accurately of a 5V circuit using the atmega using this circuit. Would it be possible to make this circuit work for 12V?
Yes, it's possible. But, you need an [u]over-voltage protection circuit[/u] so you don't fry your Arduino. And of course, you have to adjust the calculations accordingly.
And if you the ADC reads 1023, you've maxed-out the ADC and you'll need to change the known-resistor value to bring the voltage down.
Now... The Arduino has a regulated 5V supply, so why use 12V? Normally when you read resistance (with a multimeter) you turn power-off in the circuit under test, so the only voltage & current is coming from the meter. Any voltage in the circuit will foul-up the resistance reading. And in a circuit, the meter reads the resistance of the resistor and any parallel resistances so you may not read the true resistance of the resistor unless you remove it from the circuit.
Here is a schematic to demonstrate how it'll work.
As you can see the NC contact of the relay just passes the current on to the next device, if there is no smoke detected, the current will go through the EOL resistor and the atmega will read that as there being no fire.
However if a smoke detector detects smoke, the relay will flick over to NO and the current will be redirected to that resistor, the atmega will read the new resistance and trip an alarm.
Your mistake is thinking you want measure resistance. You cannot do that directly with an Arduino, you can only measure voltage up 5 volts (or what's on the VREF pin). So, to measure 12 volts, you need a voltage divider. Google "voltage divider"for your solution.
Please understand that you DO NOT need to use 12 volts due to the wire length but I think being a non-English speaker is the root problem here... And if you do this incorrectly, you will destroy your Arduino with 12 volts on an input pin so you have been warned! Please test your circuit before connecting the Arduino.
The circuit is really not the correct way to detect closed relays - but you asked so here you go:
Make the the EOL resistor 20k ohm. The 4 detector resistors can be 10k ohm each.
The voltage will go up for each relay that is turned on.
Again, this is a poor design but it should work, in theory.