1
\$\begingroup\$

I have the Arduino Mega 2560 and also the Freetronics Ethermega (with the same chipset). My board and code was functioning perfectly until last weekend when it no longer outputs any data from the Serial (via USB). When working it displays the temps from 12 growing rooms and when the temp gets to a certain threshold it pages me (via VB code).

I have confirmed this using 2 Boards (Mega & Freetronics). Yet the Freetronics with the Ethernet displays the output values correctly on a webpage. Also note that the "Serial Monitor" also displays 0.00 as the current temp.

I have put in displays for the sensor value and this is showing a value in the 300's. Typical statement, "Honest I didnt change anything....".

I have removed the Arduino software, installed the latest version and removed the USB driver and re-installed. Funny thing is it recognises both as attached. Com 8 & Com 9 depending on which board is attached. I've also trued using different power supplys.

This is the serial code, the second one is for both serial and Ethernet connection.

#define SENSOR_COUNT 12
const int analog_pins[SENSOR_COUNT] = {0,1,2,3,4,5,6,7,8,9,10,11};

void loop() {
   for(int I=0; I < SENSOR_COUNT; I++){
      int sensorValue = analogRead(analog_pins[I]);
      float voltage;

      // { voltage = ((sensorValue) * (5.0 / 1023.0) - (0.07));}
      //  Look at the Arduino Project - Get the real voltage input usb power supply. 
      //  Check the Arduino Mega has this chipset (book marked in Firefix under Arduino - Real input voltage post
      // Putting a Meter across the 5v pin and Ground I get:-
      //  Jumper on DC In  -  3.77vDC (with both Power and Usb connected)
      //  Jumper on USB    -  4.71vDC (with only Usb connected)
      //  Jumper on DC In  -  1.16vDC (with only Usb and Jumper)
      //  Jumper on DC In Using a steady power supply gives 11.32

      // { voltage = ((sensorValue) * (5.06 / 1023.0));}   
      // { voltage = ((sensorValue) * (3.75 / 1023.0));}   
      // { voltage = ((sensorValue) * (4.24 / 1023.0));} 
      // { voltage = ((sensorValue) * (11.32 / 1023.0));}
      // { voltage = (sensorValue / 1023.0);}

  //Commented out to try and find why were getting 0.00 out of the srial

  //if (voltage < 0){ voltage = 0.00;}

      // Next 4 lines only used for testing

      Serial.print(I);
      Serial.print(" ");
      Serial.print(sensorValue);
      Serial.print(" ");

      Serial.print("Address = ");
      Serial.print(analog_pins[I] +1);
      Serial.print(" ");
      Serial.print(voltage);
      Serial.println();
      delay(1500);  
    }
}`

Second code for Serial and ethernet..

    /*
 Arduino and Ethernet
 */

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {  192,168,1,11 }; // don't forget to change this IP address for your own situation

EthernetServer server(80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  server.begin();
}

float voltage=0;
float sensor=0;

#define SENSOR_COUNT 12
const int analog_pins[SENSOR_COUNT] = {0,1,2,3,4,5,6,7,8,9,10,11};

void loop()
{
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<!DOCTYPE html>");
          client.println("<html>");
          client.println("<head>");
          client.println("<title>Greenhill Mushrooms</title>");
          client.println("<meta http-equiv=\"refresh\" content=\"1\">");
          client.println("</head>");
          client.println("<body>");
          client.println("<h1 align=center>Greenhill Mushrooms</h1>");
          client.println("<h1 align=center>Room Monitoring System</h2>");          
          client.println("</body>");
          client.println("</html>");

        for(int I=0; I < SENSOR_COUNT; I++){
          int sensorValue = analogRead(analog_pins[I]);
          float voltage;

          // { voltage = ((sensorValue) * (5.0 / 1023.0) - (0.07));}
          { voltage = ((sensorValue) * (5.0 / 1023.0));}
          if (voltage < 0){ voltage = 0.00;}

          voltage = voltage * 10;

          client.print("Room ");
          client.print(analog_pins[I] +1);
          client.print("'s Temperature is ");
          client.print(voltage);
          client.println("<br />"); // new line

          Serial.print("Address = ");
          Serial.print(analog_pins[I] +1);
          Serial.print(" ");
          Serial.print(voltage / 10);
          Serial.println();

         delay(1500);           

          }
           break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } 
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
   client.stop();
  }
}

Can you help solve what's wrong?

\$\endgroup\$
  • \$\begingroup\$ What happened that could have affected the Mega 2560 board between when you last saw it working correctly and last weekend? Thunderstorms, splashes, power-supply goof-ups, something cross-wired? Something appears to have changed on the board. \$\endgroup\$ – JRobert Jul 2 '13 at 13:53
  • 1
    \$\begingroup\$ You say you get no serial output, but you also say: "Also note that the "Serial Monitor" also displays 0.00 as the current temp.". So which is it? Do you get Serial output or do you get incorrect serial output. \$\endgroup\$ – baldengineer Jul 2 '13 at 20:27
  • \$\begingroup\$ In the first example where is setup() and the associated Serial.begin()? \$\endgroup\$ – baldengineer Jul 2 '13 at 20:28
  • \$\begingroup\$ You really don't want to get into the practice of using brackets like: "{ voltage = ((sensorValue) * (5.0 / 1023.0));}". Eventually you're going to forget one and spend a lot of time figuring out why the compiler is complaining about the wrong section of code. \$\endgroup\$ – baldengineer Jul 2 '13 at 20:29
  • \$\begingroup\$ Thanks for the feedback team...JRobert. Agree but why both boards as only 1 was connected. \$\endgroup\$ – Mark Fellowes Jul 2 '13 at 21:01
1
\$\begingroup\$

In the second code example, you have:

Serial.print(voltage / 10);

You probably meant:

  Serial.print(voltage / 10.0);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.