I'm using an Arduino Mega, an LM35 sensor, and a 16x2 LCD to display information. The LCD requires 5V through a couple of the analog pins in order to work (along with its buttons.) The LM35 works best when using a 10-bit adc for 1.0 V. I'm using analog pin 2 on the Arduino to read in the sensor values.
However, if I use the INTERNAL1V1 analog ref voltage on the board, all the analog pins get affected (I should have seen that coming :o ). The sensor reads great, but the LCD won't work as expected.
I also have a low pass filter from the output of the sensor to analog pin 2. 24.7kOhm and 0.1uF cap.
So the question is, how can I reference 1.1 (or 1.0V) for analog pin 2 and keep the 5V for the other analog pins? Is it as simple as creating a voltage divider from the board voltage to the pin or by some other way? I'm sort of new to nifty electronics and component solutions, but don't hold back to going into detail if need be. Grazie.
I assume you mean an LCD shield, since you have mentioned buttons.
AFAIK only the button ladder uses one of the analogue pins (A0).
The LCD itself is not using any of the analogue pins, and is therefore not affected by Aref.
What do you mean with "the LCD won't work as expected".
If you mean "the buttons won't work with 1.1volt Aref", then you're right.
Leo..
Edit
You could try switching to 1.1 just before reading the LM35, and change back to default Aref after that.
But switch-overs don't seem to be smooth (need a few dummy reads to stabilise).
Tried that once, and abandoned it.
Maybe best to dump the LM35, and use a digital DS18B20.
Yea, sorry, should've been more specific. The buttons will not work...the LCD shield works fine in terms of display.
Would the low pass filter, then the voltage divider (128kOhm - R1, 32kOhm - R2) on analog pin 2 work?
Or would the analog pin still have the board voltage 5V?
Anthony
Edit.
I'm going to stick with the LM35 because it currently works well and has worked on a previous version of the current project. But does the voltage divider to the analog pin work? I'm going to try it now anyway, but I only have 2 demo boards made so I figured I'd ask here first.
float readTemperatureK( int adcPin )
{
analogReference( INTERNAL );
// Dummy read to set the new reference.
analogRead( adcPin );
// may not be necessary to stabalize the new ADC reference,
// but this delay is a "just in case" sort of thing"
delay( 10 );
int tempSense = analogRead( adcPin );
// Temperature sensor is calibrated to read Celsius.
float celsiusTemp = tempSensorToCelsius( tempSense, vRefTemp );
// Covert to Kelvins.
return temperatureCtoK( celsiusTemp );
}
float readPressureKPa( int adcPin )
{
analogReference( DEFAULT );
analogRead( adcPin );
delay( 10 );
int pressSense = analogRead( adcPin );
return baroSensorToKPa( pressSense, vRefPress );
}
This is from a project I did years ago and never revisited. The delay( 10 ); may not be necessary, test that out for yourself. However, the analogRead immediately after the reference change is. Without it, there was no way I could get sensible values from the temperature and pressure sensors.
The temp sensor in the project was an LM35, just like you are trying to use.
The function looks good, but I feel like the commands will run so quickly in the loop() that using the LCD buttons would be somewhat hard.....pressing a button and trying to "catch" the button command in between the analogReference(INTERNAL) on/off situation. I'm assuming that's what you're talking about, right? Turning on and off the analogReference so that, when I need it, the 1.1V will be there for the LM35?
Now imagine 1.0V into analog pin 2 only, and the rest get 5V (for the LCD and whatever else I can use them for.) Any thoughts on that scenario?
I'm not sure what you think the trouble is. Quick is good.
I have an extremely strong suspicion that you are misdiagnosing whatever problems you are encountering. Changing the analog reference does not change any of the output values of the Arduino, so I am confused when you talk about the "LCD requires 5V through a couple of the analog pins".
The function looks good, but I feel like the commands will run so quickly in the loop() that using the LCD buttons would be somewhat hard.....pressing a button and trying to "catch" the button command in between the analogReference(INTERNAL) on/off situation.
Running "too fast" isn't a problem, except you may need some delay to allow the analog inputs and the analog reference to stabilize.
So you may need a few milliseconds delay. You don't need to read the temperature or update the display every time through the loop, but you do want to read the buttons as fast as you can get-away with. You can make timers without delay(). Look at the blink Without Delay Example, and "Doing several things at once" at the top of the forum.
You might need a short delay between button-reads and another short delay or two when you "occasionally" change the reference to read the temperature.
To extend the scenario a little more, I constantly read the temperature in order to keep a control loop going (using PID theory.) In terms of display, no, I agree that updating it constantly in the loop() is not fruitful.
So rapidly changing references isn't a problem in terms of operability? So long as no analog signal is read before reference is defined?
You are required to do an analog read after changing the reference every time, and discarding the result, if
I remember the data sheet right you should throw away the first analog read after reset as well, but no-one
ever does!
Thanks for the info. Can I use 1.1V internal reference at will? Can I use analogReference(INTERNAL1V1) for LM35, then switch to 5V for LCD using analogReference(DEFAULT)`?
Thanks for the info. Can I use 1.1V internal reference at will? Can I use analogReference(INTERNAL1V1) for LM35, then switch to 5V for LCD using analogReference(DEFAULT)`?
Yes. I already showed you code that did exactly that in my last post.
Jiggy-Ninja:
I have an extremely strong suspicion that you are misdiagnosing whatever problems you are encountering. Changing the analog reference does not change any of the output values of the Arduino, so I am confused when you talk about the "LCD requires 5V through a couple of the analog pins".
The switches of an LCD shield are connected to a resistor 'ladder' circuit, so all switches only use one pin (A0).
The ladder is hard-wired on to the 5volt rail.
To read the switches, Aref must be 5volt (default).
OP wants to use 1.1volt Aref for the LM35 for a more stable readout and higher resolution.
Leo..
Thanks for the confirmation...didn't actually think that the on/off process would work..'til I realized that you could hold any LCD button down and get a response without having to "catch" the 5V reference when it's not referencing 1.1V.
i don't know why you think you'd have to "catch" it. The choice of reference is completely under your control at all times, and the transition takes microseconds.
Maybe easier way would be to use voltage divider: divide voltage from the buttons to 1/5 and it will work with 1.1V reference.
The resistors in your voltage divider should be large enough not to interfere with result but it should be easy to try.
Smajdalf:
Maybe easier way would be to use voltage divider: divide voltage from the buttons to 1/5 and it will work with 1.1V reference.
The resistors in your voltage divider should be large enough not to interfere with result but it should be easy to try.
It's a premade shield. Doing that would require modification.