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.
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: help with sketch

Post by tldr »

nate21 wrote:im still getting a error on line 27 int TempSet=85, tempreset=83; the error is expected primary expression before int
that message usually indicates an improperly terminated statement in a previous line. that would probably be the fault of your incomplete declarations of the lcd and temp sensor.

User avatar
jigsawnz
 
Posts: 180
Joined: Mon Mar 12, 2012 10:17 pm

Re: help with sketch

Post by jigsawnz »

this compiles but wont work. Pin 8 and pin 4 are being used for activating relays and for the LCD. You will need to change the Pins around.

I knew the code looked familiar. http://www.420magazine.com/forums/do-yo ... oller.html I used the same code when I first tried to build an egg incubator.

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 tempcontpin 8   //temp output to control
#define humcontpin 4    //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 dht(DHTPIN, DHTTYPE);

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

thank you thats what i need im having a hard time learning code

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

Re: help with sketch

Post by nate21 »

Code: Select all

i am using pin 8 to control temp and pin 9 to control humidity im using leds to test i can only get the outputs to turn on if i lower tempset and humset down very low i hope im posting the code corectly

 //4.5 Adding output, Relays etc. with hysterisis

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

#define DHTPIN 7    // what pin we're connected to
#define tempcontpin 8   //temp output to control
#define humcontpin 9    //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(12,11,10,5,4,3,2);
int backLight = 13;
DHT dht(DHTPIN, DHTTYPE);

//here's where the temp and hum setpoints are changed
int tempset=99, tempreset=98;
int humset=99, humreset=98;
int tmem=0, hmem=0;

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

  dht.begin();
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH);
  
  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(10,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);         
        
    if (h>maxH)  {
      maxH=h;
    }  //check for max hum
    if (h<minH)  {
      minH=h;
    }  //check for min hum
    lcd.setCursor(0,1);
    lcd.print("tempset"); 
    lcd.print(tempset);
    lcd.write(B11011111);
    lcd.print("humset"); 
    lcd.print(humset);
    lcd.print("%");

    //Here's the section for control with hysterisis

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

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

  }
}

User avatar
jigsawnz
 
Posts: 180
Joined: Mon Mar 12, 2012 10:17 pm

Re: help with sketch

Post by jigsawnz »

Out of curiosity, whats your project. What are you building?

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

Re: help with sketch

Post by nate21 »

a egg incubator

User avatar
jigsawnz
 
Posts: 180
Joined: Mon Mar 12, 2012 10:17 pm

Re: help with sketch

Post by jigsawnz »

I've a work in progress. Relays are easy to control but the problem is the amount they switch on and off. Depending on the settings, insulation of the box, air flow and heat source, this can happen several times a minute. Even if it was every minute for 21 days thats 30,2400 times its switches on and off. They contacts will wear out.

There is a PID library for arduino that you use with Mosfets. Thats what I am using now to avoid that problem.
Last edited by jigsawnz on Sun Nov 18, 2012 12:07 am, edited 1 time in total.

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

Re: help with sketch

Post by nate21 »

i will try and find that information thanks

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

Re: help with sketch

Post by nate21 »

are you willing to share more information on your incubator

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

Return to “Arduino”