티스토리 뷰
python/Lecture
[arduino] DS18B20 Digital Sensor 연결 및 wifi 통신 to Web
jinozpersona 2023. 11. 23. 15:02Arduino UNO R4 Wifi : DS18B20 연결도
WiFi 공유기

[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
[Code 작성 및 시리얼모니터링]
#include "RTC.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiS3.h>
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int keyIndex = 0; // your network key index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(80);
#define ONE_WIRE_BUS 13
OneWire Wire(ONE_WIRE_BUS);
DallasTemperature sensor(&Wire);
char value[8];
int loopcnt = 0;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin();
// you're connected now, so print out the status:
printWifiStatus();
RTC.begin();
RTCTime startTime(27, Month::NOVEMBER, 2023, 10, 00, 00, DayOfWeek::MONDAY, SaveLight::SAVING_TIME_ACTIVE);
RTC.setTime(startTime);
}
void loop() {
RTCTime currentTime;
// Get the current time from the RTC
RTC.getTime(currentTime);
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an HTTP request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the HTTP request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard HTTP response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
sensor.requestTemperatures();
dtostrf(sensor.getTempCByIndex(0) , 5, 2, value);
Serial.println(value);
// output Date Time & value
// Print the date (DD/MM/YYYY)
client.print(currentTime.getDayOfMonth());
client.print("/");
client.print(Month2int(currentTime.getMonth()));
client.print("/");
client.print(currentTime.getYear());
client.print(" - ");
// Print the time (HH:MM:SS)
client.print(currentTime.getHour());
client.print(":");
client.print(currentTime.getMinutes());
client.print(":");
client.println(currentTime.getSeconds());
client.println("<br />");
client.print(value);
client.println("<br />");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
wifi SSID, PASS header file(동일 폴더에 두고 업로드)
arduino_secrets.h
//arduino_secrets.h header file
#define SECRET_SSID "TP-LINK_C71232"
#define SECRET_PASS "YourWIFI_PASS"
Serial Monitor

browser : 172.30.1.160

반응형
'python > Lecture' 카테고리의 다른 글
[arduino][python] DS18B20 Digital Sensor pyserial 통신 (0) | 2023.11.23 |
---|---|
[arduino] DS18B20 Digital Sensor 연결 및 BLE 통신 to App. (0) | 2023.11.23 |
[arduino] DS18B20 Digital Sensor 연결 및 wifi 통신 with MariaDB (0) | 2023.11.22 |
[arduino][python] DS18B20 Digital Sensor Bluetooth 통신 (0) | 2023.11.21 |
[arduino] YF-S401 Flow Sensor 연결 및 모니터링 (0) | 2023.11.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- arduino
- DAQ
- COVID-19
- vscode
- Raspberry Pi
- github
- pyserial
- Django
- CSV
- 확진
- 자가격리
- template
- ERP
- server
- Regression
- 라즈베리파이
- Python
- r
- 코로나
- Templates
- MacOS
- Model
- DS18B20
- sublime text
- 코로나19
- Pandas
- git
- analysis
- raspberrypi
- SSH
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함