Arduino Mega 2560 stubbornly offline

I’m very new to this.

The Arduino Mega 2560 is connected to my computer via a USB cable. Connection seems good as I can upload a sketch to successfully blink the LED. However when I try to add the device to the cloud account it is reported as offline. I reset the board via the reset button and by the the brute force method of unplugging power.

In attempting to add the device the board is recognized, but clicking on that device returns the following error message:

“We could not find any Arduino device
The connection was lost. This may happen if the device is off, cable is disconnected, or the device is out of range. (None of these are true)
What you can do:

  • Detach the device from any shield/carrier or external circuitry. (No shield)

  • Reconnect the device to the computer with another USB cable and make sure the power LED lights up. (Tried two different cables. Same problem with each)

  • Reset your device” (Tried this too)

Because of my naivety, I don’t know if this will affect my working with the device as I use it to automate the blast gates in my new workshop, but my OCD tells me this should be working and it will bother me if it doesn’t.

So, if you have ideas, please let me know what I might try.

Thanks in advance.

That a nice part! However, please keep in mind that we are not a free design or code-writing service. We’re more than happy to help with your design or code, but we need you to make an initial attempt. Please design and write your code, then post it along with an explanation of what’s not working properly. There is also a for hire section if you want to pay for it.

I would assume the teacher/professor expects you to learn how to do this and understand what you did. This is basic material and if you do not master this you will have an increasingly difficult time.

  1. Show Your Work First: Before asking for assistance, make an attempt to design or write the code yourself. Share your work along with details about what isn’t working. That includes a preliminary schematic that you drew.

  2. Provide Clear Documentation: Since we can’t see your project, share an annotated schematic (best) or a clear drawing of your setup. Clear Pictures are welcome, but avoid using Fritzing diagrams as they are wiring diagrams, not schematics, and are not ideal for troubleshooting.

  3. Include Technical Details: If there is specific hardware involved, include links to technical information. There are often many versions of similar components, so precise details are essential. Many times the processor is assumed, please state which one and post a link to it.

  4. Reference Resources: For additional help, check out useful links and tutorials: Useful Links on Arduino Forum. Of course one of the better sources of information (in my opinion) is the Arduino Cookbook. Skim it cover to cover and stop on any project that interests you.

Welcome to the forum

You need to give us more details

When you plug the Mega into the PC USB port does the PC create a new COM port ? If so, have you selected the COM port and board in the IDE ?

What messages do you get in the IDE and when do they occur ?

Sorry, I hit return too soon without the full message. Please read my verbose edit.
Yes Com 3 is shown when I try to connect the device. The device and the com port are both detected.

Here’s the code that you asked for. It does compile.

/*
Ted's workshop automation
*/
unsigned long DCtimer; // create DC timer for run time measurement
const unsigned long DCrunTime = 600000; // set runtime limit to 10 mins.
const int DCpin = 16; // choose fixed dust collector pin
const int bGates = 15; // max number of blast gates
int i; // shared read/write pin variable 

void setup(){
  i = 0; // initialize variable
  for(i <= bGates; i++;){ 
    pinMode(i, OUTPUT); // enable output on digitasl BG pins
    digitalWrite(i, LOW); // close all blast gates
    }
    pinMode(DCpin, OUTPUT); // enable output on DC pin
    digitalWrite(DCpin, LOW); // make sure DC is off
    DCtimer = 0; // initialize DC timer 
    Serial.begin(9600);
  }

void loop(){
  i = 0; // initialize variable
  for (i <= bGates; i++;){
    analogRead(i); // look for current flow
    if (i == HIGH){ // current is flowing
      digitalWrite(DCpin, HIGH); // start DC
      DCtimer = millis(); // start DC timer
      digitalWrite(i, HIGH); // open blast gate
    } else if (millis() - DCtimer >= DCrunTime){ // running long enough?
        digitalWrite(DCpin, LOW); // stop DC
        DCtimer = 0; // reset DCtimer 
    } else {
      delay(20000); // allow time for multiple cuts on CMS
      digitalWrite(i, LOW); // close blast gate
    }
  }
}

As for the code that successfully blinks the LED it is here:

/*
Blink LED
 */

int LEDpin = 13; // Pin where the LED is connected
void setup() {
  pinMode(LEDpin, OUTPUT); // Set the LED pin as an output
}
void loop() {
  digitalWrite(LEDpin, HIGH); // Turn the LED on
  delay(1000); // Wait for one second
  digitalWrite(LEDpin, LOW); // Turn the LED off
  delay(1000); // Wait for one second
}

Hi @dyckbook

The reason for this is that the Mega 2560 is not supported for use as an Arduino Cloud IoT Device. The reason it is not supported is because IoT devices must have an Internet communication capability, and this board does not have such a capability.

You can learn which boards are supported for use as IoT Devices from this section of the Arduino Cloud documentation:

https://docs.arduino.cc/arduino-cloud/guides/overview/#compatible-boards


Please note that, although you can't use it with the IoT component of the Arduino Cloud platform, you can use the Arduino Cloud Editor component to create, compile, and upload any non-IoT sketches with the Mega 2560 board:

https://docs.arduino.cc/arduino-cloud/guides/cloud-editor/

So as long as your blast gates project doesn't require the use of Arduino Cloud IoT, you won't have any problems. I can see from your sketch code that it doesn't, so you are all set!

Thank you so much for that comprehensive reply. I thought it might be something that I was doing.

Does that mean that I won't be able to communicate with the serial monitor? I was hoping to be able to use that to debug the code.

Ted

Your Arduino program will use Serial.print() and Serial.read() to communicate with the serial monitor.

The program you posted does not use those function calls. Serial.begin() is already present in the code, but the capability is unused.

There are plenty of examples in the Arduino IDE and on line.

No. You can use Serial Monitor all you like.

If you want to understand exactly what it is you are not able to use your Mega 2560 for, read this introduction to the optional Arduino Cloud IoT features:

https://docs.arduino.cc/arduino-cloud/guides/overview/

Alternatively, you can stop being sidetracked by all this completely irrelevant stuff and get back to progressing on your project.

Yes it's there in anticipation of using it to debug the program.