adapting code to work with four wind sensors.

Hi. I am new with arduino and I do not know how to programing, yet. I am trying to run a platform of 4 wind sensors in parallel, using an Arduino mega 2560
Each sensor provides two analog signal Out= wind speed and TMP=temperature. So, I have connected the sensors to six pins in the analog in of the arduino board:
Sensor 1 OUT=A0 TMP=A1
Sensor 2 =OUT=A2 TMP=A3
Sensor 3 =OUT=A4 TMP=A5
Sensor 4 =OUT=A6 TMP=A7

Now, I took the sketch provided by the sensors factory and (with help) I adapted the code to try to work with the four sensors, but the output in the serial monitor only show two columns of numbers. Can someone check this edited code?

This is the original code:

/* A demo sketch for the Modern Device Rev P Wind Sensor
* Requires a Wind Sensor Rev P from Modern Device
* http://moderndevice.com/product/wind-sensor-rev-p/
* 
* The Rev P requires at least at least an 8 volt supply. The easiest way to power it 
* if you are using an Arduino is to use a 9 volt or higher supply on the external power jack
* and power the sensor from Vin.
* 
* Hardware hookup 
* Sensor     Arduino Pin
* Ground     Ground
* +10-12V      Vin
* Out          A0
* TMP          A2
*
* Paul Badger 2014
* code in the public domain
*/

const int OutPin  = A0;   // wind sensor analog pin  hooked up to Wind P sensor "OUT" pin
const int TempPin = A2;   // temp sesnsor analog pin hooked up to Wind P sensor "TMP" pin


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

void loop() {

    // read wind
    int windADunits = analogRead(OutPin);
    //Serial.print("RW ");   // print raw A/D for debug
    //Serial.print(windADunits);
    //Serial.print("\t");
    
    
    // wind formula derived from a wind tunnel data, annemometer and some fancy Excel regressions
    // this scalin doesn't have any temperature correction in it yet
    float windMPH =  pow((((float)windADunits - 264.0) / 85.6814), 3.36814);
    Serial.print(windMPH);
    Serial.print(" MPH\t");    

 


    // temp routine and print raw and temp C
    int tempRawAD = analogRead(TempPin);  
    //Serial.print("RT ");    // print raw A/D for debug
    //Serial.print(tempRawAD);
    //Serial.print("\t");
    
    // convert to volts then use formula from datatsheet 
    // Vout = ( TempC * .0195 ) + .400
    // tempC = (Vout - V0c) / TC   see the MCP9701 datasheet for V0c and TC
    
    float tempC = ((((float)tempRawAD * 5.0) / 1024.0) - 0.400) / .0195; 
    Serial.print(tempC);
    Serial.println(" C");
    delay(750);
}

And this is the code edited for four sensors:

/* A demo sketch for the Modern Device Rev P Wind Sensor
* Requires a Wind Sensor Rev P from Modern Device
* http://moderndevice.com/product/wind-sensor-rev-p/
* 
* The Rev P requires at least at least an 8 volt supply. The easiest way to power it 
* if you are using an Arduino is to use a 9 volt or higher supply on the external power jack
* and power the sensor from Vin.
* 
* Hardware hookup 
* Sensor     Arduino Pin
* Ground     Ground
* +10-12V      Vin
* Out          A0
* TMP          A2
*
* Paul Badger 2014
* code in the public domain
*/

const int OutPin[4]  = {A0, A2, A4, A6};   // wind sensor analog pin  hooked up to Wind P sensor "OUT" pin
const int TempPin[4] = {A1, A3, A5, A7};   // temp sesnsor analog pin hooked up to Wind P sensor "TMP" pin

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

void loop() {

    // wind formula derived from a wind tunnel data, annemometer and some fancy Excel regressions
    // this scalin doesn't have any temperature correction in it yet
    // Leo comenzando en A0 hasta A3 y los presento
    for (int i=0; i<4; i++){
        int windADunits = analogRead(OutPin[i]);
        float windMPH =  pow((((float)windADunits - 264.0) / 85.6814), 3.36814);
        Serial.print(windMPH);
        Serial.print(" MPH\t");
        // temp routine and print raw and temp C
        int tempRawAD = analogRead(TempPin[i]);  
        // Serial.print("RT ");    // print raw A/D for debug
        // Serial.print(tempRawAD);
        // Serial.print("\t");
        
        // convert to volts then use formula from datatsheet 
        // Vout = ( TempC * .0195 ) + .400
        // tempC = (Vout - V0c) / TC   see the MCP9701 datasheet for V0c and TC
        
        float tempC = ((((float)tempRawAD * 5.0) / 1024.0) - 0.400) / .0195; 
        Serial.print(tempC);
        Serial.println(" C");        
    }
    
   
    delay(750);
}

