Photon analogRead wrong Value

I have an analog Sensor that outputs 0V-2V when powered with 4.5V-5.5V.
On my Arduino it all works as expected and the Sensor provides ~0.6V on the Signal Line
(I used “float voltage = sensorValue*(5000/1024.0);” to convert the analog Signal to a Voltage).
I also tested the Voltage with a Multimeter.
On my Particle Photon on the other Hand, I get a Voltage of ~1.4V
(this time calculated with “float voltage = sensorValue*(3300/4096.0);”)
but when i test it with my Multimeter it also outputs ~0.6V.

The Code is:

unsigned long lastTime = 0;
#define         A_PINA                       (0) 

void setup() {


}

void loop() {
    int CO2sensorValue = analogRead(A_PINA);
    float voltage = CO2sensorValue*(3300/4096.0); 

    unsigned long now = millis();
    if ((now - lastTime) >= 60000) {
           Particle.publish("voltage", String(voltage),60,PRIVATE);
           lastTime = now;
    }
}

Could you try using the ‘proper’ name for the pin? A0-A7, rather than the ‘obscure’ Arduino variant. You might be reading a different pin and getting floating values. Not sure on this one, but best to use the proper names.

How are you powering the sensor on the Photon?

1 Like

Sorry I should have included that i power the Sensor from the VIN Pin of the Photon so it should be supplied with 4.7V right?
I just changed the name but it doesn’t make a difference.

Not sure how you get 0.6 volts out of this equation. Calculating for sensorValue, which should be a whole number, you get 0.12288! What you should be using on the photon is:

float voltage = CO2sensorValue*(3.3/4096.0);

Still not sure how you get 1.4v when using 3300.

2 Likes

The Arduino reads 139 on the analog Pin so 139 * (5000/1024) = 678mV.
Let’s say you read 1024 on the Arduino which represents 5V: 1024 * (5000/1024) = 5000mV
On the Photon 4096 represents 3.3V so 4096*(3300/4096) = 3300mV.
Am i missing something?

Edit: Your Version gives me the Voltage and not the mV so i guess you are right but since i do it like that on the Arduino and the Photon it should still give me roughly the same Value shouldn’t it?

Edit2: The Photon reads 1800 on the analog Pin 1800*(3.3/4096) = 1,45V

1 Like

Does the number change, or is it pinned to 1800? Can you hook up a potentiometer to the input and see the full range of values?

Ok i kooked up the Potentiometer and it gives me the full range then i plugged in the Sensor again and now it works like intended for some Reason.
I guess all it was was a faulty soldering joint?!
I feel a bit stupid right now.
Sorry for wasting your Time and thanks for the Help!

4 Likes

So electronics has made you feel like a fool... Welcome to the club, we have many members. :slight_smile:

5 Likes