01-31-2024 02:10 AM
Good Evening,
I am using 4 temperature sensor(NTC 10K, Picture attached). 1 humidity sensor(DHT 11, Picture attached) and Pressure sensor (BMP 180, Picture attached). I am accessing the data in Labview through Arduino nano. I have code and labview file for this. but i am not getting accurate value.
Note- for temperature sensor i have used NTC 100K also, but didnt get proper values. and arduino code in in text file.
Thank you in advance
01-31-2024 02:12 AM
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
// NTC sensor pins
const int ntcPin1 = A0;
const int ntcPin2 = A1;
const int ntcPin3 = A2;
const int ntcPin4 = A3;
// BMP180 sensor
Adafruit_BMP085 bmp;
// DHT11 sensor
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP180 sensor, check wiring!");
while (1);
}
dht.begin();
}
void loop() {
// Read temperatures from NTC sensors
float temperature1 = readTemperature(ntcPin1);
float temperature2 = readTemperature(ntcPin2);
float temperature3 = readTemperature(ntcPin3);
float temperature4 = readTemperature(ntcPin4);
// Read pressure from BMP180 sensor
float pressure = bmp.readPressure() / 100.0; // Convert Pa to hPa
// Read humidity from DHT11 sensor
float humidity = dht.readHumidity();
// Print sensor values to serial monitor
Serial.print("Pressure:");
Serial.print(pressure);
Serial.println("hPa");
Serial.print("Humidity:");
Serial.print(humidity);
Serial.println("%");
Serial.print("Temperature 1:");
Serial.print(temperature1);
Serial.println("°C");
Serial.print("Temperature 2:");
Serial.print(temperature2);
Serial.println("°C");
Serial.print("Temperature 3:");
Serial.print(temperature3);
Serial.println("°C");
Serial.print("Temperature 4:");
Serial.print(temperature4);
Serial.println("°C");
//delay(1000); // Adjust delay as needed
}
float readTemperature(int ntcPin) {
// Implement the logic for reading temperature from the NTC sensor
// Replace this with your specific code or function
// You can use the same convertToTemperature function from the previous example
// For example, using the function from the previous example:
int adcValue = analogRead(ntcPin);
return convertToTemperature(adcValue);
}
float convertToTemperature(int adcValue) {
// Replace the parameters below with the characteristics of your NTC sensor
float referenceResistance = 10000.0; // Resistance of the NTC at the reference temperature (in ohms)
float referenceTemperature = 25.0; // Reference temperature (in degrees Celsius)
float betaValue = 3950.0; // Beta value of the NTC
// Calculate the resistance of the NTC based on the measured ADC value
float resistance = referenceResistance * (1023.0 / adcValue - 1.0);
// Calculate the temperature using the Steinhart-Hart equation
float temperature = 1.0 / (1.0 / (referenceTemperature + 273.15) + (1.0 / betaValue) * log(resistance / referenceResistance));
temperature -= 273.15; // Convert temperature to degrees Celsius
return temperature;
}
01-31-2024 03:02 AM
Hi Alien,
@AlienVi6789 wrote:
but i am not getting accurate value.
What do you get and what do you expect?
01-31-2024 03:06 AM
I want temperature value from 0 to 100 celcius but I am getting temperature from 21 to 100 celcius.
And one more thing, can I do everything from LabVIEW, if I don't want to code from LabVIEW for all sensors.
01-31-2024 03:32 AM
Hi Alien,
@AlienVi6789 wrote:
I want temperature value from 0 to 100 celcius but I am getting temperature from 21 to 100 celcius.
Debug your Arduino code as in there the data is measured and scaled!
@AlienVi6789 wrote:
can I do everything from LabVIEW, if I don't want to code from LabVIEW for all sensors.
As LabVIEW is a programming language you can do (almost) anything "from" LabVIEW!
What do you mean by "don't want to code from LabVIEW for all sensors"???
01-31-2024 04:34 AM
I am saying if I don't want to code from Arduino ide and do everything from LabVIEW only. Can I do that?
Please help me on that.
01-31-2024 07:15 AM
Hi Alien,
using the Arduino IDE gives you much more options than using LabVIEW+Hobbyists toolkit...
When the Hobbyist toolkit supports ALL of your requirements then you can try to use that and create your program only with LabVIEW.
01-31-2024 11:34 AM - edited 01-31-2024 11:40 AM
There are VI's in the Hobbyist Toolkit (LINX) that directly support reading a 10K thermistor and there are VI's for reading devices on the I2C bus.
So you could do this entire project in LabVIEW
In general there are three ways of using LabVIEW with an Arduino