Arduino - analog to digital converter & thermistors
By DarthVader
Date: 2022-06-13
Topic: 126 see comments
Post views: 988
analogRead() - Analog to digital converter - (thermistor)
Here is how a microcontroller converts electric signals from various hardware components into useable digital values i.e numbers:
analogRead() - Description
Reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit.
Note:
This means that you multiply the integer value returned in the serial or LCD display by 0.0049 in order to get the voltage across the component connected to the analog pin.
As the ADC (analog to digital converter has a range from 0 - 1024), 1024 × 0.0049 = 5 V, the max voltage output of the board.
analogRead(pin) = voltage / 0.0049
voltage = analogRead(pin) × 0.0049
Thermistor
Thermistors are a special type of resistor than changes its resistance based on its temperature in order of ohm's per degree. This can be a substancial change in ohm's per degree.
To get a usable temperature value from the thermistor, the voltage across it is converted to a temperature value.
This is done on the microcontroller via an analog to digital converter, and then a short calculation using a natural log and polynomial.
To set up the hardware you need a liquid crystal LCD display, a microcontroller and a thermistor:
#include <LiquidCrystal.h>
int tempPin = 0;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
int tempReading = analogRead(tempPin);
// This is OK
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
// Display thermistor reading
lcd.setCursor(0, 0);
lcd.print(tempReading);
delay(500);
}
[log] = natural log, not log base 10
[int tempReading = analogRead(tempPin)] = gets voltage reading from analog pin (thermistor)
Comments | Creator | Date | ID |
---|