help with sketch

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

Moderators: adafruit_support_bill, adafruit

Re: help with sketch

Postby tldr » Sun Nov 11, 2012 12:32 am

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.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 342
Joined: Thu Aug 30, 2012 12:34 am

Re: help with sketch

Postby jigsawnz » Sun Nov 11, 2012 1:25 am

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-yourself/153079-arduino-based-room-controller.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);
    }

  }
}
jigsawnz
 
Posts: 33
Joined: Mon Mar 12, 2012 9:17 pm
Location: New Zealand

Re: help with sketch

Postby nate21 » Sun Nov 11, 2012 12:03 pm

thank you thats what i need im having a hard time learning code
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

Postby nate21 » Sat Nov 17, 2012 7:53 pm

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

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

Re: help with sketch

Postby jigsawnz » Sat Nov 17, 2012 9:03 pm

Out of curiosity, whats your project. What are you building?
jigsawnz
 
Posts: 33
Joined: Mon Mar 12, 2012 9:17 pm
Location: New Zealand

Re: help with sketch

Postby nate21 » Sat Nov 17, 2012 9:41 pm

a egg incubator
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

Postby jigsawnz » Sat Nov 17, 2012 10:47 pm

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 Sat Nov 17, 2012 11:07 pm, edited 1 time in total.
jigsawnz
 
Posts: 33
Joined: Mon Mar 12, 2012 9:17 pm
Location: New Zealand

Re: help with sketch

Postby nate21 » Sat Nov 17, 2012 11:00 pm

i will try and find that information thanks
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Re: help with sketch

Postby nate21 » Sun Jan 27, 2013 5:44 pm

are you willing to share more information on your incubator
nate21
 
Posts: 25
Joined: Fri Nov 02, 2012 3:50 pm

Previous

Return to Arduino

Who is online

Users browsing this forum: franklin97355, Magician and 15 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]