Perhaps all you need to do is make a small change at the end
From this

       Serial.println(" C");        
    }
    delay(750);

to this

        Serial.print(" C\t");        
    }
    Serial.println();
    delay(750);

...R

Thanks for the response, but it did not work. I mean, It suppose to display 8 columns of numbers, right?:

Serial monitor:

5.35 MPH 85.91 C
5.88 MPH 71.38 C
1.37 MPH 67.13 C
0.70 MPH 65.12 C

2.05 MPH 78.65 C
3.86 MPH 68.88 C
1.09 MPH 66.13 C
0.73 MPH 66.13 C

2.25 MPH 82.15 C
5.10 MPH 72.64 C
1.68 MPH 69.63 C
1.32 MPH 70.88 C

4.07 MPH 86.91 C
7.05 MPH 75.14 C
2.05 MPH 70.38 C
1.18 MPH 68.13 C

2.69 MPH 81.65 C
4.98 MPH 71.89 C
1.42 MPH 67.13 C
0.67 MPH 63.37 C

1.05 MPH 75.14 C
3.29 MPH 69.63 C
1.18 MPH 66.63 C
0.79 MPH 66.38 C

Let's see your revised code in full.

You call println on the "C".

Not if he/she did as Robin suggested, which I bet he/she did not do.

This is the code with the edition suggested:

const int OutPin[4]  = {A0, A2, A4, A6};   // wind sensor analog pin  hooked up to Wind P sensor "OUT" pin
const int TempPin[4] = {A1, A3, A5, A7};   // temp sesnsor analog pin hooked up to Wind P sensor "TMP" pin

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

void loop() {

    // wind formula derived from a wind tunnel data, annemometer and some fancy Excel regressions
    // this scalin doesn't have any temperature correction in it yet
    // Leo comenzando en A0 hasta A3 y los presento
    for (int i=0; i<4; i++){
        int windADunits = analogRead(OutPin[i]);
        float windMPH =  pow((((float)windADunits - 264.0) / 85.6814), 3.36814);
        Serial.print(windMPH);
        Serial.print(" MPH\t");
        // temp routine and print raw and temp C
        int tempRawAD = analogRead(TempPin[i]);  
        // Serial.print("RT ");    // print raw A/D for debug
        // Serial.print(tempRawAD);
        // Serial.print("\t");
        
        // convert to volts then use formula from datatsheet 
        // Vout = ( TempC * .0195 ) + .400
        // tempC = (Vout - V0c) / TC   see the MCP9701 datasheet for V0c and TC
        
        float tempC = ((((float)tempRawAD * 5.0) / 1024.0) - 0.400) / .0195; 
        Serial.print(tempC);
        Serial.println(" C\t");        
    }
   Serial.println(); 
   
    delay(750);
}

In your revised code

        Serial.println(" C\t");

Compare that with what Robin suggested

       Serial.print(" C\t");

Now do you see the problem as explained by Delta_G ?

Ohhh. I see. sorry, my mistake. I did not read properly. I understand now.

Thanks a lot.

Just one think, the columns looks a bit confuse. it should be MPH C - MPH C - MPH C - MPH C
But in the serial monitor, actually it looks like this:

Is there a way to make more separated the columns visually?

Is there a way to make more separated the columns visually?

Adjust the layout by printing spaces and/or tabs where you want/need them.

Sure, just move the "\t" to a better place. It creates the tab.
Have some fun with this. You won't crash the program or anything.

"four strong winds that blow lonely... seven C's that run high" :slight_smile:

Thanks again. I will play with the "\t" XD

Hi im curious of your application, were you using 4 to sense direction? Do you have another post of your prokect?

Thanks,

Ken

Can someone explain for me this part of code guys ? How to find values of V0c and TC from datasheet ?

// convert to volts then use formula from datatsheet
// Vout = ( TempC * .0195 ) + .400
// tempC = (Vout - V0c) / TC see the MCP9701 datasheet for V0c and TC

seashell90:
Can someone explain for me this part of code guys ?

What has this got to do with "four wind sensors" ?

...R