Tu przykład działania takiego kabelka podpiętego do pinu analogowego w Arduino (czyli atmedzie) i efekty
od kabla ładującego telefon. Zrobiłem taką zabawkę aby sprawdzić co mi zakłóca urządzenia.
Możesz wgrać do swojego arduino taki kod:
Kod: Zaznacz cały
// EMF Detector for LED Bargraph v1.0
// 5.12.2009
// original code/project by Aaron ALAI - [email protected]
// modified for use w/ LED bargraph by Collin Cunningham - [email protected]
// modified for use buzzer signalization by Tomasz Bartuś
// http://home.agh.edu.pl/~bartus/index.php?action=efekty&subaction=arduino&item=28
#define NUMREADINGS 15 // raise this number to increase data smoothing
int senseLimit = 15; // raise this number to decrease sensitivity (up to 1023 max)
int probePin = 5; // analog 5
int val = 0; // reading from probePin
// variables for smoothing
int readings[NUMREADINGS]; // the readings from the analog input
int inde = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // final average of the probe reading
void setup() {
Serial.begin(9600); // initiate serial connection for debugging/etc
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}
void loop() {
val = analogRead(probePin); // take a reading from the probe
if(val >= 1){ // if the reading isn't zero, proceed
val = constrain(val, 1, senseLimit); // turn any reading higher than the senseLimit value into the senseLimit value
val = map(val, 1, senseLimit, 1, 1023); // remap the constrained value within a 1 to 1023 range
total -= readings[inde]; // subtract the last reading
readings[inde] = val; // read from the sensor
total += readings[inde]; // add the reading to the total
inde = (inde + 1); // advance to the next index
if (inde >= NUMREADINGS){ // if we're at the end of the array...
inde = 0; // ...wrap around to the beginning
}
average = total / NUMREADINGS; // calculate the average
Serial.println(val); // use output to aid in calibrating
}
}