BASIC4MCU | 질문게시판 | 온도센서로 스위치 역할을 코딩부탁드립니다 ㅠㅠ
페이지 정보
작성자 야채왕 작성일2018-12-16 01:10 조회6,320회 댓글0건본문
하고자 하는 방향은 이렇습니다.
아두이노 쉴드에 블루투스 + 온도 + 심박센서 를 연동하는것인데요
블투+심박코드와 온도아두이노 코드를 합치고 싶습니다
근데 여기서 관건은 온도가 20 도 이하일경우인데요
1. 심박이 무조건 100으로 출력되기
2. 블루투스모듈이 꺼지기
둘중 하나만 충족이 되면 됩니다.
만약 온도가 20도 이상이라면 블루투스를통해 측정된 심박만 전송이되는거고요...
다소 까다롭지만... 부탁드립니다 ㅠㅠㅠ
온도센서 코딩값
#include <math.h>
int a;
float temperature;
int B=3975; //B value of the thermistor
float resistance;void setup()
{
Serial.begin(9600);
}void loop()
{
a=analogRead(0);
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
delay(1000);
Serial.print("Current temperature is ");
Serial.println(temperature);
}
블루투스 센서 + 심박센서 코딩값
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //블루투스의 Tx,Rx핀을 2번 3번핀으로 설정
//
#include <Wire.h>
//
long t=0;
//
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("heart rate sensor: ");
mySerial.begin(9600);
}
//
void loop(){
if(millis()-t>500){ t=millis(); // 500ms 마다 처리
Wire.requestFrom(0xA0>>1,1); // request 1 bytes from slave device
while(Wire.available()){ // slave may send less than requested
unsigned char c=Wire.read(); // receive heart rate value(a byte)
Serial.println(c,DEC); // print heart rate value
mySerial.println(c,DEC); // print heart rate value 블루투스 전송
}
}
//
if(mySerial.available()){
Serial.write(mySerial.read());
}
if(Serial.available()){
mySerial.write(Serial.read());
}
}
감사합니다.
댓글 0
조회수 6,320등록된 댓글이 없습니다.