Components and supplies
Resistor 1M ohm
ATtiny24A
3 mm LED: Red
Resistor 221 ohm
Tools and machines
Soldering iron (generic)
Project description
Code
Arduino Code of this project
arduino
1// EMF Detector Attiny85 and 4 led v1.0// 23.10.2015// original code/project by Aaron ALAI - aaronalai1@gmail.com// modified for use by Patryk Bedkowski - bedkowskisite@gmail.com 2 3#define NUMREADINGS 15 // Number of readings 4int senseLimit = 16; // Raise this num to decrease sensitivity 5int val = 0; 6int antenna = A7; 7int LED[] = {0,1,2,3,4,5,6}; // After verify the position of red green and yellow leds 8// Variables for smoothing 9int readings[NUMREADINGS]; 10int index = 0; 11int total = 0; 12int averange = 0; 13void setup() { 14 for(int i=0;i<7;i++){ 15 pinMode(i, OUTPUT); 16 } 17pinMode(antenna, INPUT); 18// Test leds on start 19for (int i=0; i<7; i++) { 20digitalWrite(LED[i],HIGH); 21delay(250); 22} 23for (int i=0; i<7; i++) { 24digitalWrite(LED[i],LOW); 25} 26// Initialize all the readings 27for (int i = 0; i < NUMREADINGS; i++) { 28readings[i] = 0; 29} 30} 31void loop() { 32int val = analogRead(antenna); 33if(val >= 1){ 34val = constrain(val, 1, senseLimit); // turn any readings higher than the senseLimit into the senseLmit 35val = map(val, 1, senseLimit, 1, 1023); // remap the values 36total -= readings[index]; // subtract the last reading 37readings[index] = val; // read from the sensor 38total+= readings[index]; // add the reading to the total 39index = (index + 1); // advance to the next index 40if (index >= NUMREADINGS)index = 0; 41averange = total / NUMREADINGS; 42 43if (averange > 380) { 44digitalWrite(0,HIGH);} 45else{digitalWrite(0,LOW);} 46 47if (averange > 480){ 48digitalWrite(1,HIGH);} 49else{digitalWrite(1,LOW);} 50 51if (averange > 580){ 52digitalWrite(2,HIGH);} 53else{digitalWrite(2,LOW);} 54 55if (averange > 680){ 56digitalWrite(3,HIGH);} 57else{digitalWrite(3,LOW);} 58 59if (averange > 780){ 60digitalWrite(4,HIGH);} 61else{digitalWrite(4,LOW);} 62 63if (averange > 830) { 64digitalWrite(5,HIGH);} 65else {digitalWrite(5,LOW);} 66 67if (averange > 900) { 68digitalWrite(6,HIGH);} 69else {digitalWrite(6,LOW);} 70}}
Arduino Code of this project
arduino
1// EMF Detector Attiny85 and 4 led v1.0// 23.10.2015// original code/project by Aaron ALAI - aaronalai1@gmail.com// modified for use by Patryk Bedkowski - bedkowskisite@gmail.com 2 3#define NUMREADINGS 15 // Number of readings 4int senseLimit = 16; // Raise this num to decrease sensitivity 5int val = 0; 6int antenna = A7; 7int LED[] = {0,1,2,3,4,5,6}; // After verify the position of red green and yellow leds 8// Variables for smoothing 9int readings[NUMREADINGS]; 10int index = 0; 11int total = 0; 12int averange = 0; 13void setup() { 14 for(int i=0;i<7;i++){ 15 pinMode(i, OUTPUT); 16 } 17pinMode(antenna, INPUT); 18// Test leds on start 19for (int i=0; i<7; i++) { 20digitalWrite(LED[i],HIGH); 21delay(250); 22} 23for (int i=0; i<7; i++) { 24digitalWrite(LED[i],LOW); 25} 26// Initialize all the readings 27for (int i = 0; i < NUMREADINGS; i++) { 28readings[i] = 0; 29} 30} 31void loop() { 32int val = analogRead(antenna); 33if(val >= 1){ 34val = constrain(val, 1, senseLimit); // turn any readings higher than the senseLimit into the senseLmit 35val = map(val, 1, senseLimit, 1, 1023); // remap the values 36total -= readings[index]; // subtract the last reading 37readings[index] = val; // read from the sensor 38total+= readings[index]; // add the reading to the total 39index = (index + 1); // advance to the next index 40if (index >= NUMREADINGS)index = 0; 41averange = total / NUMREADINGS; 42 43if (averange > 380) { 44digitalWrite(0,HIGH);} 45else{digitalWrite(0,LOW);} 46 47if (averange > 480){ 48digitalWrite(1,HIGH);} 49else{digitalWrite(1,LOW);} 50 51if (averange > 580){ 52digitalWrite(2,HIGH);} 53else{digitalWrite(2,LOW);} 54 55if (averange > 680){ 56digitalWrite(3,HIGH);} 57else{digitalWrite(3,LOW);} 58 59if (averange > 780){ 60digitalWrite(4,HIGH);} 61else{digitalWrite(4,LOW);} 62 63if (averange > 830) { 64digitalWrite(5,HIGH);} 65else {digitalWrite(5,LOW);} 66 67if (averange > 900) { 68digitalWrite(6,HIGH);} 69else {digitalWrite(6,LOW);} 70}}
Downloadable files
Connections
I didn't want to use fritzing program because of lacks of elements.
Connections
Comments
Only logged in users can leave comments
EMF Detector Using ATtiny24A-PU | Arduino Project Hub