NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/****************
* Istanbul Teknik Universitesi Elektrik - Elektronik Fakültesi Kontrol ve Otomasyon Kulübü
* Akıllı Kulüp Odası Projesi v1.7
* ITU Kontrol ve Otomasyon Kulübü Teknik Projeler Ekibi 2017 Yaz Dönemi
* Amacı : Nesnelerin interneti konusunda araştırmada bulunmak, çalışma mantığını kavramak, takım çalışmasını gerçekleştirmek.
***************/
#include <Servo.h>

#define ssid "OTOKON" //Bağlanılan Ağ
#define pwd "DontPanic42" // Ağ Şifresi
#define IP "192.168.43.178" //Bağlandığımız sunucunun IP adresi

#define LdrPin A8
#define LM35Pin A15
#define MQ135Pin A14

const int KeyPadPin[] = {22,24,26,28}; // 1x4 Membran Tuş takımının bağlandığı pinler

const int LedAPin = 8;
const int LedBPin = 7;
const int PirOutsidePin = 2;
const int PirInsidePin = 3;
const int ServoPin = 9; //PWM
const int LedOnButtonPin = 21;
const int LedOffButtonPin = 20;
const int EnterButtonPin = 19;
const int ResetButtonPin = 38;
const int LedOnLedPin = 12;
const int LedOffLedPin = 13;
const int LedESPOnPin = 11;
const int LedESPOffPin = 10;
const int tenth1LedPin = 30;
const int tenth2LedPin = 32;
const int tenth3LedPin = 36;
const int tenth4LedPin = 34;
const int buzzerPin = 6;

volatile bool LedOnButton_state = 0;
volatile bool LedOffButton_state = 0;

boolean keyPadButtonState = 0;
int passwordCounter = 0;
int passwordAccuracy = 1;
int password[] = {4, 2, 3, 1};
int userInput[] = {};
int LdrThreshold = 700;
float TempValue;
float GasValue;


Servo servo;

