Switching from USB power to Vinn cause troubles...

Hello, first sorry for my bad english...

I have an Arduino Mega 2560 and Arduino Software 1.0.1.

I wrote a simple program wich make the LED on pin 13 blink at differents speeds depending on the value read by an accelerometer connect on analog pin A0. I also read the accelerometer value on the Serial Monitor for double checking.

When I'm readding it, from the USB cable, it works fine, and so the arduino is powered by the USB. Then when I unplug the USB and plug an external 5V batterie on VInn(comming throught en ESC's BEC from a 11.1V LI-PO), the board is well powered, but the LED stop changing the blink speed. Of course I removed the Serial.begin(9600) so that is doesn't wait for the connexion and cause troubles... but the problem is that the card doesn't react the same way when powered by USB or VInn... I'm lost...

Here is my program if that could help somebody...

//Constante
const int CAPTEUR_PIN = 0;

int capteur;

void setup(){
  //Serial.begin(9600);  -- When USB pluged only
  pinMode(13,OUTPUT);
}

void loop(){
  
  capteur = analogRead(CAPTEUR_PIN);
  //Serial.println(capteur);  -- When USB pluged only
  if((capteur > 325 && capteur < 335)){
    digitalWrite(13,HIGH);
    delay(500);
    digitalWrite(13,LOW);
    delay(500);
  }
  else{
    digitalWrite(13,HIGH);
    delay(100);
    digitalWrite(13,LOW);
    delay(100); 
  }

}

I have made some test, and it seems that when Im powering the Arduino from VInn, Analog pin doesn't work anymore. With my voltmeter, I still got voltage changing at the accelerometer's output, but it seems that it is not read anymore by arduino...I'm lost !

Thanks !

but the problem is that the card doesn't react the same way when powered by USB or VInn... I'm lost...

The voltage you apply to Vin must be in the range of 7.5 to 12 vdc, not 5vdc. You can however wire a regulated +5vdc (say from your ESC's BEC output) to the arduino 5V shield pin.

Lefty

Oh that's right :cold_sweat:
I tried to connect the BEC to the 5V input but it did the same thing... I'll try to put in serie 2 BEC so I can get 10V and put it in the Vin to see if it works.

I also discovered something else. Actually, when connected on USB, the analogPin read the value 330, but when switching to Vin, it reads 400, like if voltage was raising up. But it didn't raise, I've checked with my multimeter : 1.6V so a 330 value is ok, but not 400...

The analog read gives a value that is dependant on the analog reference which is usually your supply voltage. When powered by external voltage, it will be very close to 5 volts because of the onboard regulator. When its powered from USB it takes the voltage of the USB in the computer, which from experience can be a long way out. (4.7 volts isn't unusual) so the value read will change.

Yes but I should read 1.66V so it should be 340. That's why USB seems good and the external power not...

I just tried to power via Vin with 7.4V, and it didn't work. So I tried with much voltage, 11.1, and this time it works ! I just found this weird that it didn't work with 7.4V... Anyway, it seems to work fine with 11.1V coming directly from the LI-PO and not the 5V from ESC's BEC. I hope this is going to continue working !

Thanks !