Show Posts
Pages: 1 ... 4 5 [6] 7
76  Using Arduino / Programming Questions / If trigger statement not working on Uno board on: June 08, 2011, 06:45:35 pm
I cobbled together some different code for a DHT11 sensor and a CO2meter.com k-22 (Thanks to Andrew at CO2 sensor who wrote the I2C code.)sensor. I put in an If statement, which turns co2 on at 1300, and off at 1500. I used this same code reading the DHT11 sensor to turn fans on for temp or humidity and that works fine... but for some reason, pin 13 LED is just stays dimly lit and reads 1.4V, instead of 5V. The only part that doesn't work is,

Quote
    // CO2 Control
    if (co2Value < co2ON) // Set CO2 to turn ON
    {
      digitalWrite(co2Pin, HIGH);
    }
    else if (co2Value > co2OFF) // Set CO2 to turn OFF
    {
      digitalWrite(co2Pin, LOW);
    }

The rest of the code including the temp/humidity triggers work fine. Any help/hints would be awesome!

Quote
#include <Wire.h>
#include <dht11.h>
#define DHT11PIN 2 // Data Pin on Arduino
dht11 DHT11;

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

int co2Addr = 0x68;
int dehumidPin = 11;
int aircoolerPin = 12;
int co2Pin = 13;
int co2ON = 1300;  // Set the low co2 PPM trigger
int co2OFF = 1500; // Set the high co2 PPM trigger
int rhHIGH = 50;   // Set the high humidity trigger (when to turn dehumidifier ON)
int rhLOW = 40;    // Set the low humidity trigger (When to turn dehumidifier OFF)
int tHIGH = 86;    // Set the high temperature trigger (When to turn cooler ON)
int tLOW = 83;     // Set the low temperature trigger (When to turn cooler OFF)

void setup() {
  Serial.begin(9600);
  Wire.begin ();
  pinMode(aircoolerPin, OUTPUT);
  pinMode(dehumidPin, OUTPUT);
  Serial.println("Enivronmental Control Unit");
}
  int readCO2()
{
  int co2_value = 0;

  Wire.beginTransmission(co2Addr);
  Wire.send(0x22);
  Wire.send(0x00);
  Wire.send(0x08);
  Wire.send(0x2A);
  Wire.endTransmission();

  delay(10);

  Wire.requestFrom(co2Addr, 4);
  byte i = 0;
  byte buffer[4] = {
    0, 0, 0, 0  };

  while(Wire.available())
  {
    buffer = Wire.receive();
    i++;
  }

  co2_value = 0;
  co2_value |= buffer[1] & 0xFF;
  co2_value = co2_value << 8;
  co2_value |= buffer[2] & 0xFF;
  byte sum = 0; //Checksum Byte
  sum = buffer[0] + buffer[1] + buffer[2]; //Byte addition utilizes overflow

  if(sum == buffer[3])
  {

    return co2_value;
  }
  else
  {

    return 0;
  }
}
void loop() {
  int co2Value = readCO2();
  if(co2Value > 0)
  {
    Serial.print("CO2 Value: ");
    Serial.print(co2Value);
  }
  else
  {
    Serial.print("Checksum/Com Fail");
  }
  {
// The following is for DHT11 only
    int chk = DHT11.read(DHT11PIN);

    Serial.print("   DHT11: ");
    switch (chk)
    {
    case 0:
      Serial.print("OK");
      break;
    case -1:
      Serial.print("Checksum error");
      break;
    case -2:
      Serial.print("Time out error");
      break;
    default:
      Serial.print("Unknown error");
      break;
    }

    Serial.print("   Humidity (%): ");
    Serial.print((float)DHT11.humidity, 1); 

    Serial.print("    Temperature (F): ");
    Serial.println(Fahrenheit(DHT11.temperature), 1);
// The following is for setting Environmental Triggers
    // Temperature Control
    if (Fahrenheit(DHT11.temperature) > tHIGH)
    {
      digitalWrite(aircoolerPin, HIGH);
    }
    else if (Fahrenheit(DHT11.temperature) <= tLOW)
    {
      digitalWrite(aircoolerPin, LOW);
    }

    // Humidity Control   
    if (DHT11.humidity > rhHIGH)
    {
      digitalWrite(dehumidPin, HIGH);
    }
    else if (DHT11.humidity <= rhLOW)
    {
      digitalWrite(dehumidPin, LOW);
    }

    // CO2 Control
    if (co2Value < co2ON) // Set CO2 to turn ON
    {
      digitalWrite(co2Pin, HIGH);
    }
    else if (co2Value > co2OFF) // Set CO2 to turn OFF
    {
      digitalWrite(co2Pin, LOW);
    }

    delay(2000);
  }
}
77  Using Arduino / Installation & Troubleshooting / Re: Feedback issues from my power supply on: May 08, 2011, 11:37:57 pm
I always understood the general role of grounds, but I had this misguided thought in my head that you had to keep the grounds of different voltages separated and I see where I was wrong with that thinking now.

