Pages: [1]   Go Down
Author Topic: Reading 5v analogue sensor  (Read 817 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a sensor which outputs  0-5v analogue output.
I've noticed that when the sensor has an output of 4v, and I do a analogRead(A3) it returns 1023.

I was expecting to see a figure of 800.

This is the code I used to test the sensor:
Code:
void setup() {
  Serial.begin(57600);
}
void loop() {
  Serial.println(analogRead(A3));
  delay(50);
}

Would you expect to get a value over 1000 or around 800 back?

Thanks

Jim
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27069
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is your system? Standard Uno running from 5V?
Nothing connected to Aref pin?
Do you have all grounds connected?

I would expect a reading of ~Vin/.00488.
So 4V = ~819
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm just using an atmega 328 on a breadboard, there is nothing connected to pin21 Aref, is this where I've gone wrong?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm just using an atmega 328 on a breadboard, there is nothing connected to pin21 Aref, is this where I've gone wrong?

No, nothing should wire to the pin unless you are using a analogReference(EXTERNAL) command in your sketch. Some recommend wiring a .1 ufd cap from Aref pin to ground for added noise filtering.

Check all your wiring between sensor and arduino board. A link to your sensor might be useful.
Also check your breadboard wiring and be sure you are using proper bypass capacitors on the AVR Vcc and Avcc pins.
Lefty
Logged

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sensor is a load cell, I've also replicated the problem using a diode between 5v and analogue input 3. When tested with a digital multi meter it shows around 4.2v but stil 1023 on the serial monitor. There is nothing else in my code, the complete code is above.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34128
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Some recommend wiring a .1 ufd cap from Aref pin to ground for added noise filtering.
Yes I would, even up to 1uF.
Also check the decoupling on the supply pins and also make sure you have both the analogue and digital supplies connected on the bread board.
For extra precision wire an inductor between analogue and digital power pins, with a cap to ground on both and feed the power into the digital pin.
Logged

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to be lame, but what do you mean by coupling?

Maybe I should start from the beginning, can anyone point me in the direction of a diagram of the minimum components for an arduino where I can read analogue voltages accurately?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34128
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but what do you mean by coupling?
Not coupling but decoupling, the art of isolating the power supply from the noise generated by the circuits it is driving.

Google decoupling and my foroum name, I am on an iPad so I haven't got access to my links.
As for a stand alone circuit look at my monome project.
Logged

UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Mike, I'll have a read.

For anyone else here is the link
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've also replicated the problem using a diode between 5v and analogue input 3. When tested with a digital multi meter it shows around 4.2v but stil 1023 on the serial monitor.

As well as a diode, you need a pulldown resistor connected between the pin and ground. When the DMM is connected, the DMM acts as a pulldown resistor. Disconnect it and the pin will probably float up to 5V.

Check that the Aref pin isn't shorted to anything, and that Avcc is connected to +5V.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: