Pages: [1] 2 3 4   Go Down
Author Topic: Help reading voltage on an analogread pin  (Read 3688 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all, i am posting this aside of the main forum post (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=69887&postdays=0&postorder=asc&start=60) that has been going on for a few months now. I recently had time to work on some of it and i am not getting the results that i need. So i am looking for help on the problem.

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:
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:
Code:
0
0
64
1023
860
1023
944
0
0
10
etc...
And when i disconnect the voltages from pin 3 it looks like this:
Code:
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.

So any help would be great! smiley

David
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

David
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
« Last Edit: January 30, 2009, 10:47:47 pm by halley » Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

David
« Last Edit: January 31, 2009, 02:23:55 pm by StealthRT » Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Grounding it with the Arduino ground fixed that problem.

Good news!  Glad to hear that it worked!

Quote
How would i get the 5v that comes out of another analog pin to 0v

But that doesn't make sense, to me.

Quote
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:

http://en.wikipedia.org/wiki/Voltage_divider

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK i see the parts for the relay stuff:

1 - 1000k resistor (1K?)
1 - 5v relay
1 - 1N4004 transistor

But how about the BC548 and the HE3321? I cant really find anything on them...

David
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
« Last Edit: January 31, 2009, 02:54:31 pm by anachrocomputer » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK Anachrocomputer, do you mind checking my parts list to make sure its what i am in need of for this?
  • 2k Ohms = (mfr. Part#: 271-2K-RC)1/4WATT Metal Film Resistors 1/4watt 2Kohms 1%
  • 1n4004 = (mfr. Part#: 1N4004RLG) Rectifiers- Standard and Fast Recovery 400V 1A Standard
  • BC548 = (mfr. Part#: BC548CTA) Small Signal Transistors NPN 30V 100mA HFE/8
  • HE3321 = (mfr. Part#: JS1A-5V) Power Relays 10A 5VDC SPST SEALED PCB
David
« Last Edit: January 31, 2009, 03:15:29 pm by StealthRT » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

David
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?



http://www.flickr.com/photos/anachrocomputer/3242387876/

Probably best to view it full size!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey thanks for taking the time to draw that up for me.

The part numbers come from http://www.mouser.com

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?
Code:
NC=======>[L SWITCH R]<=======
C<========================^
Where the NC connects to the left side of the button pin and the Common connects to the right side of the button pin.

Or is it as simple as soldering just the NC wire to both sides of the button?

David
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Take the two wires from the button, connect one to "common" on the relay, and the other to "normally open".
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

David
Logged

Pages: [1] 2 3 4   Go Up
Jump to: