loading

This instructable likes others using DHT11 and 7 Segment Display module to show the current temperature and humidity, but I will not show you the construction, rather I will major on the technique to display data on the 7 segment display. Most of the code were not written by me, I tried to experiment with other codes to perform the same task, my code may not accurate nor effective, I just want to show you what I've done to accomplish the job.

Step 1: The Code............

As I've told that most of the code were not written by me, the copyright or any patent belongs to the originators. I also found many instructablers seldom discuss on the code they used, so I post the code here on the purpose of case study only.

int aPin = 12; int bPin = 8; int cPin = 4; int dPin = 6; int ePin = 7; int fPin = 11; int gPin = 3; int GND1 = 13; int GND2 = 10; int GND3 = 9; int GND4 = 2; int DATA_PIN = 5; int DTime = 30; #include DHT11 dht11(DATA_PIN);

void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(aPin, OUTPUT); pinMode(bPin, OUTPUT); pinMode(cPin, OUTPUT); pinMode(dPin, OUTPUT); pinMode(ePin, OUTPUT); pinMode(fPin, OUTPUT); pinMode(gPin, OUTPUT); pinMode(GND1, OUTPUT); pinMode(GND2, OUTPUT); pinMode(GND3, OUTPUT); pinMode(GND4, OUTPUT); }

void loop() { // put your main code here, to run repeatedly: int humid=0, temp=0; int d1, d2, d3, d4; switch(dht11.read()){ case DHT11::OK: humid=dht11.getHumidity(); temp=dht11.getTemperature(); d1 = temp/10; d2 = temp-(d1*10); d3 = humid/10; d4 = humid-(d3*10); displayData(d1, d2, d3, d4); break; } }

void displayData(int d1, int d2, int d3, int d4){ digitalWrite( GND1, HIGH); pickNumber(d1); delay(DTime); digitalWrite( GND1, LOW); digitalWrite( GND2, HIGH); pickNumber(d2); delay(DTime); digitalWrite( GND2, LOW); digitalWrite( GND3, HIGH); pickNumber(d3); delay(DTime); digitalWrite( GND3, LOW); digitalWrite( GND4, HIGH); pickNumber(d4); delay(DTime); digitalWrite( GND4, LOW); }

void pickNumber(int x){ switch(x){ case 1: one(); break; case 2: two(); break; case 3: three(); break; case 4: four(); break; case 5: five(); break; case 6: six(); break; case 7: seven(); break; case 8: eight(); break; case 9: nine(); break; default: zero(); break; } }

void one(){ digitalWrite( aPin, HIGH); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, HIGH); digitalWrite( ePin, HIGH); digitalWrite( fPin, HIGH); digitalWrite( gPin, HIGH); }

void two(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, HIGH); digitalWrite( dPin, LOW); digitalWrite( ePin, LOW); digitalWrite( fPin, HIGH); digitalWrite( gPin, LOW); }

void three(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, HIGH); digitalWrite( fPin, HIGH); digitalWrite( gPin, LOW); }

void four(){ digitalWrite( aPin, HIGH); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, HIGH); digitalWrite( ePin, HIGH); digitalWrite( fPin, LOW); digitalWrite( gPin, LOW); }

void five(){ digitalWrite( aPin, LOW); digitalWrite( bPin, HIGH); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, HIGH); digitalWrite( fPin, LOW); digitalWrite( gPin, LOW); }

void six(){ digitalWrite( aPin, LOW); digitalWrite( bPin, HIGH); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, LOW); digitalWrite( fPin, LOW); digitalWrite( gPin, LOW); }

void seven(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, HIGH); digitalWrite( ePin, HIGH); digitalWrite( fPin, HIGH); digitalWrite( gPin, HIGH); }

void eight(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, LOW); digitalWrite( fPin, LOW); digitalWrite( gPin, LOW); }

void nine(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, HIGH); digitalWrite( fPin, LOW); digitalWrite( gPin, LOW); }

void zero(){ digitalWrite( aPin, LOW); digitalWrite( bPin, LOW); digitalWrite( cPin, LOW); digitalWrite( dPin, LOW); digitalWrite( ePin, LOW); digitalWrite( fPin, LOW); digitalWrite( gPin, HIGH); }

Step 2: 7 Segment Display

The LCD I used is a 4 digit common anode 7 segment display, I didn't use any multiplexing circuit, I connected eleven pins to the arduino board as shown, the decimal point I have no use saved one pin to connect the DHT-11.

In the loop function, temperature and humidity data are extracted and separated into individual digit and call to the desire functions to display the digit.

In the displayData function, individual data is passed to the function and call to the pickNumbers routine to switch on and off the corresponding LED, from left to right respectively, so each LED with lit on a portion of time determined by the DTime, the more shorter time the most flickering the LED to be, to adjust the DTime most suit you.

About This Instructable

641views

12favorites

License:

More by martinhui:ESP8266 Wall Clock LEGO Clock Auto Trash by Arduino 
Add instructable to: