Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa berfungsi sebagai pasien monitor, jadi alat ini bisa mendeteksi heart beat atau detak jantung dan suhu tubuh dengan output yaitu bisa diprint dengan printer thermal sehingga ada data recordnya. alat ini menggunakan pulse sensor dan sensor DS18B20. kemudian agar pada kertas printer terdapat jam dan tanggal maka ditambahi RTC DS1302. untuk lebih jelasnya berikut adalah program dan skemanya.
a. Arduino Uno
b. Sensor Suhu DS18B20
c. Sensor Pulse
d. RTC DS1302
e. LCD 16x2
f. Printer Thermal
g. Program Arduino IDE
#include "Wire.h"
#include <LiquidCrystal.h>
#include <DS1302.h>
#include <OneWire.h>
#include <SoftwareSerial.h>
SoftwareSerial Thermal(0, 1);
LiquidCrystal lcd(11, 9, 8, 7, 6, 5);
// Init the DS1302
DS1302 rtc(2, 3, 4);
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
int buzzer = 13;
int tombol = 12;
int tombolx;
int n = 0;
int x;
int dataadc;
int bpmx;
int bpms;
void initPrinter()
{
//Modify the print speed and heat
Thermal.write(27);
Thermal.write(55);
Thermal.write(7); //Default 64 dots = 8*('7'+1)
Thermal.write(heatTime); //Default 80 or 800us
Thermal.write(heatInterval); //Default 2 or 20us
//Modify the print density and timeout
Thermal.write(18);
Thermal.write(35);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.write(printSetting); //Combination of printDensity and printBreakTime
}
void setup(){
Thermal.begin(19200); // to write to our new printer
initPrinter();
Wire.begin();
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
pinMode(tombol,INPUT);
digitalWrite(tombol,HIGH);
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(TUESDAY);
//rtc.setTime(12, 43, 0);
//rtc.setDate(21, 3, 2017);
}
void loop(){
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
tombolx = digitalRead(tombol);
if(tombolx == 0){
lcd.clear();
lcd.print("Printing...");
//TURN OFF UNDERLINE MODE
Thermal.write(27);
Thermal.write(45);
Thermal.write(zero);
delay(3000);
//NORMAL MODE
Thermal.println("HASIL PEMERIKSAAN");
Thermal.print(rtc.getTimeStr());
Thermal.print(" ");
Thermal.println(rtc.getDateStr());
Thermal.write(10);
//print suhu
Thermal.print("Suhu = ");
Thermal.print(celsius);
Thermal.println(" c");
Thermal.print("BPM = ");
Thermal.print(bpmx);
Thermal.write(10);
lcd.clear();
}
dataadc = analogRead(0);
if(dataadc > 600){
delay(200);
n = 0;
bpmx = 0;
bpms = 0;
lcd.clear();
bpm();
}
// Display time centered on the upper line
lcd.setCursor(0, 0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(0, 1);
lcd.print("T= ");
lcd.print(celsius);
lcd.setCursor(9, 1);
lcd.print("B= ");
lcd.print(bpmx);
if((bpmx < 50)&&(bpmx > 0)){
digitalWrite(buzzer,LOW);
}
else if(bpmx > 130){
digitalWrite(buzzer,LOW);
}
else if(celsius > 37){
digitalWrite(buzzer,LOW);
}
else
{
digitalWrite(buzzer,HIGH);
}
/* Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());
*/
delay(1000); // maybe 750ms is enough, maybe not
}
void bpm(){
n++;
dataadc = analogRead(0);
if ((dataadc > 600) && (x == 1)) {
x = 0;
bpms = bpms + 1;
}
else if ((dataadc < 600) && (x == 0)) {
x = 1;
}
lcd.setCursor(0, 0);
lcd.print("BPM= ");
lcd.print(bpms);
delay(200);
if(n > 50){
bpmx = bpms * 6;
lcd.clear();
return;
}
else{
bpm();
}
}
h. Gambar Hasil Print-nya
i. VIDEO HASILNYA
No comments:
Post a Comment