Now, should I connect this Tip120 Darlington to some type of heatsink via the tab with the hole in it? Or is it small enough that I can just solder it down on a breadboard? Basically, what's the best/usual way to mount these things?
78  Using Arduino / Installation & Troubleshooting / Re: Feedback issues from my power supply on: May 08, 2011, 08:50:51 pm
Thanks Mark.

I followed this guys tutorial and just built this circuit using a diode, resistor and a Tip120 and using my PC power supply for the 5V signal and the 12V and she works fine. I would still like to know why my previous setup with the 5V relay and the 12V relay made the Arduino go nucking futs. I'd rather use transistors anyway, as it reduces the cost and the size of the total package.

Now just to clarify this... I connect one of the Arduino ground pins to the 12V ground, right? If so, why? Is that so the transistor has a "larger" ground source to go to?

I see how transistors work now... Basically when you energize the Base, it opens a gate which allows current to flow from the emitter to the collector. But in this case, it's a ground current. So basically it's just a little switch, right? Could I connect the emitter to a + voltage source and then have a higher voltage come out of the collector? I'm going to read this site tomorrow, http://www.technologystudent.com/elec1/transis1.htm -- but if you care to chime on my questions, feel free.

Thanks for your help!

P.S. I come from an aviation background, specifically being a pilot, and since you let me in on the little secret of how electronics work (smoke lol) I'll let you in on the secret of how airplanes stay in the sky... Money and coffee. lol
79  Using Arduino / Installation & Troubleshooting / Re: Feedback issues from my power supply on: May 08, 2011, 07:38:11 pm
Mark, I'll try those suggestions. I was also going to power the Arduino using a 9v battery, thus eliminating the USB connection and see if the program keeps running (see if the Tx light keeps blinking as it should).

I tried using a TIP120, and I hooked it up as per the instructions but the Collector pin kept going up to like .7V and then dropping back to zero, then back up to .7v then dropping to zero. Any thoughts on that? I'm new to electronics and figured the easiest way would be to use these 5V relays to trigger 12V relays until I learned more and could do a better setup. I set the transistor up as per the instructions here, http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads#toc6

Except I skipped the pot and wired the base to a pin set to high on the arduino, connected the emitter to arduino ground and the collector pin was giving me that rise and fall to .7v... Any thoughts?
80  Using Arduino / Installation & Troubleshooting / Re: Feedback issues from my power supply on: May 08, 2011, 07:14:29 pm
No, I haven't. So I should take the -12vdc of the PSU and tie it to the -5v ground of the Arduino?

I'm not sure why that would do anything, but it's worth a try. Like I said before, the 12VDC PSU runs 12V through the digital relay in order to come back and trip a 12V relay... So the only possible way it would have back to the Arduino is through the relay, and I shouldn't be getting interference from a 12V source when this thing is rated to switch 30VDC and 250VAC, etc....

** Tied the grounds together and even put a diode on the 12v relay to stop any interference from coming back... still no worky lol

Turn the PSU off, unplug the USB cable and plug it back in and then bam Com3 comes back to life, what the hell haha

Aaaaand, turn the PSU back on with the Arduino running and Com3 working fine, dun dun dun! One more transmission is sent to the Serial Monitor and then after that it goes dead... Relays keep clicking on schedule but the Tx light on the arduino stops blinking and Com3 goes dark.
81  Using Arduino / Installation & Troubleshooting / Feedback issues from my power supply on: May 08, 2011, 06:53:26 pm
Hey guys, I programmed my Arduino to act as a timer and temperature control device. All my tests were running fine, until I hooked an external power supply up.

My Arduino powers and trips a seeedstudio.com Electronic Brick (digital) 5v relay, relay is the He Li Shun HLS8L-DC5V-S-C

I'm using a PC power supply to send 12VDC into the comm. side of the relay, and then a wire comes out other side of relay to a 12VDC 30amp automotive style relay. So basically, I'm using the Arduino to trigger the 5VDC relay to relay 12VDC to trigger the larger relay. The larger automotive relay is grounded via the power supply, and the coil is also energized how I just described above.

