I have a water and temperature sensor connected to the Arduino Mega board and they both work separately on different files when I put the code in and run it. So I tried to get them to run together by uploading one code for the water sensor and then trying to upload the temp. sensor code to run together but only one works. Would I need to combine the code together and if so what would the code be. What do I need to do to get both the water and temp sensor running at the same time?
Code I used for the water sensor.
#define POWER_PIN 10
#define SIGNAL_PIN A5
int value = 0; // variable to store the sensor value
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT); // configure D7 pin as an OUTPUT
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
}
void loop() {
digitalWrite(POWER_PIN, HIGH); // turn the sensor ON
delay(10); // wait 10 milliseconds
value = analogRead(SIGNAL_PIN); // read the analog value from sensor
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
Serial.print("Sensor value: ");
Serial.println(value);
delay(1000);
}
No I don't really understand how the code works separately, I just copy and pasted the codes into one file, but there were a lot of error messages when I tried uploading it.
Keep it simple and stupid firstly.
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.
That's what I did. This is for a school project and I'm also wondering how to be able to see the serial monitor appearing together at the same time for both the water and temp. sensor.
The code is in two different sketch files, I meant to say that they both work separately but I need them to work together. How would I be able to do that?
#include <dht.h>
#define POWER_PIN 10
#define SIGNAL_PIN A5
#define DHT11_PIN 8
dht DHT;
int value = 0; // variable to store the sensor value
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT); // configure D7 pin as an OUTPUT
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
}
void loop() {
digitalWrite(POWER_PIN, HIGH); // turn the sensor ON
delay(10); // wait 10 milliseconds
value = analogRead(SIGNAL_PIN); // read the analog value from sensor
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
Serial.print("Sensor value: ");
Serial.println(value);
delay(1000);
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
I am not a big expert myself...is this the same code you tried when combining?..
Also here its running water sensor first and then the temperature sensor