BASIC4MCU | 질문게시판 | 온도 센서 오류
페이지 정보
작성자 핸찌니 작성일2023-05-03 00:40 조회543회 댓글1건본문
안녕하세요!
이번엔 와이어링을 끝내고 코드를 실행햇는데 온도센서가 작동하지않습니다
사용한 온도센서는 ds18b20 인데 온도가 300도이상으로 나오고 변하지않습니다
// define the pins for the sensors
const int phSensorPin = A0;
const int temperatureSensorPin = 2;
const int ultrasonicTriggerPin = 3;
const int ultrasonicEchoPin = 4;
// define variables to store the sensor readings
float pHValue = 0.0;
float temperatureValue = 0.0;
float distanceValue = 0.0;
void setup() {
// initialize serial communication
Serial.begin(9600);
// set the pin modes
pinMode(temperatureSensorPin, INPUT);
pinMode(ultrasonicTriggerPin, OUTPUT);
pinMode(ultrasonicEchoPin, INPUT);
}
void loop() {
// read the pH value from the sensor
int rawValue = analogRead(phSensorPin);
float voltage = rawValue * 5.0 / 1024.0;
pHValue = 3.5 * voltage;
// read the temperature from the sensor
int rawTemperatureValue = analogRead(temperatureSensorPin);
float voltageTemperature = rawTemperatureValue * 5.0 / 1024.0;
temperatureValue = (voltageTemperature - 0.5) * 100.0;
// read the distance from the ultrasonic sensor
digitalWrite(ultrasonicTriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(ultrasonicTriggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(ultrasonicTriggerPin, LOW);
float duration = pulseIn(ultrasonicEchoPin, HIGH);
distanceValue = (duration / 2.0) * 0.0343;
// print the sensor values to the serial monitor
Serial.print("pH value: ");
Serial.println(pHValue);
Serial.print("Temperature value: ");
Serial.print(temperatureValue);
Serial.println(" degrees Celsius");
Serial.print("Distance value: ");
Serial.print(distanceValue);
Serial.println(" cm");
// wait for 1 second before reading again
delay(1000);
}
사용한 코드입니다
댓글 1
조회수 543master님의 댓글
master 작성일
라이브러리 설치하면 예제가 함께 설치됩니다.
라이브러리의 예제를 구동해서 정상동작하는지 확인하시고요
선연결에 문제가 없는 지도 체크하세요