Components and supplies
5 mm LED: Red
Jumper wires (generic)
HC-05 Bluetooth Module
Solderless Breadboard Full Size
Resistor 220 ohm
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
Arduino LED patterns with Bluetooth
c_cpp
Arduino LED patterns with Bluetooth
1int t = 100; 2int counter = 10; 3int val = 0; 4 5void setup() { 6 for(int i = 4; i <= 13; i++){ 7 pinMode(i,OUTPUT); 8 } 9 Serial.begin(9600); 10} 11 12void loop() { 13 if(Serial.available()){ 14 val = Serial.read(); 15 Serial.println(val,DEC); 16 } 17 if(val == '1'){ 18 pat1(); 19 } 20 else if(val == '2'){ 21 pat2(); 22 } 23 else if(val == '3'){ 24 pat3(); 25 } 26 else if(val == '4'){ 27 pat4(); 28 } 29 else if(val == '5'){ 30 pat5(); 31 } 32 else if(val == '6'){ 33 pat6(); 34 } 35 else if(val == '7'){ 36 pat7(); 37 } 38} 39 40void pat1(){ 41 for(int i = 4; i <= 13; i++){ 42 digitalWrite(i,HIGH); 43 delay(t); 44 digitalWrite(i,LOW); 45 } 46 for(int i = 12; i >= 4; i--){ 47 digitalWrite(i,HIGH); 48 delay(t); 49 digitalWrite(i,LOW); 50 } 51} 52void pat2(){ 53 for(int i = 4; i<=13; i=i+2){ 54 digitalWrite(i,HIGH); 55 delay(t); 56 digitalWrite(i,LOW); 57 } 58 for(int i = 12; i>=4; i=i-2){ 59 digitalWrite(i,HIGH); 60 delay(t); 61 digitalWrite(i,LOW); 62 } 63} 64void pat3(){ 65 for(int i = 4; i <= 13; i++){ 66 digitalWrite(i,HIGH); 67 delay(t); 68 } 69 for(int i = 13; i >= 4; i--){ 70 digitalWrite(i,LOW); 71 delay(t); 72 } 73} 74void pat4(){ 75 for(int i = 4; i <= 8; i++){ 76 digitalWrite(i,HIGH); 77 } 78 delay(500); 79 for(int i = 4; i <= 8; i++){ 80 digitalWrite(i,LOW); 81 } 82 83 84 85 for(int i = 9; i <= 13; i++){ 86 digitalWrite(i,HIGH); 87 } 88 delay(500); 89 90 for(int i = 9; i <= 13; i++){ 91 digitalWrite(i,LOW); 92 } 93 94 95} 96 97void pat5(){ 98 digitalWrite(4,HIGH); 99 digitalWrite(5,HIGH); 100 digitalWrite(6,HIGH); 101 digitalWrite(11,HIGH); 102 digitalWrite(12,HIGH); 103 digitalWrite(13,HIGH); 104 105 delay(500); 106 107 digitalWrite(4,LOW); 108 digitalWrite(5,LOW); 109 digitalWrite(6,LOW); 110 digitalWrite(11,LOW); 111 digitalWrite(12,LOW); 112 digitalWrite(13,LOW); 113 114 digitalWrite(7,HIGH); 115 digitalWrite(8,HIGH); 116 digitalWrite(9,HIGH); 117 digitalWrite(10,HIGH); 118 119 delay(500); 120 121 digitalWrite(7,LOW); 122 digitalWrite(8,LOW); 123 digitalWrite(9,LOW); 124 digitalWrite(10,LOW); 125} 126void pat6(){ 127 for(int i = 4; i<=13; i=i+2){ 128 digitalWrite(i,HIGH); 129 } 130 131 delay(500); 132 133 for(int i = 4; i<=13; i=i+2){ 134 digitalWrite(i,LOW); 135 } 136 137 138 139 for(int i = 5; i<=13; i=i+2){ 140 digitalWrite(i,HIGH); 141 } 142 143 delay(500); 144 145 for(int i = 5; i<=13; i=i+2){ 146 digitalWrite(i,LOW); 147 } 148} 149void pat7(){ 150 int d = 1; 151 for(int a = 9; a<=13; a++){ 152 digitalWrite(a,HIGH); 153 digitalWrite((a - d),HIGH); 154 delay(t); 155 156 digitalWrite(a,LOW); 157 digitalWrite((a - d),LOW); 158 159 160 d = d + 2; 161 } 162} 163
Arduino LED patterns with Bluetooth
c_cpp
Arduino LED patterns with Bluetooth
1int t = 100; 2int counter = 10; 3int val = 0; 4 5void setup() { 6 for(int i = 4; i <= 13; i++){ 7 pinMode(i,OUTPUT); 8 } 9 Serial.begin(9600); 10} 11 12void loop() { 13 if(Serial.available()){ 14 val = Serial.read(); 15 Serial.println(val,DEC); 16 } 17 if(val == '1'){ 18 pat1(); 19 } 20 else if(val == '2'){ 21 pat2(); 22 } 23 else if(val == '3'){ 24 pat3(); 25 } 26 else if(val == '4'){ 27 pat4(); 28 } 29 else if(val == '5'){ 30 pat5(); 31 } 32 else if(val == '6'){ 33 pat6(); 34 } 35 else if(val == '7'){ 36 pat7(); 37 } 38} 39 40void pat1(){ 41 for(int i = 4; i <= 13; i++){ 42 digitalWrite(i,HIGH); 43 delay(t); 44 digitalWrite(i,LOW); 45 } 46 for(int i = 12; i >= 4; i--){ 47 digitalWrite(i,HIGH); 48 delay(t); 49 digitalWrite(i,LOW); 50 } 51} 52void pat2(){ 53 for(int i = 4; i<=13; i=i+2){ 54 digitalWrite(i,HIGH); 55 delay(t); 56 digitalWrite(i,LOW); 57 } 58 for(int i = 12; i>=4; i=i-2){ 59 digitalWrite(i,HIGH); 60 delay(t); 61 digitalWrite(i,LOW); 62 } 63} 64void pat3(){ 65 for(int i = 4; i <= 13; i++){ 66 digitalWrite(i,HIGH); 67 delay(t); 68 } 69 for(int i = 13; i >= 4; i--){ 70 digitalWrite(i,LOW); 71 delay(t); 72 } 73} 74void pat4(){ 75 for(int i = 4; i <= 8; i++){ 76 digitalWrite(i,HIGH); 77 } 78 delay(500); 79 for(int i = 4; i <= 8; i++){ 80 digitalWrite(i,LOW); 81 } 82 83 84 85 for(int i = 9; i <= 13; i++){ 86 digitalWrite(i,HIGH); 87 } 88 delay(500); 89 90 for(int i = 9; i <= 13; i++){ 91 digitalWrite(i,LOW); 92 } 93 94 95} 96 97void pat5(){ 98 digitalWrite(4,HIGH); 99 digitalWrite(5,HIGH); 100 digitalWrite(6,HIGH); 101 digitalWrite(11,HIGH); 102 digitalWrite(12,HIGH); 103 digitalWrite(13,HIGH); 104 105 delay(500); 106 107 digitalWrite(4,LOW); 108 digitalWrite(5,LOW); 109 digitalWrite(6,LOW); 110 digitalWrite(11,LOW); 111 digitalWrite(12,LOW); 112 digitalWrite(13,LOW); 113 114 digitalWrite(7,HIGH); 115 digitalWrite(8,HIGH); 116 digitalWrite(9,HIGH); 117 digitalWrite(10,HIGH); 118 119 delay(500); 120 121 digitalWrite(7,LOW); 122 digitalWrite(8,LOW); 123 digitalWrite(9,LOW); 124 digitalWrite(10,LOW); 125} 126void pat6(){ 127 for(int i = 4; i<=13; i=i+2){ 128 digitalWrite(i,HIGH); 129 } 130 131 delay(500); 132 133 for(int i = 4; i<=13; i=i+2){ 134 digitalWrite(i,LOW); 135 } 136 137 138 139 for(int i = 5; i<=13; i=i+2){ 140 digitalWrite(i,HIGH); 141 } 142 143 delay(500); 144 145 for(int i = 5; i<=13; i=i+2){ 146 digitalWrite(i,LOW); 147 } 148} 149void pat7(){ 150 int d = 1; 151 for(int a = 9; a<=13; a++){ 152 digitalWrite(a,HIGH); 153 digitalWrite((a - d),HIGH); 154 delay(t); 155 156 digitalWrite(a,LOW); 157 digitalWrite((a - d),LOW); 158 159 160 d = d + 2; 161 } 162} 163
Downloadable files
Arduino LED patterns with Bluetooth
Arduino LED patterns with Bluetooth
Arduino LED patterns with Bluetooth
Comments
Only logged in users can leave comments