http://makezine.com/2009/05/15/making-the-arduino-emf-detector/
Components Required:
(1) LED BAR (You can also use LEDs instead)
(2) 10 resistors (220 - 330 ohm)
(3) ONE 3.3M ohm resistor (Or, use multiple resister to make them equivalent to 3.3M ohm)
(4) Wires!
(5) Probe (basically, a wire)
SCHEMATIC:
Here, I just used an Android Nano instead of Arduino Uno. And, also used three- 1M resistors and one- 220 ohm resistor instead of using one- 3.3M resistor. (You can use what ever you want!) |
CODE: (by Collin Cunningham)
// EMF Detector for LED Bargraph v1.0
// 5.12.2009
// original code/project by Aaron ALAI - aaronalai1@gmail.com
// modified for use w/ LED bargraph by Collin Cunningham
// collin@makezine.com
#define NUMREADINGS 15
void setup();
void loop();
int senseLimit = 15;
int probePin = 5;
int val = 0;
int LED1 = 11;
int LED2 = 10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;
int LED7 = 5;
int LED8 = 4;
int LED9 = 3;
int LED10 = 2;
int readings[NUMREADINGS];
int index = 0;
int total = 0;
int average = 0;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0;
}
void loop() {
val = analogRead(probePin);
if(val >= 1){
val = constrain(val, 1, senseLimit);
val = map(val, 1, senseLimit, 1, 1023);
total -= readings[index];
readings[index] = val;
total += readings[index];
index = (index + 1);
if (index >= NUMREADINGS)
index = 0;
average = total / NUMREADINGS;
if (average > 50){
digitalWrite(LED1, HIGH);
}
else{
digitalWrite(LED1, LOW);
}
if (average > 150){
digitalWrite(LED2, HIGH);
}
else{
digitalWrite(LED2, LOW);
}
if (average > 250){
digitalWrite(LED3, HIGH);
}
else{
digitalWrite(LED3, LOW);
}
if (average > 350){
digitalWrite(LED4, HIGH);
}
else{
digitalWrite(LED4, LOW);
}
if (average > 450){
digitalWrite(LED5, HIGH);
}
else{
digitalWrite(LED5, LOW);
}
if (average > 550){
digitalWrite(LED6, HIGH);
}
else{
digitalWrite(LED6, LOW);
}
if (average > 650){
digitalWrite(LED7, HIGH);
}
else{
digitalWrite(LED7, LOW);
}
if (average > 750){
digitalWrite(LED8, HIGH);
}
else{
digitalWrite(LED8, LOW);
}
if (average > 850){
digitalWrite(LED9, HIGH);
}
else{
digitalWrite(LED9, LOW);
}
if (average > 950){
digitalWrite(LED10, HIGH);
}
else{
digitalWrite(LED10, LOW);
}
Serial.println(val);
}
}
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
The code you posted here doesn't set pin 4-7 as an output. Not sure if you did that intentionally.
ReplyDelete