unstable vibration sensor with arduino FIO

hi guys,

i'm working on a project which required to have vibration sensor with arduino with Xbee module installed on it to send the vibration data it's quite simple but the problems happens when i connect arduino FIO with external 6 volts usb supply
i found that the vibration sensor is giving me voltage as if there is a vibration
i don't know why this happens but when i tried the battery only it works fine
when i try the supply from my PC by using usb cable to connect from my PC usb to the arduino no problem also

i checked the design of the FIO i found that the external power supply won't affect the arduino FIO board as it's working on 3.3 volts and it pass through regulator and many capacitors for smoothing the voltage

the Hardware design was very simple
the Positive pin of the sensor connect to pin 1
the negative to the ground
1 mega ohm resistor in parallel with the two pins of the vibration sensor

i need your help please
here is my code it may be something wrong on it

//arduino node ID 
#define ID 10
///////////Vibration sensor//////////////////////
// these constants won't change:
const int knockSensor = 1;  // the piezo is connected to analog pin 1
unsigned long threshold = 475;  // threshold value to decide when the detected sound is a knock or not
//////////////////////////////////////////////////


void setup() {

   Serial.begin(9600);
   digitalWrite(vcc, HIGH);   // sets the vcc on
   analogReference(INTERNAL) ;


}


void loop() {

//check vibration sensor
vibration() ;

}

void vibration()
{
  unsigned long sensorReading = 0 ;
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(knockSensor);

      // if the sensor reading is greater than the threshold:
      if (sensorReading >= threshold)
      {

      Serial.print(ID);Serial.print(",UP,");
       // send the string "Knock!" back to the computer, followed by newline
      Serial.print("glass=knock.");
      Serial.print(sensorReading);
      Serial.println(";");
       delay(2);
}

so i need to make some calibration ???
do i need to change the 1 meag ohm

any help would be appreciated

i was using this sensor

What does this do?
digitalWrite(vcc, HIGH);
Can't find vcc referenced in your code so you are not posting all of it.

If it works on batteries and it works on USB connections but not on your USB external 6 volts usb supply, then it is this supply or the wiring of it that is faulty.
Have you connected the ground?

i found that the external power supply won't affect the arduino FIO board as it's working on 3.3 volts and it pass through regulator and many capacitors for smoothing the voltage

No that is only what you think it is not reality. Have you measured the ripple of your supply on an oscilloscope? The ripple you are looking for will be small possibly as small as the phantom voltage you are seeing.

this was for another temperature sensor sht1x

   digitalWrite(vcc, HIGH);   // sets the vcc on

so as what i understand from your post that the problem is in the supply voltage because it may have ripples which makes the ADC in the arduino unstable
but i tried many types of power supplies and all have the same result

but i tried many types of power supplies and all have the same result

No you said it works with the USB cable supplying power and with the battery supplying power. If it works with those two then you problem HAS to be the power supply you are using, either in how it is being regulated or how you wire it up.

When you say:-

with external 6 volts usb supply

How is this wired in? Is it through a regulator? If not 6V is too high for the chip and that is why you are having problems.

How is this wired in? Is it through a regulator?

it's regulated and i took this power supply from D-link router to be sure it's regulated very well :frowning:

i will try yo get variable power supply like this one and try 3.5 , 5 , and 5 volts with the FIO

That sort of PSU is not regulated very well. If you measure it the voltage taps are only approximate and the actual voltage varies with load. If you are putting your 6V PSU through a regulator to get 5V then it will not work as you have not enough excess voltage to allow the regulator to work. You need to use about 7V minimum to get a 5V regulator to work.