Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )

PROJECT 3: BAR GRAPH

Audio Amplifier ေတြမွာ အသံလိႈင္း အတတ္ အက်ကို လိုက္ျပီးေတာ့ Led


မီးတန္းေလးေတြ လိုက္ကစားေနတာတို႔ ၊ Led မီးတန္းေလးျဖင့္ volume တင္တဲ့
ပမာဏကို ျပန္လည္ေဖာ္ျပေပးၾကတာတို႔ကို ေတြ႔ဖူးၾကမွာပါ ။ အယ့္ဒီ့
မီးတန္းေလးကို Bar graph လုိ႔ ေခၚျပီး သူူ႔ကို အလ်ားလိုက္ (သိ)ု႔ ေဒါင္လက
ို ္
လိုအပ္သလို စီတန္းထားၾကပါတယ္ ။ Potentiometer (သိ)ု႔ Microphone
ကဲ့သို႔ေသာ Analog input device ေတြမွ ေပးပို႔တဲ့ တန္ဖိုးေတြကို
လက္ခံျပီးေတာ့ Led မီးတန္းျဖင့္ အနီးစပ္ဆံုး ပမာဏကို ျပန္လည္
ေဖာ္ျပေပးၾကတာပဲ ျဖစ္ပါတယ္ ။ ဒါကို စမ္းသပ္ေလ့လာ ၾကည့္ပါမယ္ ဗ် ။
2

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )

လုိအပ္တဲ့ ပစၥည္းမ်ား

• Arduino board x 1
• Breadboard x 1
• Jumper wires x 13
• LED x 9
• 50k-ohm potentiometer x 1
• 220-ohm resistor x 9
3

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )

Circuit Diagram

ပံုပါအတိုင္း ခ်ိတ္ဆက္ေပးပါ ။

သိမွတ္စရာ

ညာ ေပါင္း (+)
ဘယ္ အနုတ္ (-)

အလယ္ Output
4

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )

Program ( SKETCH )

/*
*Program Name : Led Bar Graph
*/
const int Analog_input_Pin = A0; // Pin connected to the potentiometer
const int LedNumber = 9; // Number of LEDs
int ledPins[] = {2,3,4,5,6,7,8,9,10}; // Pins connected to the LEDs

void setup() {
for (int thisLed = 0; thisLed < LedNumber; thisLed++) {
// Set the LED pins as output
pinMode(ledPins[thisLed], OUTPUT);
}
}

void loop() {
// Receive Analog input
int InputValue = analogRead(Analog_input_Pin);
// input and output value Mapping
int ledLevel = map(InputValue, 0, 1023, 0, LedNumber );

for (int thisLed = 0; thisLed < LedNumber ; thisLed++) {


// Turn on LEDs in sequence
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// Turn off LEDs in sequence
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
5

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )

ရွင္းလင္းခ်က္

const int Analog_input_Pin = A0; // Pin connected to the potentiometer


Arduino မွ pin A0 ဟာ Analog_input_Pin ျဖစ္ေၾကာင္း အမည္သက္မွတ္ေပး
ျခင္းျဖစ္ပါတယ္။
const int LedNumber = 9; // Number of LEDs
အသံုးျပဳမယ့္ Led အလံုးအေရအတြက္က ၉ လံုး ။

int ledPins[] = {2,3,4,5,6,7,8,9,10}; // Pins connected to the LEDs


pin No - 2,3,4,5,6,7,8,9,10 ဟာ Led တပ္ဆင္မယ့္ LedPin မ်ားျဖစ္ေၾကာင္း
Array တခုအျဖစ္ စုဖြဲ႔တည္ေဆာက္ျခင္း ။

void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// Set the LED pins as output
pinMode(ledPins[thisLed], OUTPUT);
}
}
ေပၚမွာ ေဖာ္ျပေပးခဲ့တဲ့ pin No ေတြကို Output အျဖစ္ အသံုးျပဳမည္
ဆိုသည့္အေၾကာင္းကို void setup ထဲမွာ ေၾကညာေပးျခင္းျဖစ္ပါတယ္ ။
For statement နဲ႔ Array အေၾကာင္းကို သိရင္ေတာ့ ေသခ်ာနားလည္
ပါလိမ့္မယ္။

void loop() {
// Receive Analog input
int InputValue = analogRead(Analog_input_Pin);
Analog pin မွ ရရွိေသာ တန္ဖိုးမ်ားကို Input value အျဖစ္
သက္မွတ္ေပးျခင္းျဖစ္ပါတယ္။
6

Arduino project hand book Myanmar Arduino Learner (Ye Lin Naing )
// input and output value Mapping
int ledLevel = map(InputValue, 0, 1023, 0, LedNumber);
ရရွိတဲ့ input တန္းဖိုးေတြဟာ 0 မွ 1023 အတြင္းမွာ ရွိေနမွာျဖစ္ျပီး ထုိတန္ဖိုးကို
အေရအတြက္ ၉လံုးရွိတဲ့ Led မီးတန္းအတြက္ ရွိရမယ့္ Led level အျဖစ္ Map
function ကို အသံုးျပဳကာ ၄င္းတန္ဖိုးႏွစ္ခုအား ယွဥ္တြဲ တြက္ထုတ္ေပးရမွာပဲ
ျဖစ္ပါတယ္ ။

for (int thisLed = 0; thisLed < LedNumber ; thisLed++) {


// Turn on LEDs in sequence
if (thisLed <= ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// Turn off LEDs in sequence
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}

Led level နွင့္ ညီေသာပမာဏထိ Led မ်ားဟာ လင္းမယ္ ။ က်န္တဲ့ Led


ေတြဟာ မွိတ္ေနမယ္ ။ ဥပမာ Led level ဟာ 5 ရွိတယ္ဆိုရင္ Pin No-2,3,4,5,6
ဟာ HIGH (Led On) ျဖစ္ေနမွာျဖစ္ျပီး က်န္ pin မ်ားျဖစ္သည့္ 7,8,9,10 ဟာ
LOW ( Led Off) ျဖစ္ေစမွာပဲ ျဖစ္ပါတယ္ ။

ှါသနာရွင္မ်ား အားလံုးအား အစဥ္ေလးစား


တန္ဖိုးထားလ်က္ …
Myanmar Arduino Learner ( Y.L.N )

You might also like