Trouble reading low voltage ona standalone UNO

Hi everyone,

I am working on a project that consists on switching and dimming some LED when someone is detected by an IR motion sensor. I also added some temperature sensor (TMP36).

I am experiencing some problem when I try to get the value from this sensor. Please find attached my schematic.

The voltage I want to read is included between 0 and 1.5 V or something, and typical value is 0.75V. When I read the voltage on my A0 pin, it always returns 0. I am also reading other sensor between 0 and 5V so I can’t change the analogREF value, and those measurements works perfectly well. I also tried to change to another analog pin but I get the same result. I also attach my code, but I doubt this could come from there, since I am running the same code for the 2 measures and one works while the other one doesn’t. I get the value from the arduino through Bluetooth device HC-06.

#include <SoftwareSerial.h>
SoftwareSerial BT(7, 8);


int sensorValue = 10 ;
float temp = 0; 
int detect = 0;
int msg_received =0;

// the setup routine runs once when you press reset:
void setup() {
  
    // set the data rate for the SoftwareSerial port
  BT.begin(9600);
  // Send test message to other device
  BT.println("Hello from Arduino");
  pinMode(5, OUTPUT);

}

// the loop routine runs over and over again forever:
void loop() {

   sensorValue = analogRead(A0);
  detect = analogRead(A1);

   if (BT.available())
    // if text arrived in from BT serial...
  {
    msg_received = (BT.parseInt());
    BT.println("Message Received."); 
  }
  
  if (msg_received == 1)
  {
    BT.println("Temperature is : "); 
    BT.println(sensorValue);
    msg_received = 0;
  }
    if (msg_received == 2)
  {
     BT.print(" detect value : ");
    BT.println(detect);
    msg_received = 0;
  }
 
}

Any help appreciated, thanks you.

The schematic shows a TMP36 with the output going to A0. Edit, this comment in response to another post since removed.

Do you have a multimeter? If so, measure the voltage on the output pin. This is to confirm the device is actually working.

Weedpharma

Hi thanks for your replies !

There is a TMP 36 with the output going to A0, yes. I do have measured the value, and the device is working well. I have around 750 mV on the physical pin of the ATMEGA328. When I remove the TMP 36 and get a floating pin, the analogRead is working and shows me random values as expected...

[EDIT] I don't get random values when the pin is floating but actually only 3 values, that come randomly : 685, 684 and 4. I didn't test engouh times before.

Have you swapped the A0 and A1 inputs?

This will show if it is code or device related.

Weedpharma

I did. I get the same problem. I still can't read the voltage from the TMP36, the other reading runs great whatever the pin is.

Did you swap the pins in the code as well? Or just the wires to the inputs?

Weedpharma

Yeah I did. I mean, whatever the pin is for tmp36, I still get 0.

I have a clue now. When seeing the output with my scope, it appears that the output from tmp36 is not stable. it stay up to 0.5V then get 0, like a square wave.

It is the same when I replace the sensor with another one..

If you look at the datasheet, you see on every diagram a 100n ceramic cap across the sensor. Supply to ground. Directly on the pins. Leo..

Thanks for your help !!

If you look at my schematic, you see I put this 100n ceramic cap.

Concerning the square wave I get, I figured this out. I use a package that include a shutdown I did not connected to Vcc. Now I did, and I have a clean signal coming from the TMP36 sensor. But I still get 0 from the analogRead.

[EDIT]

Actually I measure either 680 either 0. Most of the time it is 0 though. Which is """surprisingly""" exactly 3.3 V or 0V. 3.3V is the supply of this tmp sensor. When I check on my scope, I do have a clean signal of continuous 850mV on the analog pin though.

Sorry, just saw your schematic. And indeed, the shutdown pin has to be connected to +Vs.

I would write a short program that reads the temp sensor pin and prints it to the serial monitor. Nothing else. Leo..

Hi, If you remove the sensor signal from the analog pin, and place 2 x 10K resistors. One from analog input to Gnd and one from analog input to 3.3V. So you have 1.65V on the analog input, what does it read?

Have you tried using 5V to power the sensor instead of 3.3V

Also try reading the temp sensor input twice in a row. (humor me)

 sensorValue = analogRead(A0);
  sensorValue = analogRead(A0);
  detect = analogRead(A1);

Tom... :)

Don't connect AREF to 5V, it will not fix this problem, but it should not be connected.

Thanks you guys for your help !

I tried what you advised and it is now working.

TomGeorge: Also try reading the temp sensor input twice in a row. (humor me)

I just need to read twice the value. TomGeorge, now that this is sorted, can you please explain to me why I need to do such a thing ?

Thanks again for helping !

Hi, The reason for the double analog read is because the arduino only has one AtoD converter, it must switch between the inputs as you request them in your program. It takes time for the AtoD input level to change from the previous level to the next, sometimes, if you sample too quickly you get a value that is between the two levels. By reading the same input twice like that, you do not use the first reading, but the second reading, this will have given the AtoD input time to measure the true stable value of the new level.

Tom.... :)

Ok, always great to learn stuff like that. I will keep this in mind.

Thank you !