1
2
3
4int sensorPin = A0;
5int resistorPin = A1;
6
7byte relay = 3;
8byte led1 = 4;
9byte led2 = 5;
10byte led3 = 6;
11byte led4 = 7;
12byte led5 = 8;
13byte led6 = 9;
14byte led7 = 10;
15byte led8 = 11;
16byte led9 = 12;
17byte led10 = 13;
18char ledbar[10] {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10};
19int sensorValue = 0;
20int resistValue = 0;
21unsigned long currentMillis;
22long interval = 1000;
23long previousMillis = 0;
24
25void setup() {
26 for (int z = 0; z < 10; z = z + 1) {
27 pinMode(ledbar[z], OUTPUT);
28 }
29 pinMode(relay, OUTPUT);
30 pinMode(sensorPin, INPUT);
31 pinMode(resistorPin, INPUT);
32 Serial.begin(9600);
33
34}
35
36void ledson(byte x) {
37
38 for (int z = 0; z < x; z = z + 1) {
39 digitalWrite(ledbar[z], HIGH);
40 }
41}
42
43void ledbar1() {
44
45 resistValue = analogRead(resistorPin);
46 resistValue = map(resistValue, 0, 1023, 0, 400);
47
48 AlleLedsUit ();
49 if (resistValue > 0 & resistValue <= 40)
50 {
51 ledson(1);
52 }
53 else if (resistValue > 40 & resistValue <= 80)
54 {
55 ledson(2);
56 }
57 else if (resistValue > 80 & resistValue <= 120)
58 {
59 ledson(3);
60 }
61 else if (resistValue > 120 & resistValue <= 160)
62 {
63 ledson(4);
64 }
65 else if (resistValue > 160 & resistValue <= 200)
66 {
67 ledson(5);
68 }
69 else if (resistValue > 200 & resistValue <= 240)
70 {
71 ledson(6);
72 }
73 else if (resistValue > 240 & resistValue <= 280)
74 {
75 ledson(7);
76 }
77 else if (resistValue > 280 & resistValue <= 320)
78 {
79 ledson(8);
80 }
81 else if (resistValue > 320 & resistValue <= 360)
82 {
83 ledson(9);
84 }
85 else if (resistValue > 360 )
86 {
87 ledson(10);
88 }
89
90
91}
92
93void loop() {
94
95 sensorValue = analogRead(sensorPin);
96 sensorValue = map(sensorValue, 0, 1023, 0, 1000);
97
98 if (sensorValue < 500)
99 {
100 delay(resistValue);
101 digitalWrite(relay, HIGH);
102 delay(750);
103 digitalWrite(relay, LOW);
104 }
105
106 currentMillis = millis();
107 if (currentMillis - previousMillis > interval)
108 {
109 previousMillis = currentMillis;
110
111 ledbar1();
112
113 }
114}
115
116void AlleLedsUit () {
117 for (int z = 0; z < 10; z = z + 1) {
118 digitalWrite(ledbar[z], LOW);
119 }
120
121}
122