Programming Language?

Oh yes! Everything you ever wanted to know about equipment or ask about equipment, this is the place to be! Share photos or ideas about equipment here.

Moderator: Post Moderators

User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

brahn wrote:If I remember right the thermocouple isn't as accurate as the thermistor, DS1820, or the LM34. It's probably not really a concern for this project as I don't think you're worried about tenths of degrees. Depending on the voltages that your thermocouple generates, the Arduino's analog input may do the conversion for you. What makes the thermocouple a better solution for this project?

BTW, the LM34 is really easy to use too, but you can't run a string of them like you can with the DS1820. Hook it up to +5 and GND and the middle pin gives you 1mV/degree F * a multiplier based on the input voltage. This is nice since it scales linearly, unlike a thermistor.
The only thing that makes the thermocouple appealing is that it is already nicely packaged, wired and ready to be immersed. Looking at the conversion chips though, they're expsnsive: $17 for a single IC and not multi-channel. The most popular type on eBay is a K type and from what I've read, they're really suited for higher temps anyway, like it'll tell you the temp of your kiln within 1/2 * :roll:

The DS1820 is a neat little chip, but I think a thermistor or the LM34 chip are probably the best choices since you'd want the Adruino to do the math anyway. Besides, the Adruino will take 8 ananlog inputs and I can't imagine 8 different things I'd want to monitor the temperature on at once anyway. It looks like the LM34 would be better since it doesn't sound like you'd need a lookup table in memory like you would with a thermistor.

At some point, I'm going to have to do some work for actual work today.... lol.
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

I just ordered an Arduino, a DS18B20 and a 10K thermistor to play with. Can't wait to breadboard this up.

Edit: I also ordered some relays and FET's to make a relay board.

I guess we'll see if I can make this work.
Last edited by backyard brewer on Tue Jun 17, 2008 10:57 am, edited 1 time in total.
User avatar
spkrtoy
Posts: 2893
Joined: Thu Sep 30, 2004 4:04 pm
Location: Orange, Orange County Calif.

Post by spkrtoy »

BB, Pete gave me a "Solder Sucker" to remove excess solder from your boards.
Cheers,
Lyn
Everybody has the right to be stupid. Some people abuse the privilege.

I hope life isn’t a big joke, because I don’t get it.
What I don't Know Far out weighs what I do.
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

Thanks Lyn (Pete). I'll have to get that.

Brent,

How are you communicating with the display? Did you buy a serial specific display? Most of the (cheap) ones I've seen look to all be parallel.
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

My LCD has a parallel interface and I use the 4-Wire interface. So it does take 4 of the Arduino's inputs. I think it's possible to cut that down, but I haven't played with that. There's a library available for the 4-Wire interface at the Arduino playground. There's actually a lot more than 4 wires necessary, but only 4 hook up to the Arduino, the rest are +5 or GND or something in between (a pot for contrast). LadyAda has a great tutorial on setting it up.

I got this LCD. I only bought it along with another order because it was really cheap and I figured I'd use it sometime. It came with a spec sheet, but it still took me a few minutes to figure out the pinout. I still need to come up with a decent connector instead of the ugly wires running to the breadboard into the cable.
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

I got my Arduino today and I've got a blinking LED. Whoo Hoo!
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

Wooo! Congrats! :)
User avatar
Oskaar
Posts: 979
Joined: Tue Apr 12, 2005 7:18 pm
Location: Sunny So Cal

Post by Oskaar »

Backyard Brewer wrote:...snip...I've got a blinking LED. Whoo Hoo!
I heard a little Preparation H will help with the itching and burning!
Don't go into the Pimped-Out-Refrigerator Jack!
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

Oskaar wrote:
Backyard Brewer wrote:...snip...I've got a blinking LED. Whoo Hoo!
I heard a little Preparation H will help with the itching and burning!
Thanks, I'll keep that in mind :roll:

I breadboarded up a simple transistor driven relay circuit and that seems to work fine. I just used the "blink" sketch and you can hear the relay pull in and out. I added an indicator LED as well and that's all working.

Next I'll start playing with the DS1820 sensor. Brent, can you post your sketch for your temp logger?

This thing is pretty neat.
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

No problem BB, here you go. It's a little more complicated than is strictly necessary since I'm outputting it to the LCD. I also noticed that the reading from the LM34 would jump around a bit, I tried adding a small capacitor to see if that would resolve the issue but it didn't seem to help much so I decided to handle it in software. I'm averaging the last 5 readings from the sensor. Because I was being lazy, the first 4 readings are way off and then it's pretty stable after that. I'm not sure how the DS1820 will work exactly, but you'll need to use the Wire library I believe. I've seen a few examples of that on the web too.

Code: Select all

#include <LCD4Bit.h>
/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */
#define LM34_ADJ 0.48828125
#define ARRAY_SIZE 5
LCD4Bit lcd = LCD4Bit(2);

float lastAvg = 0.0;
float temp_array[ARRAY_SIZE] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
float tempSum = 0.0;
int array_counter = 0;

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);
  lcd.init();
}

