User Tools

Site Tools


soil_sensor_project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
soil_sensor_project [2013/06/17 05:10]
admin
soil_sensor_project [2016/09/01 14:17] (current)
Line 10: Line 10:
  
 ===== Software ===== ===== Software =====
-<file ino Smart_Counter_Altivar_11_1.0.0.ino>​+<file ino Example_Soil_Sensor_1.0.0.ino>​ 
 +/* 
 +Author: Dubravko Penezic 
 + 
 +Version: 1.0, 2013 
 + 
 +This code is example how to use Sensor for measure soil temperature and humidity. 
 + 
 +Source code is provided as is, without any warranty. 
 + 
 +Distributetd under CC BY v 3.0 
 + 
 +*/ 
 + 
 +// include 1Wire library 
 +#include <​Dp1WBasic.h>​ 
 +#include <​Dp1WDS18xxxTermo.h>​ 
 + 
 +// Data wire is plugged into port 5 on the Arduino 
 +#define ONE_WIRE_BUS 5 
 + 
 +// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/​Dallas temperature ICs) 
 +Dp1WBasic oneWire(ONE_WIRE_BUS);​ 
 + 
 +// Pass our oneWire reference to Dallas Temperature.  
 +Dp1WDS18xxxTermo tSen(&​oneWire);​ 
 + 
 +// arrays to hold device address 
 +SensorInfo tempSensors[16];​ 
 + 
 +//include CapSense library 
 +#include <​CapSense.h>​ 
 + 
 +CapSense ​  ​cs_7_9 = CapSense(7,​9); ​       // 10M resistor between pins 7 & 9, pin 9 is sensor pin  
 +CapSense ​  ​cs_7_10 = CapSense(7,​10); ​       // 10M resistor between pins 7 & 10, pin 10 is sensor pin 
 +CapSense ​  ​cs_7_11 = CapSense(7,​11); ​       // 10M resistor between pins 7 & 11, pin 11 is sensor pin 
 +CapSense ​  ​cs_7_12 = CapSense(7,​12); ​       // 10M resistor between pins 7 & 12, pin 12 is sensor pin 
 + 
 +// set LED pin 
 +byte led1 = 6; 
 +byte led2 = 8; 
 +byte led3 = 13; 
 + 
 +void setup(void) { 
 +  //   ​cs_7_9.set_CS_AutocaL_Millis(0xFFFFFFFF); ​    // turn off autocalibrate on channel 1 - just as an example 
 + 
 +  Serial.begin(9600);​ 
 +  Serial.println("​DpSoilCapTempSensor V 1.0"​);​ 
 +  pinMode(led1,​ OUTPUT); 
 +  pinMode(led2,​ OUTPUT); 
 +  pinMode(led3,​ OUTPUT); 
 +  digitalWrite(led1,​ HIGH); 
 +  digitalWrite(led2,​ HIGH); 
 +  digitalWrite(led3,​ HIGH); 
 +  delay(10000);​ 
 +
 + 
 +void loop(void) { 
 + 
 +  byte broj = tSen.readTemperature(tempSensors,​ 16, NORMAL_SEARCH);​ 
 + 
 +  if(broj == 0 ) {  
 +    Serial.print("​\n\nNo 1-Wire Temperature Sensor Found on Digital Pin "); 
 +    Serial.println(ONE_WIRE_BUS);​ 
 +  } else { 
 +    for(byte i = 0; i < broj; i++) { 
 +      Serial.print("​\n\nTemperature sensor "); 
 +      Serial.print(i);​ 
 +      Serial.println("​."​);​ 
 + 
 +      Serial.print("​ROM Address: \t\t"​);​ 
 +      for(byte j=0; j<8;j++) { 
 +        if (tempSensors[i].dAddr[j] < 16) Serial.print("​0"​);​ 
 +        Serial.print(tempSensors[i].dAddr[j],​ HEX); 
 +      } 
 + 
 +      Serial.print("​\nSensor type: \t\t"​);​ 
 +      switch (tempSensors[i].dAddr[0]) { 
 +        case DS18B20MODEL:​ 
 +   Serial.println("​DS18B20"​);​ 
 +    break; 
 +        case DS1822MODEL:​ 
 +   Serial.println("​DS1822"​);​ 
 +   break; 
 +        case DS18S20MODEL:​ 
 +   Serial.println("​DS18S20/​DS1820"​);​ 
 +   break; 
 +      } 
 +     
 +      Serial.print("​Actual temperature \t"​);​ 
 +      Serial.print(tempSensors[i].dTemperature);​ 
 +      Serial.print("​ C ("); 
 +      Serial.print(getResolution(tempSensors[i].dAddr,​tempSensors[i].dTempReso),​DEC);​ 
 +      Serial.println("​ bit)"​);​ 
 +     
 +      Serial.print("​Alarm Low Temperature \t"​);​ 
 +      Serial.print(tempSensors[i].dMinAlarm,​2);​ 
 +      Serial.println("​ C"); 
 +     
 +      Serial.print("​Alarm High Temperature \t"​);​ 
 +      Serial.print(tempSensors[i].dMaxAlarm,​2);​ 
 +      Serial.println("​ C"); 
 + 
 +      if(i==0) {      
 +        if(tempSensors[i].dTemperature>​28) { 
 +          digitalWrite(led1,​ HIGH); 
 +        } else { 
 +          digitalWrite(led1,​ LOW); 
 +        } 
 +      } 
 +      if(i==1) {      
 +        if(tempSensors[i].dTemperature>​28) { 
 +          digitalWrite(led2,​ HIGH); 
 +        } else { 
 +          digitalWrite(led2,​ LOW); 
 +        } 
 +      } 
 +      if(i==2) {      
 +        if(tempSensors[i].dTemperature>​28) { 
 +          digitalWrite(led3,​ HIGH); 
 +        } else { 
 +          digitalWrite(led3,​ LOW); 
 +        } 
 +      } 
 +     
 +    } 
 +  } 
 +  
 +  for(byte j = 0; j <25; j++) { 
 +     long start = millis(); 
 +     long total1 =  cs_7_9.capSense(30);​ 
 +     long total2 =  cs_7_10.capSense(30);​ 
 +     long total3 =  cs_7_11.capSense(30);​ 
 +     long total4 =  cs_7_12.capSense(30);​ 
 +     
 +     ​Serial.print(millis() - start); ​       // check on performance in milliseconds 
 +     ​Serial.print("​\t"​); ​                   // tab character for debug windown spacing 
 + 
 +     ​Serial.print(total1); ​                 // print sensor output 1 
 +     ​Serial.print("​\t"​);​ 
 +     ​Serial.print(total2); ​                 // print sensor output 2 
 +     ​Serial.print("​\t"​);​ 
 +     ​Serial.print(total3); ​               // print sensor output 3 
 +     ​Serial.print("​\t"​);​ 
 +     ​Serial.println(total4); ​               // print sensor output 3mit data to serial por 
 +   
 +     ​delay(20);​ 
 +  } 
 +
 + 
 +byte getResolution(uint8_t* deviceAddress,​ uint8_t conf) { 
 +   
 +  if (deviceAddress[0] == DS18S20MODEL) return 9; // this model has a fixed resolution 
 + 
 +  switch (conf) { 
 +    case TEMP_12_BIT:​ 
 +      return 12; 
 +       
 +    case TEMP_11_BIT:​ 
 +      return 11; 
 +        
 +    case TEMP_10_BIT:​ 
 +      return 10; 
 +         
 +    case TEMP_9_BIT:​ 
 +      return 9; 
 + 
 +  } 
 +   
 +  return 0; 
 +}
 </​file>​ </​file>​
soil_sensor_project.txt · Last modified: 2016/09/01 14:17 (external edit)