i have used arduino mega 2560. and i am using four type of sensors, they are 3x flow sensors, and pH sensor, temperature sensor, and turbidity sensor . i have connected three flow sensors and conditions may apllied it's working properly. and the other sensors are individually performs perfectly with conditions, but all the sensors connected and program merged for all sensors gives output perfectly but flow sensors conditions only works, and the other sensors are not satisfies the conditions and it won't works...
I wanna merge and all the below programs and the problem must be resolved...
somebody please help...
#define FLOWSENSORPIN 2
#define FLOWSENSORPIN2 3
#define FLOWSENSORPIN3 21
int motor = 10;
int Solenoid1 = 11;
int Solenoid2 = 12;
// count how many pulses!
volatile uint16_t pulses = 0;
volatile uint16_t pulses2 = 0;
volatile uint16_t pulses3 = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
volatile uint8_t lastflowpinstate2;
volatile uint8_t lastflowpinstate3;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
volatile uint32_t lastflowratetimer2 = 0;
volatile uint32_t lastflowratetimer3 = 0;
// and use that to calculate a flow rate
volatile float flowrate;
volatile float flowrate2;
volatile float flowrate3;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
uint8_t x = digitalRead(FLOWSENSORPIN);
if (x == lastflowpinstate) {
lastflowratetimer++;
return; // nothing changed!
}
if (x == HIGH) {
//low to high transition!
pulses++;
}
lastflowpinstate = x;
flowrate = 1000.0;
flowrate /= lastflowratetimer; // in hertz
lastflowratetimer = 0;
}
SIGNAL(TIMER2_COMPA_vect) {
uint8_t x2 = digitalRead(FLOWSENSORPIN2);
if (x2 == lastflowpinstate2) {
lastflowratetimer2++;
return; // nothing changed!
}
if (x2 == HIGH) {
//low to high transition!
pulses2++;
}
lastflowpinstate2 = x2;
flowrate2 = 1000.0;
flowrate2 /= lastflowratetimer2; // in hertz
lastflowratetimer2 = 0;
}
SIGNAL(TIMER3_COMPA_vect) {
uint8_t x3 = digitalRead(FLOWSENSORPIN3);
if (x3 == lastflowpinstate3) {
lastflowratetimer3++;
return; // nothing changed!
}
if (x3 == HIGH) {
//low to high transition!
pulses3++;
}
lastflowpinstate3 = x3;
flowrate3 = 1000.0;
flowrate3/= lastflowratetimer3; // in hertz
lastflowratetimer3 = 0;
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}
void useInterrupt2(boolean b) {
if (b) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR2A = 0xAF;
TIMSK2 |= _BV(OCIE2A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK2 &= ~_BV(OCIE2A);
}
}
void useInterrupt3(boolean C) {
if (C) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR3A = 0xAF;
TIMSK3 |= _BV(OCIE3A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK3 &= ~_BV(OCIE3A);
}
}
void setup()
{
Serial.begin(9600);
pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
lastflowpinstate = digitalRead(FLOWSENSORPIN);
pinMode(FLOWSENSORPIN2, INPUT);
digitalWrite(FLOWSENSORPIN2, HIGH);
lastflowpinstate2 = digitalRead(FLOWSENSORPIN2);
pinMode(FLOWSENSORPIN3, INPUT);
digitalWrite(FLOWSENSORPIN3, HIGH);
lastflowpinstate3 = digitalRead(FLOWSENSORPIN3);
pinMode(motor,OUTPUT);
pinMode(Solenoid1,OUTPUT);
pinMode(Solenoid2,OUTPUT);
digitalWrite(motor,LOW);
digitalWrite(Solenoid1,LOW);
digitalWrite(Solenoid2,LOW);
useInterrupt(true);
useInterrupt2(true);
useInterrupt3(true);
}
void loop() {
float ltr1;
float ltr2;
float ltr3;
float d;
float e;
float f;
ltr1 = callliters1();
ltr2 = callliters2();
ltr3 = callliters3();
//Serial.println(level);
Serial.print(ltr1); Serial.print(" Liters1"); Serial.print(" "); Serial.print(ltr2); Serial.println(" Liters2"); Serial.print(" "); Serial.print(ltr3); Serial.println(" Liters3");
delay(500);
/// LEAKAGE DETECTION
d = ltr2+ltr3;
e = (d + 0.10);
f = (d - 0.10);
if(ltr1<=e && ltr1>=f)
{
Serial.println(" NO LEKAGE DETECTED ");
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}
else
{
Serial.println(" LEKAGE DETECTED ");
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
}
if(ltr2>=1.00)
{
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(12,LOW);
}
if(ltr3>=1.50)
{
digitalWrite(12,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
if(ltr2>=1.00 && ltr3>=1.50){
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
Serial.println("water distributed");
}
}
/// calculation and return for flow 123
float callliters1()
{
float liters1 = pulses;
liters1 /= 7.5;
liters1 /= 60.0;
return(liters1);
}
float callliters2()
{
float liters2 = pulses2;
liters2 /= 7.5;
liters2 /= 60.0;
return(liters2);
}
float callliters3()
{
float C;
float liters3 = pulses3;
liters3 /= 7.5;
liters3 /= 60.0;
return(liters3);
}
int motor=10;
int solenoid1=11;
int solenoid2=12;
void setup() {
Serial.begin(9600); //Baud rate: 9600
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop() {
float voltage;
float T;
T= callvoltage();
Serial.print( " turbidity");
delay(500);
if(T<=1)
{
Serial.println( " 5.06 NTU");
digitalWrite( 10,LOW);
digitalWrite( 11,LOW);
digitalWrite( 12,LOW);
}
else
{
Serial.println( " 3 NTU");
digitalWrite( 10,HIGH);
digitalWrite( 11,HIGH);
digitalWrite( 12,HIGH);
}
}
// returning turbidity
float callvoltage()
{
int sensorValue = analogRead(A1);// read the input on analog pin 0:
float voltage = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
return(voltage); // print out the value you read:
}
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius=0;
int motor=10;
int solenoid1=11;
int solenoid2=12;
void setup()
{
Serial.begin(9600);
sensors.begin();
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop()
{
float tempe;
tempe=Tempvalue();
if(tempe>=20 && tempe<=40){
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}
else{
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
}
}
float Tempvalue(){
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Serial.print(Celcius);
Serial.print(" C ");
return(Celcius);
}
const int analogInPin = A0;
int sensorValue = 0;
unsigned long int avgValue;
float b;
int buf[10],temp;
int motor=10;
int solenoid1=11;
int solenoid2=12;
void setup()
{
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop() {
float pH;
pH=pHvalue();
if(pH>=6 && pH<=8.5){
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}
else{
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
}
}
float pHvalue(){
for(int i=0;i<10;i++)
{
buf[i]=analogRead(analogInPin);
delay(10);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++)
avgValue+=buf[i];
float pHVol=(float)avgValue*5.0/1024/6;
float phValue = -5.70 * pHVol + 21.34;
Serial.print(" sensor value = ");
Serial.println(phValue);
delay(500);
return(phValue);
}
and also i want the suggestion to which IoT platform is suitable to show the sensor values and switch on /off control via IoT.....