This concerns my Arduino's analogRead while using USB power. I have created an EMF detector using 10 LEDs controlled by a 74HC595 Shift Register. When I use a 9V battery to power the Arduino Uno, and touch the probe wire with my finger, 1 LED lights up (about 10 ADC). ADC is the value returned by analogRead. When I put it near a TV, 8-10 LEDS light up (80-100 ADC). These are reasonable results. When I power the Arduino with a USB to a desktop, and touch the wire with my finger, all the LEDs light up! The serial monitor says that the ADC is about 300! I disconnected it from the computer, hooked up the battery, and the results are back to normal. I don't suspect that any connections are incorrect. I am using the internal 1.1V analog reference. Could it be that the computer doesn't supply enough power to make the reference a full 1.1V? Please help!
Circuit: 74HC595 data to pin 2, clock to pin 3, latch to pin 4. 8 LEDs connected to Q0 - Q7 on the 74HC595, 1 LED to pin 5, 1 LED to pin 6. A bare copper wire to A0, two 1.8M resistors (total of 3.6M) in series from A0 to GND.
This is my code (it's a bit confusing for other people to read). It takes the ADC from A0, and turns on a number of LEDs depending on the range of the ADC (e.g. 1 - 10 ADC lightd up 1 LED, 11 - 20 ADC lights up 2 LEDs).
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
int data = 2;
int clock = 3;
int latch = 4;
void setup(){
Serial.begin(9600);
analogReference(INTERNAL);
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
DDRD = 0x7c;
}
byte reader[] = {
0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff};
boolean state1[]= {
0,0,0,0,0,0,0,0,0,1,1};
boolean state2[] = {
0,0,0,0,0,0,0,0,0,0,1};
void loop(){
total= total - readings[index];
readings[index] = analogRead(inputPin);
total= total + readings[index];
index = index + 1;
if (index >= numReadings)
index = 0;
average = total / numReadings;
float reading = average*1.1/1024.0/**100.0*/;
int emf = map(average,0,100,0,10);
updateLEDs(reader[emf]);
digitalWrite(5, state1[emf]);
digitalWrite(6, state2[emf]);
Serial.print(reading);
Serial.print("\t");
Serial.println(average);
}
void updateLEDs(int value){
digitalWrite(latch, LOW); //Pulls the chips latch low
shiftOut(data, clock, LSBFIRST, value); //Shifts out the 8 bits to the shift register
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
}