The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

help with sketch

by nate21 on Fri Nov 09, 2012 10:07 pm

can anyone help with this sketch i dont know about programing yet i have to buy more books i get error temp set was not declared in this scope

[Edit - moderator - please use the 'code' button when submitting code]
Code: Select all | TOGGLE FULL SIZE
// Lesson 4.5 Adding output, Relays etc. with hysterisis

#include "DHT.h"
#include <LiquidCrystal.h>
#include <Wire.h>

#define DHTPIN 2     // what pin we're connected to
#define tempcontpin8   //temp output to control
#define humcontpin4    //humidity output to control

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

int maxF=0, minF=212;
int maxH=0, minH=100;
LiquidCrystal lcd(8,9,4,5,6,7,
dht(DHTPIN2, DHTTYPE(22,

//here's where the temp and hum setpoints are changed
int (tempset=85, tempreset=83;
int humset=55, humreset=53;
int tmem=0, hmem=0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();

  lcd.begin(20, 4); // Set the display to 20 columns and 4 rows

  lcd.clear();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float tF= (t* 1.8) +32; //convert to Farenheit

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  }
  else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print("Temperature: ");
    Serial.print(tF);
    Serial.println(" *F"); 
    lcd.setCursor(0,0);
    lcd.print("Temp ");
    lcd.print(tF);
    lcd.write(B11011111); // print degree symbol
    lcd.print("F ");
    lcd.setCursor(20,0);
    lcd.print("Hum ");
    lcd.print(h);
    if (tF>maxF) {
      maxF=tF;
    }  //check for max temp
    if (tF<minF) {
      minF=tF;
    }  //check for min temp
    lcd.setCursor(0,1);
    lcd.print("H=");
    lcd.print(maxF);
    lcd.write(B11011111);
    lcd.print("F L=");
    lcd.print(minF);
    lcd.write(B11011111);
    lcd.print("F ");

    if (h>maxH)  {
      maxH=h;
    }  //check for max hum
    if (h<minH)  {
      minH=h;
    }  //check for min hum
    lcd.setCursor(20,1);
    lcd.print("max=");
    lcd.print(maxH);
    lcd.print(" min=");
    lcd.print(minH);


    //Here's the section for control with hysterisis

   
    if (tempreset<=tF && tF<=tempset && tmem==1) {
      digitalWrite (8, HIGH);
    }
     if (tF>=tempset) {
      tmem==1,
      digitalWrite (8, HIGH);
    }
     if (tF<tempreset)  {
      tmem==0,
      digitalWrite (8, LOW);
    }

   
    if (humreset<=h && h<=humset && hmem==1) {
      digitalWrite (4, HIGH);
    }
     if (h>humset) {
      hmem==1,
      digitalWrite (4, HIGH);
    }
    if (h<humreset) {
      hmem==0,
      digitalWrite (4, LOW);
    }

  }
}
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by tldr on Fri Nov 09, 2012 10:22 pm

there seems to be an extraneous parenthesis in the declaration of tempset.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: help with sketch

by nate21 on Fri Nov 09, 2012 11:04 pm

i removed the parenthesis it still want compile
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by tldr on Fri Nov 09, 2012 11:16 pm

probably got a different error message, now, though.

Code: Select all | TOGGLE FULL SIZE
// it is very difficult to read code not enclosed in code tags,


paste your code into the message window, then select it and click the code button fifth from the left at the top of the window.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: help with sketch

by tldr on Fri Nov 09, 2012 11:28 pm

line 3 - looks like you have not installed the library for your temp sensor.

lines 8-9 - you have a couple of probably incorrectly written defines.

lines 23-24 - your declarations for the display and temp sensors are not complete c++ statements.

line 27 - extraneous parenthesis.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: help with sketch

by nate21 on Fri Nov 09, 2012 11:36 pm

Code: Select all | TOGGLE FULL SIZE
// Lesson 4.5 Adding output, Relays etc. with hysterisis

#include "DHT.h"
#include <LiquidCrystal.h>
#include <Wire.h>

#define DHTPIN 2     // what pin we're connected to
#define tempcontpin8   //temp output to control
#define humcontpin4    //humidity output to control

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

int maxF=0, minF=212;
int maxH=0, minH=100;
LiquidCrystal lcd(8,9,4,5,6,7,
dht(DHTPIN2, DHTTYPE(22,

//here's where the temp and hum setpoints are changed
int (tempset=85, tempreset=83;
int humset=55, humreset=53;
int tmem=0, hmem=0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();

  lcd.begin(20, 4); // Set the display to 20 columns and 4 rows

  lcd.clear();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float tF= (t* 1.8) +32; //convert to Farenheit

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  }
  else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print("Temperature: ");
    Serial.print(tF);
    Serial.println(" *F"); 
    lcd.setCursor(0,0);
    lcd.print("Temp ");
    lcd.print(tF);
    lcd.write(B11011111); // print degree symbol
    lcd.print("F ");
    lcd.setCursor(20,0);
    lcd.print("Hum ");
    lcd.print(h);
    if (tF>maxF) {
      maxF=tF;
    }  //check for max temp
    if (tF<minF) {
      minF=tF;
    }  //check for min temp
    lcd.setCursor(0,1);
    lcd.print("H=");
    lcd.print(maxF);
    lcd.write(B11011111);
    lcd.print("F L=");
    lcd.print(minF);
    lcd.write(B11011111);
    lcd.print("F ");

    if (h>maxH)  {
      maxH=h;
    }  //check for max hum
    if (h<minH)  {
      minH=h;
    }  //check for min hum
    lcd.setCursor(20,1);
    lcd.print("max=");
    lcd.print(maxH);
    lcd.print(" min=");
    lcd.print(minH);


    //Here's the section for control with hysterisis

   
    if (tempreset<=tF && tF<=tempset && tmem==1) {
      digitalWrite (8, HIGH);
    }
     if (tF>=tempset) {
      tmem==1,
      digitalWrite (8, HIGH);
    }
     if (tF<tempreset)  {
      tmem==0,
      digitalWrite (8, LOW);
    }

   
    if (humreset<=h && h<=humset && hmem==1) {
      digitalWrite (4, HIGH);
    }
     if (h>humset) {
      hmem==1,
      digitalWrite (4, HIGH);
    }
    if (h<humreset) {
      hmem==0,
      digitalWrite (4, LOW);
    }

  }
}
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by nate21 on Sat Nov 10, 2012 9:56 am

i cant determind where you started counting the lines i installed dht library still no change
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by tldr on Sat Nov 10, 2012 12:49 pm

i used the line numbers displayed at the bottom left of the arduino ide window. they start counting at the first line of your sketch.

these two lines define tempcontpin8 & humcontpin4 as nothing. this is usually not what you want.

Code: Select all | TOGGLE FULL SIZE
#define tempcontpin8   //temp output to control
#define humcontpin4    //humidity output to control


it is customary to use caps for defined constants. assuming that you want the outputs for you temperature and humidity control on pins 8 and 4, respectively, what you probably meant was

Code: Select all | TOGGLE FULL SIZE
#define TEMPCONTPIN 8   //temp output to control
#define HUMCINTPIN 4    //humidity output to control


these two lines are not complete c++ statements.

Code: Select all | TOGGLE FULL SIZE
LiquidCrystal lcd(8,9,4,5,6,7,
dht(DHTPIN2, DHTTYPE(22,


since i'm not familiar with the libraries, i won't offer a correction, but it does look like you've got a pin usage conflict between your temp and humidity outputs and your lcd.

if you did install the library correctly it should have eliminated at least the first couple of errors.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: help with sketch

by nate21 on Sat Nov 10, 2012 1:12 pm

thanks for the help i didn't notice the pin conflict i have this book getting started with sketches but i still cant figure out why im getting the error on line 27 tempset was not declared in this scope i will change the pin arrangement
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by nate21 on Sat Nov 10, 2012 1:37 pm

i just checked the library and i looks like the dht folder is installed corectly i downloaded it from here https://github.com/adafruit/DHT-sensor-library
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by Arctic_Eddie on Sat Nov 10, 2012 2:22 pm

You have tempset preceded by an unwanted and unpaired '('. The compiler doesn't know what to do.

int (tempset=85, tempreset=83;
----^----
Arctic_Eddie
 
Posts: 208
Joined: Tue Feb 28, 2012 5:01 pm
Location: St. Petersburg, FL

Re: help with sketch

by nate21 on Sat Nov 10, 2012 4:17 pm

still cant get it to compile
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by Arctic_Eddie on Sat Nov 10, 2012 5:04 pm

You have several more missing ) just above and a missing ;. There also several places where a , has replaced a ;. You need to proof read the entire sketch for syntax errors.
Arctic_Eddie
 
Posts: 208
Joined: Tue Feb 28, 2012 5:01 pm
Location: St. Petersburg, FL

Re: help with sketch

by nate21 on Sat Nov 10, 2012 6:16 pm

ok still learning syntax
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

by nate21 on Sat Nov 10, 2012 7:37 pm

im still getting a error on line 27 int TempSet=85, tempreset=83; the error is expected primary expression before int
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm