Mar 23

Yazar:MURAT OFLEZER

11) DHT 11 Kullanmak
Bu dersimizde de DHT 11 nem ve ısı sensörünü kullanacağız. Sonuçları hem seriport ekranında hemde i2c lcd de göreceğiz.DHT 11’ in vcc ucu ile data arasına 10k direnç bağlamamız gerekmektedir.
DHT11 ve DHT22 birlikte kullanışı

Arduino Kodları;

 
#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <dht11.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

dht11 DHT11;

//Editor by MURAT OFLEZER

void setup()

{

DHT11.attach(2);

Serial.begin(9600);

lcd.begin();

lcd.backlight();

}

void loop()

{

Serial.println("\n");

int chk = DHT11.read();

Serial.print("Read sensor: ");

switch (chk)

{

case 0: Serial.println("OK"); break;

case -1: Serial.println("Checksum error"); break;

case -2: Serial.println("Time out error"); break;

default: Serial.println("Unknown error"); break;

}

Serial.print("Humidity (%): ");

Serial.println((float)DHT11.humidity, DEC);

lcd.setCursor(0,0);

lcd.print("Nem Orani (%):");

lcd.println(DHT11.humidity, DEC);

Serial.print("Temperature (°C): ");

Serial.println((float)DHT11.temperature, DEC);

lcd.setCursor(0,1);

lcd.print("Sicaklik  (C):");

lcd.print(DHT11.temperature, DEC);

delay(3000);

lcd.clear();

Serial.print("Temperature (°F): ");

Serial.println(DHT11.fahrenheit(), DEC);

lcd.setCursor(0,0);

lcd.print("Sicaklik  (F):");

lcd.print(DHT11.fahrenheit(), DEC);

Serial.print("Temperature (°K): ");

Serial.println(DHT11.kelvin(), DEC);

lcd.setCursor(0,1);

lcd.print("Sicaklik (k):");

lcd.print(DHT11.kelvin(), DEC);

delay(3000);

lcd.clear();

}

Fritzing Çizimi;

dht11

12) Rgb Led Yakmak

Şimdi de Rgb led yakalım;

 
//Katot RGB led'iniz varsa uzun ayağı GND'ye, Anot RGB LED'iniz varsa 5v'a bağlayın.

//Diğer ayakları Arduino giriş çıkış pinlerine 220Ohm'luk dirençlerle bağlayın.

const int mavi = 2;

const int yesil = 3 ;

const int kirmizi = 4;

void setup() {

pinMode(mavi, OUTPUT);

pinMode(yesil, OUTPUT);

pinMode(kirmizi, OUTPUT);

analogWrite(mavi, 255);

analogWrite(yesil, 0);

analogWrite(kirmizi, 0);

}

void loop() {

}

RGB led için bir örnek daha;

int led1=2;

int led2=3;

int led3=4;

void setup() {

pinMode(2,OUTPUT);

pinMode(3,OUTPUT);

pinMode(4,OUTPUT);

}

 void loop() {

digitalWrite(led1,HIGH);

delay(1000);

digitalWrite(led2,HIGH);

delay(1000);

digitalWrite(led3,HIGH);

delay(1000);

digitalWrite(led1,LOW);

delay(1000);

digitalWrite(led2,LOW);

delay(1000);

digitalWrite(led3,LOW);

delay(1000);

digitalWrite(led1,LOW);

digitalWrite(led2,LOW);

digitalWrite(led3,LOW);

delay(1000);

}

Fritzing Çizimi;

rgb1

Ve şimdi de potansiyometre ile rgb ledi kontrol edelim;

 
int pot1=A0;

int pot2=A1;

int pot3=A2;

int led1=2;

int led2=7;

int led3=4;

void setup() {

pinMode(A0,INPUT);

pinMode(A1,INPUT);

pinMode(A2,INPUT);

pinMode(2,OUTPUT);

pinMode(7,OUTPUT);

pinMode(4,OUTPUT);

}

void loop() {

int konum=analogRead(pot1);

konum=map(konum,0,1023,0,255);

analogWrite(2,konum);

int konum1=analogRead(pot2);

konum1=map(konum1,0,1023,0,255);

analogWrite(7 ,konum1);

int konum2=analogRead(pot3);

konum2=map(konum2,0,1023,0,255);

analogWrite(4,konum2);

}

Fritzing Çizimi:

rgb2

13) 7 Display Kullanımı

7 display anot ve katot olmak üzere ikiye ayrılıyor eğer anot ise ortak bacaklarını + ya;

Eğer katot ise orta bacaklarını – ye bağlamamız gerekmektedir şemada daha iyi anlayacağız.

7 display

Eğer Ortak Anot İse Kodları;

 
int a = 6;

int b = 7;

int c = 9;

int d = 10;

int e = 11;

int f = 5;

int g = 4;

void setup()

{

pinMode(a, OUTPUT);

pinMode(b, OUTPUT);

pinMode(c, OUTPUT);

pinMode(d, OUTPUT);

pinMode(e, OUTPUT);

pinMode(f, OUTPUT);

pinMode(g, OUTPUT);

}

void RakamYaz(int rakam)

{

switch(rakam)

{

case 0 :

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

break;

case 1:

digitalWrite(a, HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 2:

digitalWrite(a, LOW);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

break;

case 3:

digitalWrite(a, LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

break;

case 4:

digitalWrite(a, HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 5:

digitalWrite(a, LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 6:

digitalWrite(a, LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 7:

digitalWrite(a, LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 8:

digitalWrite(a, LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 9:

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

}

}

void loop(){

for(int i=0; i<=9;i++){

RakamYaz(i);

delay(500);

}

}

Eğer Ortak Katot İse Kodları;

 
int a = 6;

int b = 7;

int c = 9;

int d = 10;

int e = 11;

int f = 5;

int g = 4;

void setup()

{

pinMode(a, OUTPUT);

pinMode(b, OUTPUT);

pinMode(c, OUTPUT);

pinMode(d, OUTPUT);

pinMode(e, OUTPUT);

pinMode(f, OUTPUT);

pinMode(g, OUTPUT);

}

void RakamYaz(int rakam)

{

switch(rakam)

{

case 0 :

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

break;

case 1:

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 2:

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

break;

case 3:

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

break;

case 4:

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 5:

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 6:

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 7:

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

break;

case 8:

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

case 9:

digitalWrite(a,HIGH);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

break;

}

}

void loop(){

for(int i=0; i<=9;i++){

RakamYaz(i);

delay(500);

}

}

Fritzing Çizimi;

Sema

Yorum Yaz