#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//*********************** lcd menü
int x=13; //button is connected to digital pin 13
int y=12;
int value1=0,value2=0,sira=0;
// **********************DC VOLTMETRE
int analogPin = A0;
int raw = 0;
int Vin = 5;
float Vout = 0;
float R1 = 1000;
float R2 = 0;
float buffer = 0;
//****************** PWM SİNYAL
int sensorValue = A1;
int led_pin = 2;
int yenikonum;
int voltage;
int led_value;
//******************* basinç
const int pressureInput = A2; //select the analog input pin for the pressure transducer
const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 100; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
float pressureValue = 0; //variable to store the value coming from the pressure transducer
// ac voltmetre
int Volt = A3;
// *****************direnç okuma
int analogPin1=A4;
int ap=0;
float Vout1=0;
float R=9980; //Known Resistor value in Ohm
float resistor=0;
float buffer1=0;
String symbol;
float Data=0;
//********************flowmetre
/*int X;
int Y;
float Time = 0;
float frequency = 0;
float waterFlow = 0;
float total = 0;
float LS = 0;
const int input = A5;
const int test = 9;
*/
//******************************* modulasyon
int giris = A5;
//*****************kısa devre kontrol
int buzzerPin = 7; // buzzer artı hattı bağladığımız pin
int C_ = 300; // buzzer çalması ise için atadığım nota tiz olsun ki duyalım
int cikisPin = 6; // devre tamamlama için voltajı veren hat
int gelisPin =5; // devre tamamlama kontrol etmek için verdiğimiz elektriği alabiliyor muyuz on bakacağız.
int okuma=0; // değişken atayarak 0 1 olma durumuna göre buzzer ötecek
//*************** iyonizer
#define Buton 11
#define Led1 4
//********************* RÖLE TEST
#define RoleButon 10
#define Role 3
int buton_durumu = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("GOKTEK OTOMASYON ");
lcd.setCursor(3, 1);
lcd.print("OCAK_2023 ");
delay(1000);
pinMode(led_pin, OUTPUT);
pinMode(cikisPin, OUTPUT); // pinleri tanımlıyoruz
pinMode(gelisPin, INPUT);
noTone(buzzerPin);
digitalWrite(cikisPin, HIGH);
pinMode(Volt, INPUT);
pinMode(Buton, INPUT);
pinMode(Led1, OUTPUT);
pinMode(RoleButon, INPUT);
pinMode(Role, OUTPUT);
/*pinMode(input,INPUT);
pinMode(test, OUTPUT);
analogWrite(test,100);
*/
pinMode(giris,INPUT);
}
void loop()
{
Serial.begin(9600);
//read the value of the button when pressed
value1=digitalRead(x);
value2=digitalRead(y);
if(value1==1){ //button is pressed
sira=sira+1; //add 1 to the sira variable
}
else if (value2==1){
sira=sira-1;
}
if (sira==1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_1: ");
lcd.setCursor(0,1);
lcd.print("AC VOLTMETRE ");
acVoltmetre();
}
else if (sira==2){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_2: ");
lcd.setCursor(0,1);
lcd.print("DC 0-5V VOLTMETRE ");
direncHesapla();
}
else if (sira==3){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_3: ");
lcd.setCursor(0,1);
lcd.print(" DEVRE ");
lcd.setCursor(0,2);
lcd.print("durum:");
lcd.println(" acik kontak ");
bibbib();
}
else if (sira==4){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_4: ");
lcd.setCursor(0,1);
lcd.print("0-5 VOLT PWM ");
pwmGonder();
}
else if (sira==5){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_5: ");
lcd.setCursor(0,1);
lcd.print("NTC ");
lcd.println("10K TEST ");
direnc();
}
else if (sira==6){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_6: ");
lcd.setCursor(0,1);
lcd.print("IYONIZER TEST ");
iyonizer();
}
else if (sira==7){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_7: ");
lcd.setCursor(0,1);
lcd.print("Water Flow Meter");
delay(500);
//flowmetre();
}
else if (sira==8){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_8: ");
lcd.setCursor(0,1);
lcd.print("KOMBI BASINC ");
basinc();
}
else if (sira==9){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_9: ");
lcd.setCursor(0,1);
lcd.print("MODULASYON ");
modulasyon();
}
else if (sira==10){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MENU_10: ");
lcd.setCursor(0,1);
lcd.print("ROLE KONTROL TEST ");
roleTest();
//reset the sira variable to 0
sira=0;
}
delay(100);
}
/*************************MENU1*********/
void acVoltmetre(){
int AcVolt = analogRead(Volt); // read analog input
int AcVoltOut = (AcVolt * (5.0 / 1023))*93.67; // conversion to volts
lcd.setCursor(0,3);
lcd.print("AC GERILIM:");
lcd.print(AcVoltOut); // display
lcd.print(" volt");
delay(500);
}
/******************MENU2***************/
void direncHesapla(){
raw = analogRead(analogPin);
if(raw){
buffer = raw * Vin;
Vout = (buffer)/1024.0;
buffer = (Vin/Vout) - 1;
R2= R1 * buffer;
lcd.setCursor(0,2);
lcd.print("Vout: ");
lcd.print(Vout);
lcd.print(" volt");
lcd.setCursor(0,3);
lcd.print("R2: ");
lcd.print(R2);
lcd.print("ohm ");
delay(500);
}
}
/***********************MENU3**************************/
void bibbib(){
digitalWrite(cikisPin,LOW); // çıkış pininden voltajı verdik
okuma= digitalRead(gelisPin); // gelen sinyal var mı yok mu okuyup değişkenimize atıyoruz varsa 1 yoksa 0
if(okuma== HIGH){ // 1 ise buzzer ötmesi için komut veriyoruz ve ötüyor çekince susuyor bu kadar
noTone(buzzerPin);
tone(buzzerPin, C_);
lcd.setCursor(0,2);
lcd.print("durum:");
lcd.println(" kapali kontak");
lcd.setCursor(0,3);
lcd.print("buzzer aktif ");
}
else{
noTone(buzzerPin); // sinyal olmama durumlarında susmasını söyloyoruz.
}
delay(500);
}
/***********************MENU4**************************/
void pwmGonder(){
int sensorValue = analogRead(A1);
float voltage = (sensorValue * 5.0) / 1023.0;
yenikonum = map(sensorValue,0,1023,0,255);
lcd.setCursor(0,3);
lcd.print("PWM :");
lcd.print(voltage);
lcd.print(" volt");
analogWrite(led_pin,yenikonum);
delay(500);
}
/***********************MENU5**************************/
void direnc(){
ap=analogRead(analogPin1);
buffer1=ap*5;
Vout1=(buffer)/1024.0;
buffer1=(5/Vout)-1;
resistor=R*buffer;
Data=resistor;
if (Data<999) {
symbol = "R";
ekrana_yaz();
}
if (Data>999 && Data<999999) {
Data=Data/1000;
symbol = "K";
ekrana_yaz();
}
if (Data>999999) {
Data=Data/1000000;
symbol = "M";
ekrana_yaz();
}
ekrana_yaz ();
delay(1000);
}
void ekrana_yaz(void) {
lcd.setCursor(0,2);
lcd.print("Direnc:");
lcd.print(resistor);
lcd.print(" Ohm");
lcd.setCursor(0,3);
lcd.print(Data);
lcd.setCursor(5,3);
lcd.print(symbol);
}
/***********************MENU6**************************/
void iyonizer(){
if (digitalRead(Buton) == 1){
Serial.print(Buton);
digitalWrite(Led1,HIGH);
lcd.setCursor(0,3);
lcd.print("ALEV VAR ");
}
else{
digitalWrite(Led1,LOW);
lcd.setCursor(0,3);
lcd.print("ALEV YOK ");
delay(500);
}
}
/***************************************MENU7*************/
/*void flowmetre(){
X = pulseIn(input, HIGH);
Y = pulseIn(input, LOW);
Time = X + Y;
frequency = 1000000/Time;
waterFlow = frequency/7.5;
LS = waterFlow/60;
if(frequency >= 0)
{
if(isinf(frequency))
{
lcd.setCursor(0,2);
lcd.print("L/Min: 0.00 ");
lcd.setCursor(0,3);
lcd.print("Total: ");
lcd.print(total);
lcd.print(" L");
}
else
{
total = total + LS;
lcd.setCursor(0,2);
lcd.print("L/Min: ");
lcd.print(waterFlow);
lcd.setCursor(0,3);
lcd.print("Total: ");
lcd.print(total);
lcd.print(" L");
}
}
delay(1000);
}
/***********************MENU8**************************/
void basinc(){
pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
pressureValue=pressureValue/14,5;
lcd.setCursor(0,2); //sets cursor to column 0, row 0
lcd.print("Pressure:"); //prints label
lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
lcd.print("bar"); //prints label after value
lcd.print(" "); //to clear the display after large values or negatives
delay(sensorreadDelay); //delay in milliseconds between read values
}
/***********************MENU9**************************/
void modulasyon(){
int okunan = analogRead(giris);
float voltaj = okunan * 24 / 1023;
lcd.setCursor(0,3);
lcd.print("VOLTAJ : ");
lcd.print(voltaj);
lcd.println(" V ");
delay(50);
}
/***********************MENU10**************************/
void roleTest(){
buton_durumu = digitalRead(RoleButon);
if (buton_durumu == HIGH){
Serial.print(buton_durumu);
digitalWrite(Role,HIGH);
lcd.setCursor(0,3);
lcd.print("VAR ");
}
else{
digitalWrite(Role,LOW);
lcd.setCursor(0,3);
lcd.print(" YOK ");
delay(500);
}
}