void loop()                     // run over and over again
{
  float avgTemp;
  float tempF = (float)analogRead(1) * LM34_ADJ;
  Serial.println( tempF, DEC );
  
  tempSum -= temp_array[array_counter];
  tempSum += tempF;
  temp_array[array_counter++] = tempF;
  
  array_counter %= ARRAY_SIZE;
  
  avgTemp = tempSum / ARRAY_SIZE;
  //Serial.print("Avg: " );
  //Serial.println( avgTemp, DEC);
  //Serial.print("Last Avg: " );
  //Serial.println( lastAvg, DEC);
  delay(1500);
  if( (int)avgTemp != (int)lastAvg )
  {  
    lcd.clear();
    lcd.printIn( "Temp: " );
    char temp[12];
    itoa(avgTemp, temp, 10);
    lcd.printIn( temp );
    lcd.printIn( " F" );
    
    lastAvg = avgTemp;
  }
  
}
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

That looks like straight forward "C" Brent .. is it? What compiler are you using for this?

Dan
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

It is straight forward C, I actually think the compiler does C++ as well. I use the packaged Arduino app which bundles the whole toolset. I think it uses GCC as the compiler.
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

Nice ...

Very cool!

Dan
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Getting Somewhere

Post by backyard brewer »

I has some time tonight to dip into the programming part. I'm surprised how quick I was able to get somewhere considering all I know about programming is what I gathered by cutting and pasting code from 3 different sketches and then modifying them for my application. Here is my code, it's ugly because it's gathered from three sources and then butchered up, but I wanted it for my own proof of concept. It reads the DS18B20, converts the temp to a whole number in *F, compares it to a setpoint and then turns an LED on or off based on the setpoint:

Code: Select all

#include <OneWire.h>

/* DS18S20 Temperature chip i/o
 
 */

OneWire  ds(10);  // on pin 10

void setup(void) {
  // initialize inputs/outputs
  // start serial port
  Serial.begin(9600);
}



void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  int Temp;
  if ( !ds.search(addr)) {
	//Serial.print("No more addresses.\n");
	ds.reset_search();
	return;
  }
  
  //Serial.print("R=");  //R=28 Not sure what this is
  for( i = 0; i < 8; i++) {
   // Serial.print(addr[i], HEX);
   // Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
	Serial.print("CRC is not valid!\n");
	return;
  }
  
  if ( addr[0] != 0x28) {
	Serial.print("Device is not a DS18S20 family device.\n");
	return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);	   // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);	   // Read Scratchpad

 
  for ( i = 0; i < 9; i++) {	     // we need 9 bytes
    data[i] = ds.read();
    
  }
  Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature

  Temp=Temp>>4;//divide by 16 to get pure celcius readout

  //next line is Fahrenheit conversion
  Temp=Temp*1.8+32; // comment this line out to get celcius
  
  Serial.print("Temp = ");//output the temperature to serial port
  Serial.print(Temp);
    Serial.print(" degrees F ");

  Serial.println();
  
  
int ledPin = 13;                // LED connected to digital pin 13


  pinMode(ledPin, OUTPUT);      // sets the digital pin as output

if (Temp < 86) {                     // Checks Temp to see if it is below 86*
        digitalWrite(ledPin, HIGH);  // sets the LED on
        Serial.print(" Relay On ");} 

 else { 
         digitalWrite(ledPin, LOW);
         Serial.print(" Relay Off ");}    // sets the LED off
 
}
And here's the ouput:

Code: Select all

Temp = 82 degrees F 
 Relay On Temp = 82 degrees F 
 Relay On Temp = 82 degrees F 
 Relay On Temp = 82 degrees F 
 Relay On Temp = 82 degrees F 
 Relay On Temp = 82 degrees F 
 Relay On Temp = 84 degrees F 
 Relay On Temp = 86 degrees F 
 Relay Off Temp = 86 degrees F 
 Relay Off Temp = 87 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 89 degrees F 
 Relay Off Temp = 87 degrees F 
 Relay Off Temp = 87 degrees F 
 Relay Off Temp = 87 degrees F 
 Relay Off Temp = 86 degrees F 
 Relay Off Temp = 86 degrees F 
 Relay Off Temp = 86 degrees F 
 Relay Off Temp = 86 degrees F 
 Relay Off Temp = 84 degrees F 
 Relay On Temp = 84 degrees F 
 Relay On Temp = 84 degrees F 
 Relay On Temp = 84 degrees F 
 Relay On Temp = 84 degrees F 
 Relay On Temp = 84 degrees F 
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

So did the LED light up too? Over what period are those temp readings (maybe you could add a timestamp to the Serial.print statements.

Brent (pitch in here my "C" is VERY RUSTY) ... I don't recall if asctime is standard

You may need to include one or the other of the following:
#include <ctime>

char *asctime( const struct tm *ptr );
Serial.print(asctime)
// Then your code
Serial.print(Serial.print(" Relay On ")

Should give you something like Tue Jun 24 08:03:53 2008

How are you connected to the PC .. serial (RS232?)

Looks pretty cool.

Dan
Post Reply