Anyway, the weird thing is that when I have the PC power supply turned on, in order to make the 12V relay trigger, the Arduino stops communicating with my PC. Anything running in the serial monitor stops, and if I try to connect to the Arduino to upload an altered code, the IDE gives me an error saying that Com3 port is busy being used by another device/program! I should mention that the Arduino is being powered by my PC through the USB cable, the 12VDC PC power supply is only being used to trigger the 12V relay and nothing else. Funny thing is, if I have the Arduino running the program and then turn the PSU on, it keeps working fine... But if I unplug the Arduino and then plug it back in, bam won't work!

This 5V relay I am using supports up to 250VAC @ 7amps, so I really doubt that my 12VDC PSU is screwing with it... but it almost does seem like some kind of feedback issue. Like I said, the code keeps running but any communication with my PC, trying to upload new code to the Arduino or use the Serial Monitor, is stopped.

Any thoughts?


Quote
Binary sketch size: 6074 bytes (of a 32256 byte maximum)
processing.app.SerialException: Serial port 'COM3' already in use.  Try quiting any programs that may be using it.
   at processing.app.Serial.<init>(Serial.java:144)
   at processing.app.Serial.<init>(Serial.java:76)
   at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:75)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:93)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:56)
   at processing.app.Sketch.upload(Sketch.java:1603)
   at processing.app.Sketch.exportApplet(Sketch.java:1568)
   at processing.app.Sketch.exportApplet(Sketch.java:1524)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2293)
   at java.lang.Thread.run(Thread.java:619)
processing.app.debug.RunnerException: Serial port 'COM3' already in use.  Try quiting any programs that may be using it.
   at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:99)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:93)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:56)
   at processing.app.Sketch.upload(Sketch.java:1603)
   at processing.app.Sketch.exportApplet(Sketch.java:1568)
   at processing.app.Sketch.exportApplet(Sketch.java:1524)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2293)
   at java.lang.Thread.run(Thread.java:619)



** Ok, that's weird. I just double checked all my connections, switched the AC plug on the power supply to a different outlet, one that doesn't share the same power strip my PC is connected to, then I disconnected USB cable from Arduino and from my PC, then I turned the PSU on, then plugged the Arduino side of the USB cable in and then the PC side...

Everything worked fine for about a minute, then the com3 usb port stopped responding, the readout on the serial monitor stopped and now when I try to connect to the Arduino it gives me the Com3 error again lol. The program is still running, it just won't let me connect to the arduino lol.
82  Using Arduino / Programming Questions / Re: Arduino and limitations for greenhouse control on: April 18, 2011, 12:24:58 am
I see what you mean, Nick, thanks. I'm going to get a lot of the greenhouse construction done tomorrow so I'll have more time to just focus on code. I'm going to tinker around with this for the next day or two and see what I can figure out and I'll report back here.
83  Using Arduino / Programming Questions / Re: Arduino and limitations for greenhouse control on: April 17, 2011, 11:13:16 pm
So instead of delay() I measure the time with millis()... Mmm... Can I use an RTC instead? e.g. "check temp every minute" based off the RTC time? I had been fooling around with TimedAction/TimeAlarm library and then I discovered that because you use Alarm.delay() it stops you from being able to do multiple functions at the same time. For instance, I could make an LED stay on and have another LED flash at a set interval, but if 2 events had to happen simultaneously then I ran into the issue of the first event having to be executed then the next event would happen. Then I found EventFuse and that works wonderfully for my timed events and allows everything to keep plugging away independently. 

How do I go about putting all of this into one sketch then? Is there a "proper" way or a less confusing way of packing this all in to one sketch?

I think the problem that I am really running into here is that I'm having to design all of the aspects of this greenhouse setup, from the horticulture side to the electronics control side and I'm just getting stupidly over-whelmed with all the aspects of this project.

The other thing that is really boggling my mind is what I just said, understanding how to put all of this different code into one sketch and it be organized and functional, rather than everything just copy/pasted and looking mighty confusing. Basically, just like we use library's to help simplify the code we write, is there some way of making several different sketches, a sketch for temp control, a sketch for timing control, etc, and then plop them all together?

I know I have a lot of questions and I appreciate the help and once I get my understanding sorted out better then I promise not to be such a pain smiley

thanks for the clarity

