Voltage Sensor.

Hello I am doing a very simple project and need some help reading voltage since "float" returns random numbers.

Here is my Setup

Arduino Mega 2650
Seeed Studio Relay Shield v1.3

For my example I am taking the Relay Shield off just to simplify this
My board is being powered by a 9V battery so I will be using the 5V pin to power my sensor

I am using A15 to read voltage input

5V goes to power sensor
Ground goes to ground sensor

my problem is A15 is always reading random ghost voltage. My sensor is returning voltage from .02V to 3.8V so these ghosts numbers are throwing it all off. is there a way to fix this?

Untitled.jpg

Hi dycero,

Two quick questions:

  1. what sensor are you using, and can we see the code you're using to read it?
  2. are you sure that the shield isn't interfering, or using, the pin?

Pat.

This sensor is a pressure sensor from a Ford 7.3 Engine

I currently have removed the shield for this project. But yes the shield only uses A0 - A7

basically using the read analog voltage example code just added a delay and changed pin

/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A15);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
  delay(1000);
}

I'm not familiar with that sensor. You can try a quick experiment to make sure the code and Arduino are reading voltages correctly by connecting a 1.5v battery: negative to Gnd and positive A15 instead of the sensor. You should get a solid reading. Maybe try connecting the Arduino +5v to A15 also, to be complete.

What readings do you get?

Pat.

If i connect 5V to A15 it does read 5V but if nothing is in A15 it returns random voltages

The fact that you can reliably read the 5V indicates that the code and Arduino are ok.

The random readings are expected when the pin is not connected to anything - this is called floating, and is caused by electrical noise, which can be fixed by a pull-up or pull-down resistor (10k resistor connected to +5v or Gnd).

That all said, it sounds like your sensor isn't doing what you expect it to do. Do you have a spec for it? How do you know it takes 5v and not 12?

dycero:
If i connect 5V to A15 it does read 5V but if nothing is in A15 it returns random voltages

I believe you have a floating input: adc - Arduino has an input value in disconnected pin - Electrical Engineering Stack Exchange

Are you sure you have the pins wired correctly (ground, power, data)? Note, potentiometers tend to have the data pin as the middle pin, while your fritzing diagram has the data pin on the left. Have you checked the sensor with a multimeter to make sure it is producing the voltage?

Finally since it is a car sensor, maybe you need to power it with 12 volts (which is what the car's electrical delivers), and then you would need to reduce the output voltage from 12 volts to 5 volts to be able read it on the Arduino. If you are using a separate power supply for the sensor compared to the Arduino, you need to make sure you have the grounds of the two power systems connected.

This sensor is usually powered by a 5V supply from the truck. my sensor wiring is as followed

5v --- . . ----- ground
.
------signal

i have a 10k resistor i could use but what do i do? do i put that from ground on my sensor to ground on my board?