Advertisement
Guest User

emf165

a guest
Jan 22nd, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. // EMF Detector for LED Bargraph v1.0
  2. // 5.12.2009
  3. // original code/project by Aaron ALAI - aaronalai1@gmail.com
  4. // modified for use w/ LED bargraph by Collin Cunningham - collin@makezine.com
  5. // remodified an reanrangede for Project BlackKitty by Ed Nielsen - ed@darkgeej.dk 2017
  6.  
  7. #define NUMREADINGS 15 // raise this number to increase data smoothing
  8.  
  9. int senseLimit = 6; // raise this number to decrease sensitivity (up to 1023 max)
  10. int probePin = 0; // analog 0
  11. int val = 0; // reading from probePin
  12.  
  13. int LED1 = 2; //
  14. int LED2 = 3; // series
  15. int LED3 = 4; // in
  16. int LED4 = 5; // resistors
  17. int LED5 = 6; // with
  18. int LED6 = 7; // anodes
  19. int LED7 = 8; // bargraph
  20. int LED8 = 9; // LED
  21. int LED9 = 10; // to
  22. int LED10 = 11; // connections
  23.  
  24. // variables for smoothing
  25.  
  26. int readings[NUMREADINGS]; // the readings from the analog input
  27. int index = 0; // the index of the current reading
  28. int total = 0; // the running total
  29. int average = 0; // final average of the probe reading
  30.  
  31.  
  32. void setup() {
  33.  
  34. // set pins
  35. pinMode(2, OUTPUT); // specify LED bargraph outputs
  36. pinMode(3, OUTPUT);
  37. pinMode(4, OUTPUT);
  38. pinMode(5, OUTPUT);
  39. pinMode(6, OUTPUT);
  40. pinMode(7, OUTPUT);
  41. pinMode(8, OUTPUT);
  42. pinMode(9, OUTPUT);
  43. pinMode(10, OUTPUT);
  44. pinMode(11, OUTPUT);
  45.  
  46. // set serial
  47. Serial.begin(9600); // initiate serial connection for debugging/etc
  48.  
  49. for (int i = 0; i < NUMREADINGS; i++)
  50. readings[i] = 0; // initialize all the readings to
  51.  
  52. }
  53.  
  54. void loop(){
  55.  
  56. // Set values for sensors
  57. int S1 = 70;
  58. int S2 = 60;
  59. int S3 = 55;
  60. int S4 = 50;
  61. int S5 = 45;
  62. int S6 = 40;
  63. int S7 = 35;
  64. int S8 = 25;
  65. int S9 = 10;
  66. int S10 = 5;
  67.  
  68. // Set inputs
  69. val = analogRead(probePin); // take a reading from the probe
  70.  
  71.  
  72. // Doing the math
  73. if(val >= 1){ // if the reading isn't zero, proceed
  74.  
  75. val = constrain(val, 1, senseLimit); // turn any reading higher than the senseLimit value into the senseLimit value
  76. val = map(val, 1, senseLimit, 1, 1023); // remap the constrained value within a 1 to 1023 range
  77.  
  78. total -= readings[index]; // subtract the last reading
  79. readings[index] = val; // read from the sensor
  80. total += readings[index]; // add the reading to the total
  81. index = (index + 1); // advance to the next index
  82.  
  83. if (index >= NUMREADINGS) // if we're at the end of the array...
  84. index = 0; // ...wrap around to the beginning
  85.  
  86. average = total / NUMREADINGS; // calculate the average
  87.  
  88. // Tellings leds to be on or off
  89.  
  90. if (average > S10){ // if the average is over 50 ...
  91. digitalWrite(LED10, HIGH); // light the first LED
  92. }
  93. else{ // and if it's not ...
  94. digitalWrite(LED10, LOW); // turn that LED off
  95. }
  96.  
  97. if (average > S9){ // and so on ...
  98. digitalWrite(LED9, HIGH);
  99. }
  100. else{
  101. digitalWrite(LED9, LOW);
  102. }
  103.  
  104. if (average > S8){
  105. digitalWrite(LED8, HIGH);
  106. }
  107. else{
  108. digitalWrite(LED8, LOW);
  109. }
  110.  
  111. if (average > S7){
  112. digitalWrite(LED7, HIGH);
  113. }
  114. else{
  115. digitalWrite(LED7, LOW);
  116. }
  117.  
  118. if (average > S6){
  119. digitalWrite(LED6, HIGH);
  120. }
  121. else{
  122. digitalWrite(LED6, LOW);
  123. }
  124.  
  125. if (average > S5){
  126. digitalWrite(LED5, HIGH);
  127. }
  128. else{
  129. digitalWrite(LED5, LOW);
  130. }
  131.  
  132. if (average > S4){
  133. digitalWrite(LED4, HIGH);
  134. }
  135. else{
  136. digitalWrite(LED4, LOW);
  137. }
  138.  
  139. if (average > S3){
  140. digitalWrite(LED3, HIGH);
  141. }
  142. else{
  143. digitalWrite(LED3, LOW);
  144. }
  145.  
  146. if (average > S2){
  147. digitalWrite(LED2, HIGH);
  148. }
  149. else{
  150. digitalWrite(LED2, LOW);
  151. }
  152.  
  153. if (average > S1){
  154. digitalWrite(LED1, HIGH);
  155. }
  156. else{
  157. digitalWrite(LED1, LOW);
  158. }
  159.  
  160. Serial.println(val); // use output to aid in calibrating
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement