sci-oly-detector-building

[RADIOACTIVE] arduino thermometer for science olympiad
git clone git://git.figbert.com/sci-oly-detector-building.git
Log | Files | Refs | LICENSE

commit 7d65af20196c0dfa63d933262ee47a4618ac9f40
parent deeb2b7abdf970b836b1fc1315046fc6b7c638e4
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Wed, 19 Feb 2020 23:14:10 -0800

:sparkles: Add functional temperature sensor script

Diffstat:
AOperational/Operational.ino | 47+++++++++++++++++++++++++++++++++++++++++++++++
DRoughDraft/RoughDraft.ino | 24------------------------
2 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/Operational/Operational.ino b/Operational/Operational.ino @@ -0,0 +1,47 @@ +#include <hd44780.h> +#include <Wire.h> +#include <hd44780ioClass/hd44780_I2Cexp.h> +hd44780_I2Cexp lcd; +#define THERMISTORPIN A0 +#define THERMISTORNOMINAL 100000 +#define TEMPERATURENOMINAL 25 +#define NUMSAMPLES 10 +#define BCOEFFICIENT 4000 +#define SERIESRESISTOR 220 + +int samples[NUMSAMPLES]; + +void setup() { + lcd.begin(16, 2); + lcd.backlight(); + Serial.begin(9600); + analogReference(EXTERNAL); +} + +void loop() { + uint8_t i; + float average; + for (i=0; i< NUMSAMPLES; i++) { + samples[i] = analogRead(THERMISTORPIN); + delay(10); + } + average = 0; + for (i=0; i< NUMSAMPLES; i++) { + average += samples[i]; + } + average /= NUMSAMPLES; + average = 1023 / average - 1; + average = SERIESRESISTOR / average; + float celsius = average / THERMISTORNOMINAL; + celsius = log(celsius); + celsius /= BCOEFFICIENT; + celsius += 1.0 / (TEMPERATURENOMINAL + 273.15); + celsius = 1.0 / celsius; + celsius -= 273.15; + lcd.setCursor(5, 0); + lcd.print(celsius); + float fahrenheit = (celsius * 1.8) + 32; + lcd.setCursor(5, 1); + lcd.print(fahrenheit); + delay(1000); +} diff --git a/RoughDraft/RoughDraft.ino b/RoughDraft/RoughDraft.ino @@ -1,24 +0,0 @@ -#include <Wire.h> -#include <LiquidCrystal_I2C.h> -LiquidCrystal_I2C lcd(0x27, 16, 2); - -void setup() { - lcd.init(); - lcd.backlight(); - Serial.begin(9600); - int thermistor = A0; - float R1 = 10000; - float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; -} - -void loop() { - int sensorValue = analogRead(thermistor) - float voltage = sensorValue * (3.3 / 1023.0); - float celsius = (voltage - 0.5) * 100; - float fahrenheit = (celsius * 9.0 / 5.0) + 32.0; - lcd.setCursor(5, 0); - lcd.print(String(celsius) + "C"); - lcd.setCursor(5, 1); - lcd.print(String(fahrenheit) + "F"); -} -