0% found this document useful (0 votes)
5 views

Arduino Septian - Ino

The document contains code for an Arduino program that reads pressure sensor data, calculates pressure in mmHg, saves data to an SD card, and sends notifications if the pressure is outside normal ranges. It initializes serial communication and an SD card, defines variables for the pressure sensor reading and calculated pressure values, and contains functions to read sensor data, save to the SD card, and check the pressure against thresholds.

Uploaded by

Septian Wahyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Arduino Septian - Ino

The document contains code for an Arduino program that reads pressure sensor data, calculates pressure in mmHg, saves data to an SD card, and sends notifications if the pressure is outside normal ranges. It initializes serial communication and an SD card, defines variables for the pressure sensor reading and calculated pressure values, and contains functions to read sensor data, save to the SD card, and check the pressure against thresholds.

Uploaded by

Septian Wahyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SPI.

h>
#include <SD.h>
float sensor = A6; //Define the pin for potentiometer
float mmhg2=0;
float ADC_Tekanan= 0,
nilai_tegangan= 0;
int count;
float mmhg=0 ;
int pin_value = 0;
int progress_value;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
}
}

void save()
{
File dataku = SD.open("dika.txt", FILE_WRITE);
if (dataku){
dataku.println(count);
dataku.print(") mmHg=");
dataku.println(mmhg2);
dataku.close();
delay(1000);
Serial.println("Data Tersimpan");
count++;
}
}
void loop() {
ADC_Tekanan = analogRead(sensor);
nilai_tegangan = ADC_Tekanan*0.00478983;
mmhg = ((((nilai_tegangan/5.0)-0.04)/0.018)*7.5)-1;
if (mmhg<0){mmhg2= 0;}
if (mmhg>0 && mmhg<20){ mmhg2= mmhg;}
if (mmhg>20 && mmhg<60){mmhg2 = mmhg - (mmhg*0.14);}
if (mmhg>60 && mmhg<375){mmhg2 = mmhg - (mmhg*0.195);}

String command1 ="dika.txt=\""+String(mmhg2,2)+"\"";


Serial.print(command1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

if (Serial.available()>0)
{
String Received = Serial.readString();

if (Received[0] == 's')
{
Serial.println("save");
save();
}
}
ADC_Tekanan = analogRead(sensor);
nilai_tegangan = ADC_Tekanan*0.00478983;
mmhg = ((((nilai_tegangan/5.0)-0.04)/0.018)*7.5)-1;
if (mmhg<0){mmhg2= 0;}
if (mmhg>0 && mmhg<20){ mmhg2= mmhg;}
if (mmhg>20 && mmhg<60){mmhg2 = mmhg - (mmhg*0.14);}
if (mmhg>60 && mmhg<375){mmhg2 = mmhg - (mmhg*0.195);}
String command2 ="sep.txt=\""+String(mmhg2,2)+"\"";
Serial.print(command2);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(200);
pin_value=mmhg2;
if(progress_value !=pin_value){
progress_value=pin_value;
if(progress_value>165 && progress_value<185 ){
Serial.print("t2.txt=\"BOCOR\"");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else if(progress_value>185 && progress_value<215){
Serial.print("t2.txt=\"BAIK\"");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
}
}

You might also like