BASIC4MCU | 질문게시판 | 여러센서 아두이노 연결관련 코드
페이지 정보
작성자 핸찌니 작성일2023-04-29 22:04 조회792회 댓글0건본문
안녕하세요 저번에 master님께서 알려주신대로 이번엔 챗지피티의 도움을 조금받아서 세가지의 센서 ( 초음파, 온도 그리고 ph) 를 연결하고자하는데 코드가 맞는지 모르겠습니다ㅜㅜ
이코드가 잘작동이 된다면 이제 aws 에 연결하여 일정범위를 넘기면 알람을 보내는 프로젝트인데요ㅜㅜ
// include the libraries for the sensors
#include <phSensor.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// create instances of the sensors
phSensor pH;
OneWire oneWire(2); // set the pin for the temperature sensor
DallasTemperature temperatureSensor(&oneWire);
int ultrasonicTriggerPin = 3; // set the pins for the ultrasonic sensor
int ultrasonicEchoPin = 4;
void setup() {
// initialize serial communication
Serial.begin(9600);
// initialize the sensors
pH.begin();
temperatureSensor.begin();
}
void loop() {
// read the pH value from the sensor
float pHValue = pH.read();
// read the temperature from the sensor
temperatureSensor.requestTemperatures();
float temperatureValue = temperatureSensor.getTempCByIndex(0);
// read the distance from the ultrasonic sensor
digitalWrite(ultrasonicTriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(ultrasonicTriggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(ultrasonicTriggerPin, LOW);
float distanceValue = pulseIn(ultrasonicEchoPin, HIGH) / 58.0;
// 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);
}
댓글 0
조회수 792등록된 댓글이 없습니다.