void setup() {
servo.attach(ServoPin);
servo.write(90);
pinMode(LedAPin,OUTPUT);
pinMode(LedBPin,OUTPUT);
pinMode(LedOnLedPin,OUTPUT);
pinMode(LedOffLedPin, OUTPUT);
pinMode(LedESPOnPin,OUTPUT);
pinMode(LedESPOffPin, OUTPUT);
pinMode(tenth1LedPin, OUTPUT);
pinMode(tenth2LedPin, OUTPUT);
pinMode(tenth3LedPin, OUTPUT);
pinMode(tenth4LedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);

pinMode(PirOutsidePin,INPUT);
pinMode(PirInsidePin,INPUT);
pinMode(LdrPin,INPUT);
pinMode(LM35Pin,INPUT);
pinMode(MQ135Pin,INPUT);
pinMode(LedOnButtonPin,INPUT);
pinMode(LedOffButtonPin,INPUT);
pinMode(EnterButtonPin,INPUT);
pinMode(ResetButtonPin,INPUT);

for (int i = 0; i < 4; i++) {
pinMode(KeyPadPin[i], INPUT);
}

/* Interrupt Pinlerinin Tanımlanması */

attachInterrupt(0,PIR_OUTSIDE,RISING);//pin 2
attachInterrupt(1,PIR_INSIDE,RISING);//pin 3
attachInterrupt(2,LED_ON,RISING);//pin 21
attachInterrupt(3,LED_OFF,RISING);//pin 20
attachInterrupt(4,ENTER,RISING);//pin 19

/* ESP 8266 ile Wireless Bağlantısı */
Serial.begin(115200);
Serial.println("AT");
delay(3000);

if (Serial.find("OK")) {
Serial.println("AT+CWMODE=1");
delay(2000);
String connectCommand = String("AT+CWJAP="") + ssid + "","" + pwd """;
Serial.println(connectCommand);
delay(5000);
}

/* Ledlerin ve Servoların Başlangıç Durumunun Belirtilmesi */
digitalWrite(LedAPin,HIGH);
digitalWrite(LedBPin,HIGH);
digitalWrite(LedOnLedPin,LOW);
digitalWrite(LedOffLedPin,LOW);
digitalWrite(LedESPOnPin,LOW);
digitalWrite(LedESPOffPin, LOW);
digitalWrite(tenth1LedPin, LOW);
digitalWrite(tenth2LedPin, LOW);
digitalWrite(tenth3LedPin, LOW);
digitalWrite(tenth4LedPin, LOW);
servo.write(90);

}

void loop() {
/*
TempValue = analogRead(LM35Pin) / 9.31; //Sıcaklık değerini santigrat dereceye çeviriyoruz
Serial.println(TempValue);
GasValue = analogRead(MQ135Pin)/1024*5.0; //Hava kalitesini 0-5.0 arasına indirgiyoruz
sendInfo(TempValue, GasValue); //sendInfo fonksiyonunu çağırıyoruz

delay(3000); //30 Saniyede bir bu döngü dönsün
*/
}

void sendInfo(int temperature, int gas ) {

Serial.println(String("AT+CIPSTART="TCP","") + IP + "",8888");
delay(1000);
if (Serial.find("Error")) {
Serial.println("AT+CIPSTART Error");
return;
}
String postData = "POST /chart/temp/"; //POST methodunu kullanıyoruz sonrasında POSTu nereye göndereceğimizi sayfaya yazıyoruz
postData += " HTTP/1.1rn";
postData += "Host: ";
postData += "192.168.43.165rn"; //ESPnin aldığı IP
postData += "Accept: */*rn";
postData += "Content-Length: 7rn"; //göndereceğimiz mesajın uzunluğu
postData += "Content-Type: application/x-www-form-urlencodedrnrn";
postData += "temp="; //değişkenimizi göndereceğimiz yer
postData += int(temperature); //sıcaklık değişkenimiz
delay(3000);

Serial.print("AT+CIPSEND="); //ne kadar uzunlukta veri göndereceğimizi AT+CIPSEND komutu ile ESPye bildiriyoruz komutumuzu yollamadan
Serial.println(postData.length() + 2); // postData.length() ile yukarıdaki verimizin uzunluğunu buluyoruz sonradan yollayacağımız iki satırı* da ekliyoruz

delay(1000);

if (Serial.find(">")) { //her şey uygunsa ESP bize > bu mesajı yolluyor
Serial.print(postData); //POST requesti gönderiyor
Serial.print("rnrn"); //*= yukarıda bahsettiğimiz iki satır
}
else {
Serial.println("AT+CIPCLOSE"); // Eğer yollayamazsa "AT+CIPCLOSE" yazdırıyoruz
}
delay(1000);
Serial.println(String("AT+CIPSTART="TCP","") + IP + "",8888");
delay(1000);
if (Serial.find("Error")) {
Serial.println("AT+CIPSTART Error");
return;
}
String postData2 = "POST /chart/gas/"; //POST methodunu kullanıyoruz sonrasında POSTu nereye göndereceğimizi sayfaya yazıyoruz
postData2 += " HTTP/1.1rn";
postData2 += "Host: ";
postData2 += "192.168.43.165rn"; //ESPnin aldığı IP
postData2 += "Accept: */*rn";
postData2 += "Content-Length: 7rn"; //göndereceğimiz mesajın uzunluğu
postData2 += "Content-Type: application/x-www-form-urlencodedrnrn";
postData2 += "gas="; //değişkenimizi göndereceğimiz yer
postData2 += int(gas); //gaz kalitesi değişkenimiz
delay(3000);

Serial.print("AT+CIPSEND="); //ne kadar uzunlukta veri göndereceğimizi AT+CIPSEND komutu ile ESPye bildiriyoruz komutumuzu yollamadan
Serial.println(postData2.length() + 2); // postData.length() ile yukarıdaki verimizin uzunluğunu buluyoruz sonradan yollayacağımız iki satırı* da ekliyoruz

delay(1000);

if (Serial.find(">")) { //her şey uygunsa ESP bize > bu mesajı yolluyor
Serial.print(postData2); //POST requesti gönderiyor
Serial.print("rnrn"); //*= yukarıda bahsettiğimiz iki satır
}
else {
Serial.println("AT+CIPCLOSE"); // Eğer yollayamazsa "AT+CIPCLOSE" yazdırıyoruz
}

}

void PIR_OUTSIDE(){

if (LedOnButton_state == HIGH ){
digitalWrite(LedAPin,LOW);
}
else if(analogRead(LdrPin) <= LdrThreshold & digitalRead(LedAPin)== HIGH & LedOffButton_state == LOW)
{
digitalWrite(LedBPin,LOW);
digitalWrite(LedAPin,LOW);
}
else if(LedOffButton_state == HIGH)
{
digitalWrite(LedBPin,HIGH);
digitalWrite(LedAPin,HIGH);
}
delayMicroseconds(1000000);
}

void PIR_INSIDE(){
if (LedOnButton_state == HIGH){
digitalWrite(LedBPin,LOW);
digitalWrite(LedAPin,LOW);
}
else if(analogRead(LdrPin) < LdrThreshold & digitalRead(LedBPin)== HIGH & LedOffButton_state == LOW)
{
digitalWrite(LedBPin,LOW);
digitalWrite(LedAPin,LOW);
}
else if(LedOffButton_state == HIGH)
{
digitalWrite(LedBPin,HIGH);
digitalWrite(LedAPin,HIGH);
}
delayMicroseconds(1000000);
}


void LED_ON(){
if(LedOnButton_state = LOW){
digitalWrite(LedOnLedPin,HIGH);
digitalWrite(LedOffLedPin,LOW);
LedOffButton_state = LOW;
LedOnButton_state = HIGH;
digitalWrite(LedAPin,LOW);
digitalWrite(LedBPin,LOW);
}

else{
digitalWrite(LedOnLedPin,LOW);
LedOffButton_state = LOW;
LedOnButton_state = LOW;
digitalWrite(LedAPin,HIGH);
digitalWrite(LedBPin,HIGH);
}
}

void LED_OFF(){
if(LedOffButton_state == LOW){
digitalWrite(LedOffLedPin,HIGH);
digitalWrite(LedOnLedPin,LOW);
LedOnButton_state = LOW;
LedOffButton_state = HIGH;
digitalWrite(LedAPin,HIGH);
digitalWrite(LedAPin,HIGH);
}
else{
digitalWrite(LedOffLedPin,LOW);
LedOffButton_state == LOW;
LedOnButton_state = LOW;
digitalWrite(LedAPin,HIGH);
digitalWrite(LedAPin,HIGH);
}
}

void ENTER(){
digitalWrite(tenth1LedPin,HIGH);
digitalWrite(tenth2LedPin,LOW);

while (passwordCounter < 4) {
keyPadButtonState = digitalRead(KeyPadPin[passwordCounter]);
if (keyPadButtonState == HIGH && KeyPadPin[passwordCounter] == 22) {
delayMicroseconds(20000);
userInput[passwordCounter] = 2;
} else if (keyPadButtonState == HIGH && KeyPadPin[passwordCounter] == 24) {
delayMicroseconds(20000);
userInput[passwordCounter] = 1;
} else if (keyPadButtonState == HIGH && KeyPadPin[passwordCounter] == 26) {
delayMicroseconds(20000);
userInput[passwordCounter] = 4;
} else if (keyPadButtonState == HIGH && KeyPadPin[passwordCounter] == 28) {
delayMicroseconds(20000);
userInput[passwordCounter] = 3;
}
passwordCounter++;
}
if(digitalRead(ResetButtonPin) == HIGH){
memset(userInput, 0, sizeof(userInput));
digitalWrite(tenth2LedPin,HIGH);
}

passwordCounter = 0;
for (int i = 0; i < 4; i++) {
if (password[i] != userInput[i]) {
memset(userInput, 0, sizeof(userInput));
passwordAccuracy = 0;
break;
}
}

if (passwordAccuracy == 1) {
servo.write(25);
digitalWrite(tenth4LedPin,HIGH);
digitalWrite(tenth3LedPin,LOW);
digitalWrite(tenth2LedPin,LOW);
} else {
Buzzer();
digitalWrite(tenth4LedPin,LOW);
digitalWrite(tenth3LedPin,HIGH);
digitalWrite(tenth2LedPin,LOW);
}
digitalWrite(tenth1LedPin,LOW);

}

void Buzzer(){
tone(buzzerPin, 294);
tone(buzzerPin, 349);
tone(buzzerPin, 440);
tone(buzzerPin, 294);
tone(buzzerPin, 349);
tone(buzzerPin, 440);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.