# Photon analogRead wrong Value

**URL:** <https://community.particle.io/t/photon-analogread-wrong-value/39437>\
**Category:** Troubleshooting\
**Created:** [February 12, 2018, 7:19pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437 "2018-02-12T19:19:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hippler](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hippler](https://community.particle.io/u/Hippler)\
**Post date:** [February 12, 2018, 7:19pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/1 "2018-02-12T19:19:46Z")

</div>

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:

```auto
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;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [February 12, 2018, 7:30pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/4 "2018-02-12T19:30:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hippler](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hippler](https://community.particle.io/u/Hippler)\
**Post date:** [February 12, 2018, 7:33pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/5 "2018-02-12T19:33:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [February 12, 2018, 7:35pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/6 "2018-02-12T19:35:26Z")

</div>

> [@Hippler](#):
>
> float voltage = sensorValue\*(5000/1024.0)

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:

```auto
float voltage = CO2sensorValue*(3.3/4096.0);

```

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

---

<div class="post-metadata">

**Author:** ![Hippler](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hippler](https://community.particle.io/u/Hippler)\
**Post date:** [February 12, 2018, 7:49pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/7 "2018-02-12T19:49:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HEng](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@HEng](https://community.particle.io/u/HEng)\
**Post date:** [February 12, 2018, 8:15pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/8 "2018-02-12T20:15:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hippler](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hippler](https://community.particle.io/u/Hippler)\
**Post date:** [February 12, 2018, 8:46pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/9 "2018-02-12T20:46:36Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![HEng](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@HEng](https://community.particle.io/u/HEng)\
**Post date:** [February 12, 2018, 9:02pm UTC](https://community.particle.io/t/photon-analogread-wrong-value/39437/10 "2018-02-12T21:02:40Z")

</div>

> [@Hippler](#):
>
> I feel a bit stupid right now.

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