-steve
84  Using Arduino / Programming Questions / Re: Arduino and limitations for greenhouse control on: April 17, 2011, 10:37:42 pm
Mmmm... Looking at the code at the end of that page, won't the delay(1000); screw with my other control code? Or am I missing the fundamentals on how to combine different types of code?
85  Using Arduino / Programming Questions / Arduino and limitations for greenhouse control on: April 17, 2011, 10:10:36 pm
Hey guys, I am still trying to figure everything out, and I'm sure some of you have seen my previous posts...

What I need to do right now is:

control temperature via water pump on/off
control timing of lights/watering system
control co2 levels via 12vdc solenoid on a co2 tank

This is a setup I'm trying to do for a family member and also to see just how "scientific" I can make the grow environment, which is my own pet-project in this.

I'm using EventFuse library with msTimer to control the timing portion. I cannot have delays holding my code up while other things are trying to happen, which is the biggest
issue I am running in to with the thermostat setup.

I'm starting to think that I may need to use 2 or more Arduino's to do this right... 1 for timing, 1 for temp control/co2 control.

I could really use some help here, as I'm trying to learn the programming and the electronics at the same time and I'm starting to lose my mind with the more complicated items, like the thermostat setup.

If I need to use more than 1 Arduino (I have an Uno) for this, is there a more powerful MCU that would be able to do everything in one package? I'm really new to all this smiley-sad

Thanks
86  Using Arduino / Programming Questions / Re: TimeAlarms questions... on: April 13, 2011, 11:05:43 pm
I tried that idea with no success... It's weird tho cuz when I type Alarm.timerOnce() none of it shows up in orange... I'm thinking of using this library, TimedAction for the pumps and Alarm.alarmRepeat() for the lights.

Still need to figure out how to adjust the thermostat temp by the time of day... Any advice?
87  Using Arduino / Programming Questions / Re: TimeAlarms questions... on: April 13, 2011, 09:01:56 pm
John, I see what you mean about using Alarm.timeronce... Nice idea.
88  Using Arduino / Programming Questions / Re: TimeAlarms questions... on: April 13, 2011, 07:23:32 pm
How would I go about making the pumpPin(s) stay HIGH for x amount of time then? I just figured out that the problem is the Alarm.delay...

John, you mean set a whole new timer for the off functions?

so like,

Quote
Alarm.timerRepeat(10, Pump1ON);
Alarm.timerRepeat(2, Pump1OFF);

void Pump1ON(){
digitalWrite(pumpPin1, HIGH);
}

void Pump1OFF(){
digitalWrite(pumpPin1, LOW);
}

??

89  Using Arduino / Programming Questions / TimeAlarms questions... on: April 13, 2011, 06:57:03 pm
Quote
/*
* TimeAlarmExample.pde
*/

#include <Time.h>
#include <TimeAlarms.h>

int hidPin = 13;
int pumpPin1 = 10;
int pumpPin2 = 11;





void setup()
{
 Serial.begin(9600);   
Serial.println("Timer Test");
 Serial.println();
 
 setTime(8,29,50,1,1,10); // set time to current time/date - disregard actual time, I know it's wrong.

 
 Alarm.alarmRepeat(8,30,0, LightOn);  // Set time to come ON
 Alarm.alarmRepeat(8,35,0, LightOff); // Set time to shut OFF       
 Alarm.timerRepeat(90, PumpOn1);      // Timer for every 90s
 Alarm.timerRepeat(90, PumpOn2);
 
 pinMode(hidPin, OUTPUT); 
 pinMode(pumpPin1, OUTPUT);
 pinMode(pumpPin2, OUTPUT);

}



void LightOn()
{
 digitalWrite(hidPin, HIGH);
 Alarm.delay(0);
 Serial.println("HID ON");
 Alarm.delay(0);
}

void LightOff()
{
  digitalWrite(hidPin, LOW);
  Alarm.delay(0);
  Serial.println("HID OFF");
  Alarm.delay(0); 
}

void PumpOn1(){
  digitalWrite(pumpPin1, HIGH);
  Serial.println("Pump 1 ON");
  Alarm.delay(2000);           // Pump stays on for 2 seconds
  digitalWrite(pumpPin1, LOW);
  Serial.println("Pump 1 OFF");
 
}
 
  void PumpOn2(){
  digitalWrite(pumpPin2, HIGH);
  Serial.println("Pump 2 ON");
  Alarm.delay(2000);
  digitalWrite(pumpPin2, LOW);
  Serial.println("Pump 2 OFF");
 
}

