reding fluctuations once code is combined.

Hello,

I have a Mega2560 r3 an adafruit 2.8" TFT an LM35 temp sensor and an Ph sensor.

my code looks as follows.

/* Evan S Gray
 *  
 */



// 
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Color definitions
#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define CYAN     0x07FF
#define MAGENTA  0xF81F
#define YELLOW   0xFFE0 
#define WHITE    0xFFFF

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);



int value=0;            //initializing variables
float volts=0.0;      
float temp=0.0;      
float tempF=0.0;
int LM35 = A9; 




void setup() {

  // Begin Serial Comm
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 

  //Begin TFT
  tft.begin();

  // Read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 


  //set screen rotation
  tft.setRotation(1);
  
  //fill screen black
  tft.fillScreen(BLACK);
  
  //set text wrap
  tft.setTextWrap(true);

  // Display text
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.println("Hello World!");

  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.println("Welcome to the first");

  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println("Version of our Watering");

  tft.setTextColor(BLUE);
  tft.setTextSize(4);
  tft.println("System");

  delay(4000);
  
  tft.fillScreen(BLACK);
  
  

  

}

// the loop routine runs over and over again forever:
void loop() {

  
  // read the input on analog pin 10
  float sensorValue = analogRead(A10);     //get current sensorValue between 0-1000
  float Voltage = sensorValue*(5.0/1024.0);     //convert sensorValue to voltage 0-5v
  float pH = (Voltage*3.56)-1.889;     //convert voltage to pH

 value=analogRead(LM35);          //read from A9
  volts=(value/1024.0)*5.0;      //conversion to volts
  temp= volts*100.0;             //conversion to temp Celsius
  tempF=temp*9/5+32;             //conversion to temp Fahrenheit



  Serial.print("temperature= "); 
  Serial.println(tempF); //print the temperature in fahrenheit
  
  // print out the value for pH
  Serial.println("SensorValue");
  Serial.println(sensorValue);
  Serial.println("Voltage");
  Serial.println(Voltage);
  Serial.println("pH");
  Serial.println(pH);

  // print out value for temp
  //Serial.println("SensorValue1");
  //Serial.println(sensorValue1);
  //Serial.println("Voltage1");
  //Serial.println(Voltage1);
  //Serial.println("temp");
  //Serial.println(tempF);

  // print header 
  tft.setCursor(1,0);
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.println("GrayMatter");
  tft.setCursor(25,25);
  tft.println("Growers");
  
  
  tft.drawRoundRect(210,10,90,45,25,WHITE);
  tft.setCursor(230,15);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("pH =");
  tft.setCursor(230,33); 
  tft.println(pH); // print pH value 0-14

  tft.drawRoundRect(210,65,90,45,25,WHITE);
  tft.setCursor(230,70);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Temp");
  tft.setCursor(230,88); 
  tft.println(tempF); // print temp value F

  tft.drawRoundRect(210,120,90,45,25,WHITE);
  tft.setCursor(230,125);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Hum =");
  tft.setCursor(230,143); 
  tft.println("75%"); // print Humidity value %

  tft.drawRoundRect(210,175,90,45,25,WHITE);
  tft.setCursor(230,180);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("cO2 =");
  tft.setCursor(230,198); 
  tft.println(pH); // print cO2 value ppm
  delay(10000);        // delay in between reads for stability
  
  tft.fillScreen(BLACK);

 
}

Hello,

when I run the following code I get accurate temp sensor readings.
when I run the code combined in the first sketch I get fluctuating and errors readings.
there is no difference in the wiring between the two sketches

*/
int value=0;            //initializing variables
float volts=0.0;      
float temp=0.0;      
float tempF=0.0;
int LM35 = A9; 


void setup() {
  
  Serial.begin(9600);
    
}

void loop() {
    
    value=analogRead(LM35);          //read from A9
  volts=(value/1024.0)*5.0;      //conversion to volts
  temp= volts*100.0;             //conversion to temp Celsius
  tempF=temp*9/5+32;             //conversion to temp Fahrenheit



  Serial.print("temperature= "); 
  Serial.println(tempF); //print the temperature in fahrenheit
  
  
  delay(500);
}

