Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / DHT22 (or equivalent) over long distance. on: February 20, 2014, 11:50:39 pm
Hi. I have a project to monitor temperature and humidity at multiple place in a greenhouse. I want to use multiple DHT22 on a cable of at least 60 m (200 ft). I have cat5 cable in hand. What should i do? Use RS-485? I dont think i understand all about RS-485. Does i need an arduino with MAX485 for each sensor on the Line or i can only plug sensor on the max485 module? Tanks and sorry for my bad english... It's not my first language.
2  Using Arduino / Programming Questions / Re: Variable declaring problem on: January 16, 2013, 05:01:17 pm
Tanks. I will not use 10 sensor in the future because with 6 sensor all pin of the 328 is used but could you make me an example of your "constant value line numSoilSamples that is equal to 6" because i think i don't understand.

this is the modified code:

Code:
#include <EasyTransfer.h>

//create object
EasyTransfer ET;

struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int soil[7];

};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

void setup(){
  Serial.begin(9600);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(mydata), &Serial);

  for(int i=2;i<14;i++){
    pinMode(i,OUTPUT);
    digitalWrite(i, LOW);
  }

  for(int i=0;i<6;i++){
    pinMode(i,INPUT);
  }

}

void loop(){
  //send the data
  for (int i=0;i<6;i++){
    sensorRead(i);
    ET.sendData();
   
  }
}

void sensorRead(int sensor){
  digitalWrite(sensor*2, HIGH);
  digitalWrite(sensor*2+1, LOW);
  delay(1000);
  int val1 = analogRead(sensor-1);
  digitalWrite(sensor*2, LOW);
  digitalWrite(sensor*2+1, HIGH);
  delay(1000);
  int val2 = 1023 - analogRead(sensor-1);
  mydata.soil[sensor] = (val1 + val2) / 2;
  digitalWrite(sensor*2, LOW);
  digitalWrite(sensor*2+1, LOW);
}
3  Using Arduino / Programming Questions / Variable declaring problem on: January 16, 2013, 04:26:35 pm
Hi, i have a little piece of coding based on EasyTransfer. It's a soil moisture meter that take data and send it to another arduino. The code:

Code:
#include <EasyTransfer.h>

//create object
EasyTransfer ET;

struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int soil1;
  int soil2;
  int soil3;
  int soil4;
  int soil5;
  int soil6;

};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

void setup(){
  Serial.begin(9600);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(mydata), &Serial);

  for(int i=2;i<=13;i++){
    pinMode(i,OUTPUT);
    digitalWrite(i, LOW);
  }

  for(int i=0;i<=5;i++){
    pinMode(i,INPUT);
  }

}

void loop(){
  for (int i=1;i<=6;i++){
    sensorRead(i);
    ET.sendData();
  }
}

void sensorRead(int sensor){
  digitalWrite(sensor*2, HIGH);
  digitalWrite(sensor*2+1, LOW);
  delay(1000);
  int val1 = analogRead(sensor-1);
  digitalWrite(sensor*2, LOW);
  digitalWrite(sensor*2+1, HIGH);
  delay(1000);
  int val2 = 1023 - analogRead(sensor-1);
  soil[sensor] = (val1 + val1) / 2;
  digitalWrite(sensor*2, LOW);
  digitalWrite(sensor*2+1, LOW);
}

but when i try to compile it i have this error:

Code:
EasyTransfer_TX_Example.cpp: In function 'void sensorRead(int)':
EasyTransfer_TX_Example.pde:-1: error: 'soil' was not declared in this scope

how can i declare the soil[] variable?
tanks
4  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 04:55:01 pm
...... maybe... so i make my test with weight/read tu deternine the % of water in the soil and then i enter the value in multimap() (ex: 5%,10%,15% etc...) and the corespondant reading (ex:1000,950,900 etc...) and .....
5  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 03:02:53 pm
Quote
I want to show in % the soil humidity but Another problem is i dont think the soil resistance increase is linear so maybe i do this for nothing

Check my multiMap() on the playground, it is invented for non linear thingies. See - http://playground.arduino.cc/Main/MultiMap -

