티스토리 뷰

Arduino UNO R4 Wifi : DS18B20 연결도

 

[Arduino IDE 사용] / [Visual Studio Code사용]

Arduino IDE or VS code 초기 셋팅 및 설정 참고

https://jinozblog.tistory.com/207

 

[arduino] LM35 / TMP36 Sensor 연결도 : arduino IDE or VScode 설정 및 모니터링

Arduino UNO R3 : LM35 Sensor 연결도(TMP36 동일) 및 전달함수식 LM35 Analog Output이므로 A0 ~ A5에 연결 : 필자는 A0에 연결 range : 온도 / 출력(전송)전압, -55ºC ~ 150ºC : -550mV ~ 1500mV LM35 Transfer Function Arduino AO resol

jinozblog.tistory.com

 

 

 

#include <OneWire.h>
#include <DallasTemperature.h>

#include <ArduinoBLE.h>

#define ONE_WIRE_BUS 13
OneWire Wire(ONE_WIRE_BUS);
DallasTemperature sensor(&Wire);
char value[8];
const int ledPin = LED_BUILTIN; // pin to use for the LED

static const char* sensing = "Hello, persona!";
BLEService sensingService("0454e724-abec-43e1-8bbd-46db509439c4");  // User defined service
BLEStringCharacteristic sensingCharacteristic("0454e724-abec-43e1-8bbd-46db509439c4",  BLERead | BLENotify, 15);

void setup() {
  Serial.begin(9600);    // initialize serial communication
  while (!Serial);

  pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin

  if (!BLE.begin()) {   // initialize BLE
    Serial.println("starting BLE failed!");
    while (1);
  }

  BLE.setLocalName("ArduinoR4_persona");  // Set name for connection
  BLE.setAdvertisedService(sensingService); // Advertise service
  
  sensingService.addCharacteristic(sensingCharacteristic); // Add characteristic to service
  BLE.addService(sensingService); // Add service
  
  // assign event handlers for connected, disconnected to peripheral
  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
  
  // assign event handlers for characteristic
  sensingCharacteristic.setValue(sensing); // Set sensing string

  BLE.advertise();  // Start advertising
  
  Serial.println(("Bluetooth® device active, waiting for connections..."));
}

void loop() {
  BLE.poll();
  sensor.requestTemperatures();
  dtostrf(sensor.getTempCByIndex(0) , 5, 2, value);
  sensingCharacteristic.writeValue(value);
}

void blePeripheralConnectHandler(BLEDevice central) {
  // central connected event handler
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
  Serial.println("LED on");
  digitalWrite(ledPin, HIGH);
}

void blePeripheralDisconnectHandler(BLEDevice central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
}

 

 

Serial Monitor

 

 

iPhone App. : LightBlue

 

 

 

우측 상단 Hex 클릭 : to UTF-8

 

 

 

 

Read again : 온도계 손으로 잡고 있으면 올라가는 거 확인 가능

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함