emf detector
Max Krekeler and Giancarlo Ciavaglia
We built an EMF (Electromagnetic Field) detector. When the copper wire at the end touches an object using electricity, the arduino gets told to turn on the LEDs on the breadboard depending on how strong the current is.
The Code:
int inPin = 5; // analog 5
int val = 0; // where to store info from analog 5
int pin9= 9;
int pin10 = 10;
int pin11 = 11; // output of red led
int pin12 = 12;
int pin13 = 13;
void setup() {
Serial.begin(9600);
for(int pin = 9; pin < 13; pin++)
{
pinMode(pin,OUTPUT);
}
}
void loop() {
val = analogRead(inPin); // reads in the values from analog 5 and
//assigns them to val
if(val >= 1){
val = constrain(val, 0, 100); // mess with these values
if(val > 0 && val <= 20)
{
digitalWrite(pin13,HIGH);
}
else if(val >= 21 && val <= 40)
{
digitalWrite(pin13,HIGH);
digitalWrite(pin12,HIGH);
}
else if(val >= 41 && val <= 60)
{
digitalWrite(pin13,HIGH);
digitalWrite(pin12,HIGH);
digitalWrite(pin11,HIGH);
}
else if(val >= 61 && val <= 80)
{
digitalWrite(pin13,HIGH);
digitalWrite(pin12,HIGH);
digitalWrite(pin11,HIGH);
digitalWrite(pin10,HIGH);
}
else if(val >= 81 && val <=100)
{
digitalWrite(pin13,HIGH);
digitalWrite(pin12,HIGH);
digitalWrite(pin11,HIGH);
digitalWrite(pin10,HIGH);
digitalWrite(pin9,HIGH);
}
}else{
for(int pin = 9; pin < 13; pin++)
{
digitalWrite(pin,LOW);
}
}
Serial.println(val);
}
The only problem we encountered while doing this project was trying to add a push button to turn the whole device off. However the only thing it did was turn on all of the lights and not turn on until the button was pressed again, not to mention it wouldn't turn off. We overcame this by getting rid of it. Now it works like we want it to.
If I had more money I would add a screen and get a protective shell for it to make it look better and be more portable.