(time for a cup of tea smiley-wink

ok i read it but i not sure to understand what i'm reading smiley-razz
6  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 01:58:09 pm
I think i will have to do test by soil weight to know the humidity level and the reading according to that!
7  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 01:40:24 pm
Yes, (even unisgned int would be too small)

looking at the formula you can work around it as follows too:

Serial.print(100 - (avg2*10/101) );  // removed a common factor 10

avg2 *10 is max 10000, divided by 101 is 99 or so all within int range


Q: why divide by 101? what is the range you expect in the print? 1..100 or 0..100?

1010 it's the Max of what i can read with the sensor... I want to show in % the soil humidity but Another problem is i dont think the soil resistance increase is linear so maybe i do this for nothing smiley-razz
8  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 01:10:52 pm
there is an int overflow, make all constants long by adding the L modifier to them

Serial.print(100L - (avg2*100L/1010L) );

Tanks, that work but now to want to know why smiley-razz ....
The biggest number i have in this formula is 100000 (avg2*100) ... That's why i have this problem due to integer limitation of 32767??
9  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 12:45:33 pm
.... Another question ... Why when i wrote that:
Code:
Serial.print(100-(avg2*100/1010));

If avg2=1000, I receive 130 ... ???
10  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 12:29:15 pm
Only the define of sensorPin has changed ....

Code:
#define voltageFlipPin11 2
#define voltageFlipPin12 3
#define voltageFlipPin21 4
#define voltageFlipPin22 6
#define voltageFlipPin31 7
#define voltageFlipPin32 8
#define voltageFlipPin41 9
#define voltageFlipPin42 11
#define sensorPin1 A4
#define sensorPin2 A2
#define sensorPin3 A1
#define sensorPin4 A0

int flipTimer = 1000;
int currentsensor=1;
int val11;
int val12;
int avg1;
int val21;
int val22;
int avg2;
int val31;
int val32;
int avg3;
int val41;
int val42;
int avg4;

void setup(){
  Serial.begin(9600);
  pinMode(voltageFlipPin11, OUTPUT);
  pinMode(voltageFlipPin12, OUTPUT);
  pinMode(voltageFlipPin21, OUTPUT);
  pinMode(voltageFlipPin22, OUTPUT);
  pinMode(voltageFlipPin31, OUTPUT);
  pinMode(voltageFlipPin32, OUTPUT);
  pinMode(voltageFlipPin41, OUTPUT);
  pinMode(voltageFlipPin42, OUTPUT);
  digitalWrite(voltageFlipPin11, LOW);
  digitalWrite(voltageFlipPin12, LOW);
  digitalWrite(voltageFlipPin21, LOW);
  digitalWrite(voltageFlipPin22, LOW);
  digitalWrite(voltageFlipPin31, LOW);
  digitalWrite(voltageFlipPin32, LOW);
  digitalWrite(voltageFlipPin41, LOW);
  digitalWrite(voltageFlipPin42, LOW);
  pinMode(sensorPin1, INPUT);
  pinMode(sensorPin2, INPUT);
  pinMode(sensorPin3, INPUT);
  pinMode(sensorPin4, INPUT);
}

void loop(){
  switch (currentsensor){

  case 1:
    digitalWrite(voltageFlipPin11, HIGH);
    digitalWrite(voltageFlipPin12, LOW);
    delay(flipTimer);
    val11 = analogRead(sensorPin1);
    delay(flipTimer);
    digitalWrite(voltageFlipPin11, LOW);
    digitalWrite(voltageFlipPin12, HIGH);
    delay(flipTimer);
    val12 = 1023 - analogRead(sensorPin1);
    avg1 = (val11 + val12) / 2;
    digitalWrite(voltageFlipPin11, LOW);
    digitalWrite(voltageFlipPin12, LOW);
    ++currentsensor;
    break;

  case 2:
    digitalWrite(voltageFlipPin21, HIGH);
    digitalWrite(voltageFlipPin22, LOW);
    delay(flipTimer);
    val21 = analogRead(sensorPin2);
    delay(flipTimer);
    digitalWrite(voltageFlipPin21, LOW);
    digitalWrite(voltageFlipPin22, HIGH);
    delay(flipTimer);
    val22 = 1023 - analogRead(sensorPin2);
    avg2 = (val21 + val22) / 2;
    digitalWrite(voltageFlipPin21, LOW);
    digitalWrite(voltageFlipPin22, LOW);
    ++currentsensor;
    break;

  case 3:
    digitalWrite(voltageFlipPin31, HIGH);
    digitalWrite(voltageFlipPin32, LOW);
    delay(flipTimer);
    val31 = analogRead(sensorPin3);
    delay(flipTimer);
    digitalWrite(voltageFlipPin31, LOW);
    digitalWrite(voltageFlipPin32, HIGH);
    delay(flipTimer);
    val32 = 1023 - analogRead(sensorPin3);
    avg3 = (val31 + val32) / 2;
    digitalWrite(voltageFlipPin31, LOW);
    digitalWrite(voltageFlipPin32, LOW);
    ++currentsensor;
    break;

  case 4:
    digitalWrite(voltageFlipPin41, HIGH);
    digitalWrite(voltageFlipPin42, LOW);
    delay(flipTimer);
    val41 = analogRead(sensorPin4);
    delay(flipTimer);
    digitalWrite(voltageFlipPin41, LOW);
    digitalWrite(voltageFlipPin42, HIGH);
    delay(flipTimer);
    val42 = 1023 - analogRead(sensorPin4);
    avg4 = (val41 + val42) / 2;
    digitalWrite(voltageFlipPin41, LOW);
    digitalWrite(voltageFlipPin42, LOW);
    ++currentsensor;
    break;

  case 5:
    Serial.print("Sensor Value #1: ");
    Serial.println(avg1);
    Serial.println();
    Serial.print("Sensor Value #2: ");
    Serial.println(avg2);
    Serial.println();
    Serial.print("Sensor Value #3: ");
    Serial.println(avg3);
    Serial.println();
    Serial.print("Sensor Value #4: ");
    Serial.println(avg4);
    Serial.println("-----------------------");
     Serial.print("Average Sensor Value: ");
    Serial.println((avg1+avg2+avg3+avg4)/4);
    Serial.println();
    Serial.println();
    currentsensor=1;
    break;

  }

}
11  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 06, 2013, 12:13:02 pm
... and the sensorPin suppose to be A0, A1 like robtillaart said ... Hardware serial is digital pin not analog no? So no conflict !
12  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 05, 2013, 05:12:24 pm
#define voltageFlipPin11 2
#define voltageFlipPin21 4

conflicts with these pins ?

#define sensorPin1 4
#define sensorPin2 2

IIRC Analog pins should be addressed as A0 A1 A2 A4 etc.

Tanks a lot ... That's the problem... All works well now!!
13  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 05, 2013, 05:06:14 pm
I try nearly all analog pin combinations and i dont even see a patern... Random number on random pins... Maybe limitation with the A/D ...???
14  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 05, 2013, 02:08:04 pm
tanks for the script, yes it's simpler but i have the same problem .... i cannot use 4 sensor at same time, i can read 3 but when i add one it give me bad read ....
15  Using Arduino / Sensors / Re: Soil Moisture sensor on: January 05, 2013, 01:21:24 pm
Ok ... i change the analogPin definition and it seem to work in water. When i remove it and let the sensor in the air sensor #3 and #4 give me nearly 1024 that's ok but #1 and #2 give me random number between 600 and 800... ... i use pin 4, pin 2, pin 1 and pin 0. I really don't understand why analogPin works all fine but in this sketch some AnalogPin and DigitalPin, when they are used, give me error (DigitalPin= Not enough current, AnalogPin= Bad read value) ....

 Here the sketch(Translate from french to english) :

Code:
#define voltageFlipPin11 2
#define voltageFlipPin12 3
#define voltageFlipPin21 4
#define voltageFlipPin22 6
#define voltageFlipPin31 7
#define voltageFlipPin32 8
#define voltageFlipPin41 9
#define voltageFlipPin42 11
#define sensorPin1 4
#define sensorPin2 2
#define sensorPin3 1
#define sensorPin4 0

int flipTimer = 1000;
int currentsensor=1;
int val11;
int val12;
int avg1;
int val21;
int val22;
int avg2;
int val31;
int val32;
int avg3;
int val41;
int val42;
int avg4;

void setup(){
  Serial.begin(9600);
  pinMode(voltageFlipPin11, OUTPUT);
  pinMode(voltageFlipPin12, OUTPUT);
  pinMode(voltageFlipPin21, OUTPUT);
  pinMode(voltageFlipPin22, OUTPUT);
  pinMode(voltageFlipPin31, OUTPUT);
  pinMode(voltageFlipPin32, OUTPUT);
  pinMode(voltageFlipPin41, OUTPUT);
  pinMode(voltageFlipPin42, OUTPUT);
  digitalWrite(voltageFlipPin11, LOW);
  digitalWrite(voltageFlipPin12, LOW);
  digitalWrite(voltageFlipPin21, LOW);
  digitalWrite(voltageFlipPin22, LOW);
  digitalWrite(voltageFlipPin31, LOW);
  digitalWrite(voltageFlipPin32, LOW);
  digitalWrite(voltageFlipPin41, LOW);
  digitalWrite(voltageFlipPin42, LOW);
  pinMode(sensorPin1, INPUT);
  pinMode(sensorPin2, INPUT);
  pinMode(sensorPin3, INPUT);
  pinMode(sensorPin4, INPUT);
}

void loop(){
  switch (currentsensor){

  case 1:
    digitalWrite(voltageFlipPin11, HIGH);
    digitalWrite(voltageFlipPin12, LOW);
    delay(flipTimer);
    val11 = analogRead(sensorPin1);
    delay(flipTimer);
    digitalWrite(voltageFlipPin11, LOW);
    digitalWrite(voltageFlipPin12, HIGH);
    delay(flipTimer);
    val12 = 1023 - analogRead(sensorPin1);
    avg1 = (val11 + val12) / 2;
    digitalWrite(voltageFlipPin11, LOW);
    digitalWrite(voltageFlipPin12, LOW);
    ++currentsensor;
    break;

  case 2:
    digitalWrite(voltageFlipPin21, HIGH);
    digitalWrite(voltageFlipPin22, LOW);
    delay(flipTimer);
    val21 = analogRead(sensorPin2);
    delay(flipTimer);
    digitalWrite(voltageFlipPin21, LOW);
    digitalWrite(voltageFlipPin22, HIGH);
    delay(flipTimer);
    val22 = 1023 - analogRead(sensorPin2);
    avg2 = (val21 + val22) / 2;
    digitalWrite(voltageFlipPin21, LOW);
    digitalWrite(voltageFlipPin22, LOW);
    ++currentsensor;
    break;

  case 3:
    digitalWrite(voltageFlipPin31, HIGH);
    digitalWrite(voltageFlipPin32, LOW);
    delay(flipTimer);
    val31 = analogRead(sensorPin3);
    delay(flipTimer);
    digitalWrite(voltageFlipPin31, LOW);
    digitalWrite(voltageFlipPin32, HIGH);
    delay(flipTimer);
    val32 = 1023 - analogRead(sensorPin3);
    avg3 = (val31 + val32) / 2;
    digitalWrite(voltageFlipPin31, LOW);
    digitalWrite(voltageFlipPin32, LOW);
    ++currentsensor;
    break;

  case 4:
    digitalWrite(voltageFlipPin41, HIGH);
    digitalWrite(voltageFlipPin42, LOW);
    delay(flipTimer);
    val41 = analogRead(sensorPin4);
    delay(flipTimer);
    digitalWrite(voltageFlipPin41, LOW);
    digitalWrite(voltageFlipPin42, HIGH);
    delay(flipTimer);
    val42 = 1023 - analogRead(sensorPin4);
    avg4 = (val41 + val42) / 2;
    digitalWrite(voltageFlipPin41, LOW);
    digitalWrite(voltageFlipPin42, LOW);
    ++currentsensor;
    break;

  case 5:
    Serial.print("Sensor Value #1: ");
    Serial.println(avg1);
    Serial.println();
    Serial.print("Sensor Value #2: ");
    Serial.println(avg2);
    Serial.println();
    Serial.print("Sensor Value #3: ");
    Serial.println(avg3);
    Serial.println();
    Serial.print("Sensor Value #4: ");
    Serial.println(avg4);
    Serial.println("-----------------------");
     Serial.print("Average Sensor Value: ");
    Serial.println((avg1+avg2+avg3+avg4)/4);
    Serial.println();
    Serial.println();
    currentsensor=1;
    break;

  }

}
Pages: [1] 2 3