Sensor monitoring

From Voidwarranties - Hackerspace Antwerp, Belgium
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Project |Current=Yes |Category=Electronics |Logo=LPG Sensor.jpg |Participants=Ivom, Jobj, Jeffrey |Locations=Waag A'dam, Den Bunker, Garden |Short description=Hooking up Nanode...")
 
m (Havn't seen/heard any activity on this for a long time. put it to non-active.)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{Project
 
{{Project
|Current=Yes
+
|Current=No
 
|Category=Electronics
 
|Category=Electronics
 
|Logo=LPG Sensor.jpg
 
|Logo=LPG Sensor.jpg
 
|Participants=Ivom, Jobj, Jeffrey
 
|Participants=Ivom, Jobj, Jeffrey
 
|Locations=Waag A'dam, Den Bunker, Garden
 
|Locations=Waag A'dam, Den Bunker, Garden
|Short description=Hooking up Nanodes and arduino's with gas, light, humidity, temp, modtion -sensors
+
|Short description=Hooking up Nanodes and arduino's with gas, light, humidity, temp and motion-sensors
 
}}
 
}}
 +
example code
 +
<pre>
 +
#define DHT11_PIN 0      // ADC0
 +
 +
byte read_dht11_dat(int a)
 +
{
 +
  byte i = 0;
 +
  byte result=0;
 +
  for(i=0; i< 8; i++)
 +
  {
 +
    while(!(PINC & _BV(a)));  // wait for 50us
 +
    delayMicroseconds(30);
 +
    if(PINC & _BV(a))
 +
      result |=(1<<(7-i));
 +
    while((PINC & _BV(a)));  // wait '1' finish
 +
    }
 +
    return result;
 +
}
 +
 +
 +
void setup()
 +
{
 +
    pinMode(13, OUTPUT);
 +
  pinMode(12, OUTPUT);
 +
  digitalWrite(13, HIGH);
 +
  digitalWrite(12, HIGH);
 +
  //DDRC |= _BV(DHT11_PIN);
 +
  //PORTC |= _BV(DHT11_PIN);
 +
  Serial.begin(9600);
 +
  Serial.println("Ready");
 +
}
 +
 +
void loop()
 +
{
 +
  for (int x = 0; x<1; x++){
 +
  DDRC |= _BV(x);
 +
  PORTC |= _BV(x);
 +
  byte dht11_dat[5];
 +
  byte dht11_in;
 +
  byte i;// start condition
 +
// 1. pull-down i/o pin from 18ms
 +
  PORTC &= ~_BV(x);
 +
  delay(18);
 +
  PORTC |= _BV(x);
 +
  delayMicroseconds(40);
 +
  DDRC &= ~_BV(x);
 +
  delayMicroseconds(40);
 +
 
 +
  dht11_in = PINC & _BV(x);
 +
  if(dht11_in)
 +
  {
 +
    Serial.println("dht11 start condition 1 not met");
 +
    return;
 +
  }
 +
  delayMicroseconds(80);
 +
  dht11_in = PINC & _BV(x);
 +
  if(!dht11_in)
 +
  {
 +
    Serial.println("dht11 start condition 2 not met");
 +
    return;
 +
  }
 +
 
 +
  delayMicroseconds(80);// now ready for data reception
 +
  for (i=0; i<5; i++)
 +
    dht11_dat[i] = read_dht11_dat(x);
 +
  DDRC |= _BV(x);
 +
  PORTC |= _BV(x);
 +
  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
 +
  if(dht11_dat[4]!= dht11_check_sum)
 +
  {
 +
    Serial.println("DHT11 checksum error");
 +
  }
 +
  Serial.print("Current humdity = ");
 +
  Serial.print(dht11_dat[0], DEC);
 +
  Serial.print(".");
 +
  Serial.print(dht11_dat[1], DEC);
 +
  Serial.print("%  ");
 +
  Serial.print("temperature = ");
 +
  Serial.print(dht11_dat[2], DEC);
 +
  Serial.print(".");
 +
  Serial.print(dht11_dat[3], DEC);
 +
  Serial.println("C  ");
 +
 
 +
  int analogTemp = analogRead(1);
 +
  Serial.println("Analog temp:");
 +
  Serial.print(analogTemp, DEC);
 +
  Serial.println("-----");
 +
 
 +
  int lpgValue = analogRead(2);
 +
  Serial.println("LPG:");
 +
  Serial.print(lpgValue, DEC);
 +
  Serial.println("-----");
 +
  delay(2000); 
 +
  }
 +
 +
}
 +
 +
</pre>

Latest revision as of 10:43, 23 August 2013


Sensor monitoring
What:
Hooking up Nanodes and arduino's with gas, light, humidity, temp and motion-sensors
LPG Sensor.jpg
Participants:
Ivom, Jobj, Jeffrey
Category:
Electronics
Locations:
Waag A'dam, Den Bunker, Garden

example code

#define DHT11_PIN 0      // ADC0

byte read_dht11_dat(int a)
{
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++)
  {
    while(!(PINC & _BV(a)));  // wait for 50us
    delayMicroseconds(30);
    if(PINC & _BV(a)) 
      result |=(1<<(7-i));
    while((PINC & _BV(a)));  // wait '1' finish
    }
    return result;
}


void setup()
{
    pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  //DDRC |= _BV(DHT11_PIN);
  //PORTC |= _BV(DHT11_PIN);
  Serial.begin(9600);
  Serial.println("Ready");
}
	
void loop()
{
  for (int x = 0; x<1; x++){
  DDRC |= _BV(x);
  PORTC |= _BV(x);
  byte dht11_dat[5];
  byte dht11_in;
  byte i;// start condition
	 // 1. pull-down i/o pin from 18ms
  PORTC &= ~_BV(x);
  delay(18);
  PORTC |= _BV(x);
  delayMicroseconds(40);
  DDRC &= ~_BV(x);
  delayMicroseconds(40);
  
  dht11_in = PINC & _BV(x);
  if(dht11_in)
  {
    Serial.println("dht11 start condition 1 not met");
    return;
  }
  delayMicroseconds(80);
  dht11_in = PINC & _BV(x);
  if(!dht11_in)
  {
    Serial.println("dht11 start condition 2 not met");
    return;
  }
  
  delayMicroseconds(80);// now ready for data reception
  for (i=0; i<5; i++)
    dht11_dat[i] = read_dht11_dat(x);
  DDRC |= _BV(x);
  PORTC |= _BV(x);
  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
  if(dht11_dat[4]!= dht11_check_sum)
  {
    Serial.println("DHT11 checksum error");
  }
  Serial.print("Current humdity = ");
  Serial.print(dht11_dat[0], DEC);
  Serial.print(".");
  Serial.print(dht11_dat[1], DEC);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(dht11_dat[2], DEC);
  Serial.print(".");
  Serial.print(dht11_dat[3], DEC);
  Serial.println("C  ");
  
  int analogTemp = analogRead(1);
  Serial.println("Analog temp:");
  Serial.print(analogTemp, DEC);
  Serial.println("-----");
  
  int lpgValue = analogRead(2);
  Serial.println("LPG:");
  Serial.print(lpgValue, DEC);
  Serial.println("-----");
  delay(2000);  
  }

}

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
Content Creation
Belgian Spaces