So I am completely new to Arduino, and figured I would make this project my first, as I will use it a lot. I know I could have bought one cheaper than all I bought for the project, but I love to tinker, and do some coding, plus there is soooo much I can do with Arduino.
My question is this, I know it is as simple as copying the code for the project, pasting it in software, and uploading it, (but what is the fun in that, I will edit it some). I want to know if anyone else has built one and can give me advice on antenna length and sensitivity?
This is the original site I found the meter on, Hyundai Aftermarket
and here is the code;
/*
Copyright 2010 Adam N. Outler Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
//A note on HZ, if you notice meter oscillations on a known steady
// signal increase or decrease hertz by 1. The oscillations are
// caused when the signals are in near-perfect resonance.
float FrequencyToMonitor=59; //hertz
//setup pins
#define ANTENNA 31 //antenna pin
//16 LEDs on 16 different pins
int LEDPin[]={ 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52 } ;
int LEDCount=16; //number of LEDs
//setup initial global values
int LEDCounter=0; //initial value of LEDs to display
int HalfPeriodMicroseconds=0;// initial value of halfwavelength
/*
SETUP defines pins and performs POT(Power On Test) on LEDs
*/
void setup() {
double HalfPeriod=((1/FrequencyToMonitor)*.5); //Half-period in seconds from frequency
HalfPeriodMicroseconds=int(1000000*HalfPeriod); //Convert period seconds to microseconds integer
pinMode(ANTENNA, INPUT); //set antenna pin
for (int Pin=0; Pin < LEDCount; Pin++) { //initialize each LED
pinMode(LEDPin[Pin], OUTPUT);
digitalWrite(LEDPin[Pin], HIGH); //Turn the LED on
delay(50);
digitalWrite(LEDPin[Pin], LOW); //Turn the LED back off
}
swingLEDs(); //perform LED check to verify LED functionality
}
/*
LOOP checks for value of antenna to go high and then low
if change is seen, then 2 LEDs are lit, otherwise total number
of LEDS are decreased. This allows for a magentic effect when
near the field.
*/
void loop(){
int ANTENNAValue=0; //sets and resets ANTENNAValue
int OldANTENNAValue=0; // as well as OldANTENNAValue
for ( int Pass=0; Pass < 4; Pass++ ) {//take 4 readings
ANTENNAValue=digitalRead(ANTENNA); // from the antenna
if ( ( ANTENNAValue == HIGH ) && ( OldANTENNAValue == LOW ) ) {
incrementLED(); //If a change is detected increase twice
incrementLED(); // 4 passes means 3 changes total
} else if ( ( ANTENNAValue == LOW ) && ( OldANTENNAValue == HIGH ) ) {
incrementLED(); // This makes the meter rise by
incrementLED(); // a total factor of 2 and
} else {
decrementLED(); // if there is no change it falls by 1
}
OldANTENNAValue=ANTENNAValue; //Log old value for next pass
delayMicroseconds(HalfPeriodMicroseconds); // half-wave pause before next reading
}
delayMicroseconds(HalfPeriodMicroseconds); //visual delay between reading passes
delayMicroseconds(HalfPeriodMicroseconds); //twice to avoid extremely long numbers
}
/*
FUNCTION swingLEDs tests the LEDs by lighting
them up sequentially. Each LED is brought high
then low twice.
*/
void swingLEDs(){
for (int Pin=0; Pin < LEDCount; Pin++) {
digitalWrite(LEDPin[Pin], HIGH); // instantanious full brightness
}
for (int Pin=0; Pin < LEDCount; Pin++) {
digitalWrite(LEDPin[Pin], LOW); // clear LEDs from left to right
delay(20);
}
for (int Pin=LEDCount; Pin > -1; Pin--) {
digitalWrite(LEDPin[Pin], HIGH); // light LEDs from right to left
delay(20);
}
for (int Pin=LEDCount; Pin > -1; Pin--) {
digitalWrite(LEDPin[Pin], LOW); // clear LEDs from right to left
delay(20);
}
}
/*
FUNCTION incrementLED increases the number
of LEDs lit by 1.
*/
void incrementLED(){
if ( LEDCounter < LEDCount - 1 ){ LEDCounter++;} //if not max increase
digitalWrite(LEDPin[LEDCounter], HIGH); //light new LED
}
/*
FUNCTION decrementLED decreases the number
of LEDs lit by 1.
*/
void decrementLED(){
digitalWrite(LEDPin[LEDCounter], LOW); //turn off current LED
if ( LEDCounter >= 0 ){ LEDCounter-- ;} // if not zero, decrease}
Thank you for your help and advice!