Having an indeterminate serial bit rate can't help, surely?

Hello please find the pictures of the circuit attached.

Delta_G:
Can you describe? How much do they fluctuate? What are the errors? I shouldn't be having to pump you for information. If you want help then don't be terse, go ahead and write a little bit and tell us what is going on. Which component was it that started this trouble. You didn't go straight from the code in #2 to the code in the OP without any testing did you?

It would still help to see. There may be some electrical issues with the other sensors being connected. Who knows. But if you don't show me then I can't help you. I can't debug something I can't see. You have to understand that. If you want help then come on with the details.

Hello,

The reading fluctuates from -10 to +30 degrees when running the code combined with other code. The error is that the temp is fluctuating.

I have been running the code for some time with no problems. once I added the code for the LM35 temp sensor the readings start to fluctuate as described above.

In the first listing (post 1) you have:

int LM35 = A9;

In the one that works (post 3) you have:

int LM35 = A0;

If there's no difference in the wiring that might be your problem.

Hello,

I created new sketch with only the code to run the two sensors.
again i find that once the code for the two sensors is combined into the same sketch it starts to malfunction by showing fluctuating and erroronius readings. is it because the two sets of code are not defined in separate functions?

int value=0;            //initializing variables
float volts=0.0;      
float temp=0.0;      
float tempF=0.0;
int LM35 = A9; 


void setup() {
  
  Serial.begin(9600);
    
}

void loop() {
    
    value=analogRead(LM35);          //read from A9
  volts=(value/1024.0)*5.0;      //conversion to volts
  temp= volts*100.0;             //conversion to temp Celsius
  tempF=temp*9/5+32;             //conversion to temp Fahrenheit

   // read the input on analog pin 10
  float sensorValue = analogRead(A10);     //get current sensorValue between 0-1000
  float Voltage = sensorValue*(5.0/1024.0);     //convert sensorValue to voltage 0-5v
  float pH = (Voltage*3.56)-1.889;     //convert voltage to pH


  Serial.print("temperature= "); 
  Serial.println(tempF); //print the temperature in fahrenheit
  
  
  delay(500);
}

Which pH sensor?

Show your wiring diagram. If you don't have a proper schematic-drawing program a pencil sketch on a napkin is acceptable.

Sensors like pH sensors tend to have very harsh peaks of current usage. That upsets other sensors using the same power source as their reference voltage.

Of course a digital temperature sensor like the DS18B20 has much less problems with that and it's easier to read than the LM35.

MorganS:
Which pH sensor?

Show your wiring diagram. If you don't have a proper schematic-drawing program a pencil sketch on a napkin is acceptable.

Sensors like pH sensors tend to have very harsh peaks of current usage. That upsets other sensors using the same power source as their reference voltage.

Of course a digital temperature sensor like the DS18B20 has much less problems with that and it's easier to read than the LM35.

im using the phidgits ORP/PH 1130 pH shield

So do you think if its current usage then just providing a high amperage power supply should solve the issue.

Ill look into the digital temp sensor.

Im getting more and better pics together.

hope this helps with the wiring.

No. That does not help. Draw a diagram on paper. Photograph that.

Try to use standard symbols but you don't need to waste time getting the symbols perfect. Each component can be a square box with the inputs and outputs labelled by pin number and function is actually the best way to draw it.

Hello

I removed the LM35 temp sensor and added a DHT11 on digital pin 30.
now im having a compile error.

Can someone advise me on what the issue might be?

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\evan_\Documents\Arduino\libraries\Adafruit_GFX_Library\Adafruit_SPITFT.cpp: In member function 'writeFastHLine':

C:\Users\evan_\Documents\Arduino\libraries\Adafruit_GFX_Library\Adafruit_SPITFT.cpp:704:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.19.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

That is an unusual error. Post your code.