void loop(){
  Alarm.delay(0);
}


Ok, so I've been screwing around with the above code for about an hour now. I got everything to work, and I'm making progress, but for some reason I cannot get pumpPin1 and pumpPin2 to stay HIGH at the same time. hidPin will stay HIGH with one of the pumpPins also HIGH, but pumpPin1 and pumpPin2 will not go HIGH together. I'm using LEDs to test this all out, but later on I will be using relays to trigger a light to stay on for 18hrs, and then using pumpPin1 and pumpPin2 to control water pumps via relays, etc.

This is for a greenhouse project (legal lol) and the pumps are used to water the plants... It's not really an issue that the pins aren't both activated at the same time, but I'd like to know what I need to do to make them come on at the same time. I think I need to use the millis() command or whatever that is... or is there a different way? I will also be putting more code in, so I can't have processes screwing with each other.

I will lay out what I need to control,

1 or possibly 2 lights on different timing schedules, 1 for 18hrs on/6 off the other could be for 20hrs on 4/off, etc

3 separate watering pumps which will need to come on once every minute or two for a few seconds each

Temperature control by using a DHT11 temp/humidity sensor, would like to set varying temps throughout the day, slowly warming when the lights turn on, like, 6am temp 72F (low temp), 9am temp 75F, etc

CO2 injection using a sensor from CO2meter.com, keeping the CO2 levels in a set range by using a solenoid valve on a CO2 tank, using either a photoresistor or timer method to allow solenoid to work during light hours but stay OFF during a lights off period.

I will be adding more features later, as I learn more, but right now I only need to code the above items.

Any help on my timer code/questions, how to improve it, etc, would be greatly appreciated, and then any questions I have about the other items I can address at a later time; baby steps smiley

Thanks so much guys!
90  Using Arduino / Programming Questions / Re: noob here! on: April 10, 2011, 11:49:11 am
lol Nick, be easy on the me smiley

Thanks for the help, I realize that my code was total BS, but like I said, I'm 100% new to this and that is the first bit that I tried to 'create' on my own.

Nick, now that I see how you did it, that is the way I "thought" of doing it, but wasn't sure how. It's like learning a new language, I know some words, but I don't know how to construct
them into a coherent sentence just yet.

When you say 'const int iterations = 5', that means that you are setting the word 'iterations' as a constant numerical (integer) value of 5, right?

And 'count' always sets the count back to 0 for each 'for-loop', right?

Can you guys recommend any articles online or a specific book that might help me get the fundamentals? I have the Arduino Cookbook, and it's a pretty good book, but is there anything else specifically that will help teach me the foundation of programming the Arduino? I seem to get lost not on the "how" this works, but more on understanding the when and why you use certain commands, etc.  (I'm currently reading through the tutorial I found on ladyada.net)

Thanks so much!


** I'm going to put this in for my clarification, as I think I'm starting to gain more understanding of the code that you posted, Nick.

for (count = 0; count < iterations; count++) \\ This means that each time the loop comes to the 'for' statement, that the count is reset to 0 (which is why the loop function continuously loops), when the 'count' is less than the 'iterations' which we set as a constant value of '5', add (count++) till the count is = to the set number of iterations.

Did I say that right?

So then, just as a test to clarify my understanding I went and did something confusing, or stupid as you guys might say lol...

int zero;
for (zero = 0; zero < iterations; zero++)

I ran that and it still works just as count does, but the reason we don't do this is because it's confusing... zero does = 0, no duh lol, and now I see why that is a dumbass idea. Besides, what is zero++? 0++ is still 0, so it makes no sense... I see the error of my ways now.

What I'm still wondering about, and tell me if I have this right, is you set 'const(constant) int(integer) iterations = 5' because the iterations are not a variable, but rather a fixed value and must remain a fixed value. But, count is made to be 'int(integer) count;' because 'count' is a variable, not a constant... Am I understanding that part correctly?

Furthermore, I understand now that when you set a 'const'(constant) it has to be a numerical value (that does not change)... Whereas, 'count' can be a word because it is just telling the program that anytime it comes across 'count' that it is a variable and to add 1 until count is = to 'iterations'...

The reason that count can't be done the same as iterations, e.g. const int count = 0; is because that would fix 'count' as a 0 and not allow it to be a variable...?

Is this right? Or am I flawed somewhere in my thinking?

I really do appreciate you guys helping me out, the best way I learn is by iterating what I think is right, which is why I typed this all up the way I did.
Pages: 1 ... 4 5 [6] 7