help with sketch

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 4:50 pm

help with sketch

Post by nate21 »

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

// 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);
    }

  }
}

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: help with sketch

Post by tldr »

there seems to be an extraneous parenthesis in the declaration of tempset.

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

Re: help with sketch

Post by nate21 »

i removed the parenthesis it still want compile

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: help with sketch

Post by tldr »

probably got a different error message, now, though.

Code: Select all

// 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.

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: help with sketch

Post by tldr »

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.

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

Re: help with sketch

Post by nate21 »

Code: Select all

// 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 4:50 pm

Re: help with sketch

Post by nate21 »

i cant determind where you started counting the lines i installed dht library still no change

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: help with sketch

Post by tldr »

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

#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

#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

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.

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

Re: help with sketch

Post by nate21 »

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 4:50 pm

Re: help with sketch

Post by nate21 »

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

User avatar
arctic_eddie
 
Posts: 233
Joined: Tue Feb 28, 2012 6:01 pm

Re: help with sketch

Post by arctic_eddie »

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

int (tempset=85, tempreset=83;
----^----

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

Re: help with sketch

Post by nate21 »

still cant get it to compile

User avatar
arctic_eddie
 
Posts: 233
Joined: Tue Feb 28, 2012 6:01 pm

Re: help with sketch

Post by arctic_eddie »

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.

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

Re: help with sketch

Post by nate21 »

ok still learning syntax

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

Re: help with sketch

Post by nate21 »

im still getting a error on line 27 int TempSet=85, tempreset=83; the error is expected primary expression before int

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”