Here is part of the post from my main forum post:
Here a start how you can detect 12V wit a pin of the AVR.
Fuse 10 (Accessory Socket) looks to me like a good 'victim' to get 12V when the switch in in 'Acc' position. NOTE THAT THE PIN IN THIS PICTURE IS NOT CONNECTED TO A ANALOG PIN.. THAT HAS BEEN CORRECTED.
Ok, going back to this.. i got the resistors today to do this and its all hooked up... but i am unable to get the values i was expecting using this code:
int analogPin = 3;
int val = 0;
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
}
void loop()
{
val = analogRead(analogPin);
Serial.println(val);
}
When connected to the volts from pin 3 I get values of:
0
0
64
1023
860
1023
944
0
0
10
etc...
And when i disconnect the voltages from pin 3 it looks like this:
500
3
360
361
358
354
317
My voltmeter reads the volts going into the Arduino as 4.12 volts dc.
So why am i getting those other off the wall values when i am looking for a number from 1 to 4? And if there is nothing connected to it then the number should be 0?
I have been looking at this design here by member Shadowcat
Now some background: I am attempting to make my own Start up/Shutdown controller for my laptop for the car. Once it detects current on a 12v line then i want it to wait 5 seconds until it sends to start the pc (push the button) and if it detects no volts on the 12v line then wait 5 seconds and send the push again to turn off the pc.
And if there is nothing connected to it then the number should be 0?
No, not necessarily. The Arduino pins are hight impedance inputs, and cat 'float' if left unconnected. That is, they can take on virtually any voltage value between 0 and 5V. Unless, that is, you have a resistor connected that will 'pull' the pin down to ground. The 65k resistor should do this in your system.
When you disconnect from pin 3, do you leave the 56k resistor connected, or do you leave the pin completely open-circuit?
And, are the grounds connected together, from the 12V supply's ground to the Arduino's ground?
Anachrocomputer: Where would i connect the 65k resister to pull 0v when there is no 12v current coming through?
The 56k and 100k are connected still when power is cut off to the 12v.
No, the ground is not connected together. They are both separate. I'm just using a 12v brick for testing right now. The Arduino is powered off of the USB cable.
So how can i read the volts as my multimeter does? I need to know when its 1v or less so i know when the 12v has been cut off and i also need to know when its 2v or higher so i know that the 12v is turned on...
You need to connect the grounds between two power systems. Otherwise, the analog pin has no idea how to relate its own ground (USB ground) to the ground nor 12v supply. Just run a black wire between your 12V brick's negative pole and the GND pin of the Arduino.
The "65k resistor" was a typo, he was just referring to your first drawing, the 56k resistor. The 56k and the 100k form a voltage divider to ensure you are not exceeding 5V on the input. (But only if the Ground below the 56k resistor is the same as the Arduino's GND.)
No, the ground is not connected together. They are both separate.
There's the problem! Connect those grounds together!
And yes, 65k was a typo; sorry for not spotting it and causing confusion. The 56k should remain connected from Arduino pin to (common) ground at all times, to ensure that the analog input pin does not float.
YAY!! Grounding it with the Arduino ground fixed that problem. Now i am getting 0 when disconnected form the 12v supply and 4 when connected!
Now i have another question... How would i get the 5v that comes out of digital pin to 0v so that i can use that as the "switch" to turn on the laptop? Would i just use a 56k resistor?
Grounding it with the Arduino ground fixed that problem.
Good news! Glad to hear that it worked!
How would i get the 5v that comes out of another analog pin to 0v
But that doesn't make sense, to me.
Would i just use a 56k resistor?
There's nothing magic about 56k resistors. It's the ratio of 56k to100k that makes the voltage divider work:
Now, to drive a relay that can switch on the power, use the circuit in the lower right-hand corner of the diagram that you posted earlier. That is, a resistor, transistor, diode and relay.
Hmm.. the base resistors are labelled as 2000, which is of course 2k Ohms. Not a value that you'll usually find! 1k should be OK there.
The 1N4004 is a diode, not a transistor. It's rated 1A and a few hundred volts. Similar diodes are 1N4001, 1N4002 up to 1N4007, differing only in voltage rating.
The BC548 is the transistor, and any general purpose NPN transistor should do. BC-numbers are common in Europe, but 2N-numbers are (I think) more common in the USA. A 2N2222 transistor, or 2N3704 would be a good substitute.
Looking at it again, the diagram is not well laid out to show clearly which part number relates to which device.
The HE3321 is the part number of the relay. As it says, "5V mini relay".
My only worry is that the 5v relay's output needs to be a ground since its just acting as a momentary switch for powering up the laptop... In the drawing, it looks as though its sending some volts to the laptop? Or is the 1N4004 taking it down to 0v once it exits the relay?
You can wire up the contacts of the relay any way you like, they don't have to connect to the 12V supply. That's one of the benefits of a relay, the contacts are completely isolated from the rest of the circuit. The 1N4004 diode isn't even connected to the contacts.
You didn't say which supplier those part numbers refer to! But all the descriptions sound OK. You can make the resistor 1k if you like. Also, if you're just operating the laptop's power switch, you won't need a relay rated at 10Amps, a 1Amp one will be plenty.
Since the diagram(s) are causing some confusion, I've drawn another (yet another), which I think is clearer. Could you take a look and see if it makes things clear to you?
So i take it that the NC is what is connected to the laptop button? But i know that there is another wire that is needed in order to make the contact across the laptop switch.. So the other side has to be a ground as well? So hook that up to the "common" part?
Alright, ill connected one side to Common and the other to NO. Was that parts list OK? I'm looking to order it today if so.
Also, The power brick that comes with the Asus EEE PC is rated at 12v output so i fiugred i would just hook up the 12v from the battery to the laptop. What kind of resistors or caps would i need in order to protect the 12v from not going over it when going into the laptop say, when the car is starting or something?
It's very risky to connect a 12V laptop to a car's electrical system. The "12V" supply will vary from 10.5V to 14.8V according to whether the battery is fully discharged, charged up and floating, or on charge from the engine/alternator. The voltage will drop when starting, possibly as low as 9V.
You will need to find a specially-designed power regulator for automotive use, to avoid frying the laptop.
That regulator looks like a good 'un. It has various protection circuits, and noise suppression. The regulator chip is rated at 5Amps, so if that's enough for your laptop, go for it!
I don't understand what you mean here. The regulator part in the diagram is rated at 5Amps, and according to your info, the EEE PC takes 3Amps, so we're OK.
You may, however, be better off buying a ready-made car charger, as you suggest.