Håller på med Arduino UNO och har köpt följande sensor:
https://www.turbozentrum.de/Oil-tempera ... -Zada-Tech
Det som är trevligt är att den redan är specad som ni kan se, men för att slippa visa temp i steg om 10*C så använder jag mig utav stainhart-hart ekvationen.
Dock tycker jag inte att temperaturen stämmer riktigt och undrar om det beror på "min" kod, eller om jag tänker fel på hur jag koppla det?
Infogar koden här:
Kod: Markera allt
// include the library code:
#include <LiquidCrystal.h>
#define coolantsensorDivider 1580 //defines the resistor value that is in series in the voltage divider
#define coolantsensorPin A1 //defines the analog pin of the input voltage from the voltage divider
#define NUMSAMPLES 5 //defines the number of samples to be taken for a smooth average
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxBAR = 10.34213594; //bar value of transducer being used
//const int pressuretransducermaxPSI = 150; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
float pressureValue = 0; //variable to store the value coming from the pressure transducer
const float steinconstA = 0.00145540155933184000000; //steinhart equation constant A, determined from wikipedia equations
const float steinconstB = 0.00024370391733452000000; //steinhart equation constant B, determined from wikipedia equations
const float steinconstC = 0.00000017594920712227100; //steinhart equation constant C, determined from wikipedia equations
int samples[NUMSAMPLES]; //variable to store number of samples to be taken
void setup() {
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print("Oljetryck: ");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxBAR)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
pressureValue = (pressureValue/14.503773773); //to Bar
Serial.print(pressureValue, 1); //prints value from previous line to serial
Serial.println("bar"); //prints label to serial
lcd.setCursor(0, 0); //sets cursor to column 0, row 0
lcd.print("Oljetryck: "); //prints label
lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
lcd.print(" B"); //prints label after value
lcd.print(" "); //to clear the display after large values or negatives
delay(sensorreadDelay); //delay in milliseconds between read values
uint8_t i; //integer for loop
float average; //decimal for average
for (i=0; i<NUMSAMPLES; i++) {
samples[i] = analogRead(coolantsensorPin); //takes samples at number defined with a short delay between samples
delay(10);
}
average = 0;
for (i=0; i< NUMSAMPLES; i++) {
average += samples[i]; //adds all number of samples together
}
average /= NUMSAMPLES; //divides by number of samples to output the average
Serial.print("Average Analog Coolant Reading = ");
Serial.println(average); //analog value at analog pin into arduino
average = (coolantsensorDivider*average)/(1023-average); //conversion equation to read resistance from voltage divider
Serial.print("Coolant Sensor Resistance = ");
Serial.println(average);
float steinhart; //steinhart equation to estimate temperature value at any resistance from curve of thermistor sensor
steinhart = log(average); //lnR
steinhart = pow(steinhart,3); //(lnR)^3
steinhart *= steinconstC; //C*((lnR)^3)
steinhart += (steinconstB*(log(average))); //B*(lnR) + C*((lnR)^3)
steinhart += steinconstA; //Complete equation, 1/T=A+BlnR+C(lnR)^3
steinhart = 1.0/steinhart; //Inverse to isolate for T
steinhart -= 273.15; //Conversion from kelvin to celcius
Serial.print("Temperature = ");
Serial.print(steinhart); //prints final temp in celcius
Serial.println(" *C");
lcd.setCursor(0, 1);
lcd.print("Oljetemp :");
lcd.print(steinhart, 1);
lcd.print(" C");
lcd.print(" "); //to clear the display after large values or negatives
delay(1000); //delay between readings
}
Fick tipset att mäta restistans på givaren vid rumstemperatur och fick då ut 1600ohm, och tipset jag fick är att använda samma resistans i första motståndet.
Och ja jag har även en tryckgivare inkopplad som körs mot samma Arduino UNO.
Kan det vara så att UNO inte klarar av att leverera 5V till både tryck och tempgivare + LCD display?
Vore det bättre att mata tempgivaren med 3,3V? Vad behöver jag ändra i koden isf?
Jag kan inte så mycket själv och har mest kollat på exempel online så kanske är koden jag klippt ihop helt åt pipan?
Har även testat att köra med ett 9V batteri bara för att vara säker att Arduinon får tillräckligt med in-spänning
Tacksam för hjälp, och saknas någon info tvekan inte att fråga.