The main character of this implementation is a 4-digit 7-segment LED display, which is divided into a common anode and a common cathode, just like a single 7-segment display. If it is a common anode, the pin of the common anode is connected to the voltage terminal (5V). If it is a common cathode, the pin of the common cathode is connected to GND. The four common or common yang of the four-digit display is used to control which number to be displayed. The display mode is that only one number can be displayed at the same time. Just like watching a movie, the principle of visual persistence is used to make each number extremely In a short time, the illusion will make the eyes look brighter by 4 numbers.
The pins of the 4-digit 7-segment display are as follows:
• Arduino UNO R3 x 1
Pin assignment of Arduino Pin to 4-digit 7-segment display:
The pins of the 4-digit 7-segment display are as follows:
[Material]
• Arduino UNO R3 x 1
• 4-digit 7-segment LED display x 1
• DHT-11 temperature and humidity sensor x 1
• Breadboard x 1
• Connection line xn
[Wiring diagram]
Pin assignment of Arduino Pin to 4-digit 7-segment display:
Pin 2 -> A
Pin 3 -> B
Pin 4 -> C
Pin 5 -> D
Pin 6 -> 1
Pin 7 -> F
Pin 8 -> G
Pin 9 -> 4
Pin 10 -> 3
Pin 11 -> 2
Pin 12 -> E
[Code]
The following is a common anode display program. If it is a common cathode, change the potential HIGH to LOW and LOW to HIGH.
#include <Adafruit_Sensor.h> #include <DHT.h> #define DHT11_PIN A0 // 連接DHT11 的Pin #define DHTTYPE DHT11 // DHT 11 DHT dht(DHT11_PIN, DHTTYPE); int a = 2; int b = 3; int c = 4; int d = 5; int e = 12; int f = 7; int g = 8; int GND1 = 6; int GND2 = 11; int GND3 = 10; int GND4 = 9; int dig1 = 0; int dig2 = 0; int dig3 = 0; int dig4 = 0; int Temp; int Humi; int i; int j; void setup() { dht.begin(); for(int x = 2; x < 13; x++) { pinMode(x,OUTPUT); } } void loop() { // show temperature Temp = dht.readTemperature(); for (int i = 1; i <= 500; i++) { dig1 = Temp / 10; dig2 = Temp - (dig1 * 10); dig3 = 10; dig4 = 11; digitalWrite( GND4, HIGH); // 4 DisplayNumber(dig4); delay(4); digitalWrite( GND4, LOW); digitalWrite( GND3, HIGH); // 3 DisplayNumber(dig3); delay(4); digitalWrite( GND3, LOW); digitalWrite( GND2, HIGH); // 2 DisplayNumber(dig2); delay(4); digitalWrite( GND2, LOW); digitalWrite( GND1, HIGH); // 1 DisplayNumber(dig1); delay(4); digitalWrite( GND1, LOW); } // show humidity Humi = dht.readHumidity(); for (int j = 1; j <= 500; j++) { dig1 = Humi / 10; dig2 = Humi - (dig1 * 10); dig3 = 12; dig4 = 12; digitalWrite( GND4, HIGH); // 4 DisplayNumber(dig4); delay(4); digitalWrite( GND4, LOW); digitalWrite( GND3, HIGH); // 3 DisplayNumber(dig3); delay(4); digitalWrite( GND3, LOW); digitalWrite( GND2, HIGH); // 2 DisplayNumber(dig2); delay(4); digitalWrite( GND2, LOW); digitalWrite( GND1, HIGH); // 1 DisplayNumber(dig1); delay(4); digitalWrite( GND1, LOW); } } void DisplayNumber(int x) { switch (x) { case 0: zero(); break; 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; case 10: o(); break; case 11: C(); break; case 12: oo(); break; } } void zero() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, LOW); digitalWrite( g, HIGH); } void one() { digitalWrite( a, HIGH); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, HIGH); digitalWrite( e, HIGH); digitalWrite( f, HIGH); digitalWrite( g, HIGH); } void two() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, HIGH); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, HIGH); digitalWrite( g, LOW); } void three() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, HIGH); digitalWrite( f, HIGH); digitalWrite( g, LOW); } void four() { digitalWrite( a, HIGH); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, HIGH); digitalWrite( e, HIGH); digitalWrite( f, LOW); digitalWrite( g, LOW); } void five() { digitalWrite( a, LOW); digitalWrite( b, HIGH); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, HIGH); digitalWrite( f, LOW); digitalWrite( g, LOW); } void six() { digitalWrite( a, LOW); digitalWrite( b, HIGH); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, LOW); digitalWrite( g, LOW); } void seven() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, HIGH); digitalWrite( e, HIGH); digitalWrite( f, HIGH); digitalWrite( g, HIGH); } void eight() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, LOW); digitalWrite( g, LOW); } void nine() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, HIGH); digitalWrite( f, LOW); digitalWrite( g, LOW); } void o() { digitalWrite( a, LOW); digitalWrite( b, LOW); digitalWrite( c, HIGH); digitalWrite( d, HIGH); digitalWrite( e, HIGH); digitalWrite( f, LOW); digitalWrite( g, LOW); } void C() { digitalWrite( a, LOW); digitalWrite( b, HIGH); digitalWrite( c, HIGH); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, LOW); digitalWrite( g, HIGH); } void oo() { digitalWrite( a, HIGH); digitalWrite( b, HIGH); digitalWrite( c, LOW); digitalWrite( d, LOW); digitalWrite( e, LOW); digitalWrite( f, HIGH); digitalWrite( g, LOW); }
[Results]
The top photo shows the temperature and the bottom image shows the humidity.
[Reference]
Great Projects: Temperature and Humidity Displayed on 4 Digit 7 segment
Tags:
Arduino