Make the code run without a connection to usb

Hello :smiley: I have problems making my code function when the Arduino is connected to a external powersupply. Have been troubleshooting for a while now and after a lot of testing I have concluded that there is something in my code that only allows it to work when it is connected with usb. In short im setting up a peripheral that need to work without a usb connection. I have done testing with simpler code (make a LED blink etc) and in that case the arduino works, so i dont think it is the powersupply that is the problem (which is 5 v). please help :smiley:

#include <ArduinoBLE.h>
int ledPin = 2;
int testPin = 3;
char* deviceServiceUuid = "19B10010-E8F2-537E-4F6C-D104768A1214";
char* deviceServiceCharacteristicUuid = "19B10011-E8F2-537E-4F6C-D104768A1214";

BLEService ledService(deviceServiceUuid);
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic ledCharacteristic(deviceServiceCharacteristicUuid, BLERead | BLEWrite);


void setup() {
  
  pinMode(ledPin, OUTPUT);
  pinMode(testPin, OUTPUT);
  BLE.begin();
  
   // set the local name peripheral advertises
  BLE.setLocalName("LED");
  // set the UUID for the service this peripheral advertises:
  BLE.setAdvertisedService(ledService);
  // add the characteristics to the service
  ledService.addCharacteristic(ledCharacteristic);
  // add the service
  BLE.addService(ledService);
  ledCharacteristic.writeValue(0);
  // start advertising
  BLE.advertise();
  
}

void loop() {
  digitalWrite(testPin,HIGH);
  BLE.poll();
  
  char ledValue = digitalRead(ledPin);
  
    if (ledCharacteristic.written()) {
    // update LED, either central has written to characteristic or button state has changed
      if (ledCharacteristic.value()) {
        
        digitalWrite(ledPin, HIGH);
      } 
      else {
      
      digitalWrite(ledPin, LOW);
      }
    }
}

The power supply is very likely a problem. The Bluetooth transmitter requires a lot of current.

Please post a photo of a hand drawn wiring diagram, and the details of the power supply. Identify the Arduino, as well.

The powersupply is set to 5V.
image

image

The arduino is a MKR wifi 1010
Here i included a drawing of the wiring:
image

Please post a legible drawing.

There is nothing in the code that requires a USB connection.

Is this better ? I could not find a arduino mkr wifi 1010 in the drawing app, so i just used a normal Nano for illustrative purposes.

So it was a powerproblem, I had to apply 5.5 voltage for the device to be stable.

No. Not solved. Vin specification is 7V or greater. Read the specs on the Arduino website, or in literally hundreds of threads here on the forum.
Now, it's solved. Please move the solution check.

You might also have the current limit on the power supply set to minimum. But I can't see it in the postage stamp sized image you posted...

Nope.
https://docs.arduino.cc/hardware/mkr-wifi-1010

Input Voltage (nominal) 5-7V

Incorrect diagrams cause confusion.

Still waiting for an answer to my question.

Question asked by @mjfagerh and solution was also given my @mjfagerh
So why it has been created

@mjfagerh asked a question, got answers, and solved the problem. That seems normal to me. What does your post mean?

Does it not say 5 V ? Arduino MKR WiFi 1010 — Arduino Online Shop
at board power supply

Post a sketch with a Nano, get an answer for a Nano. Sorry.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.