Sunday, November 28, 2010

Determining your Dallas 1 wire address

1-Wire devices, such as the DS18B20 digital temperature sensor, are great to use with Arduino boards because you can connect many of them to a single IO pin. The freely available software libraries and example code make using 1-wire devices simple. There is only one problem we have seen with the examples on the web. If you have more than one device connected to a single pin, say an indoor temperature sensor, as well as an outdoor temperature sensor, how does your Arduino know which is which?

Using the tutorial at http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html, We determined the following on our two DS18B20 Temp Sensors:

0x28, 0x3C, 0xF2, 0xA7, 0x02, 0x00, 0x00, 0xCB

0x28, 0x20, 0x04, 0xA8, 0x02, 0x00, 0x00, 0x4D

Now we are ready to move forward with the indoor/outdoor temperature monitor. To be continued ...

The Reverse Geocache™ Puzzle Box

I recently read a story about a wedding gift that gave a distance to a destination, and would not open until the destination was reached. It is based upon a mix of Arduino, a gps sensor, and good old inventiveness baked with art and engineering, and was finally frosted with love and emotion for friends. What started out as a private wedding gift, and eventually brought much of the world into it's story, is in 4 parts, took a year to accomplish, and is a must read.

http://arduiniana.org/projects/the-reverse-geo-cache-puzzle/

Saturday, November 27, 2010

The DS18B20 Digital Thermometer

Dallas Semiconductor (Maxim) produces a line of "One-Wire" devices, that allow multiple sensors to connect to a single data pin on a microcontroller. GND and +5vdc are also needed. I've put together a single sensor DS18B20 (soon to be expanded to multiple sensors) displaying the temperature on a LCD display. This example is digital, unlike the analog thermistor project from a few days ago. Enjoy, and please comment.

Find the address of your DS18B20

// LCD Thermostat


#include <onewire.h>
#include <liquidcrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight

OneWire ds(8); // ds18b20 pin #2 (middle pin) to Arduino pin 8
// ds18b20 pin #1 GND
// ds18b20 pin #3 +5vdc
// 5k ohm resistor between pins 2 & 3

byte i;
byte present = 0;
byte data[12];
byte addr[8];
 
int HighByte, LowByte, SignBit, Whole, Fract, TReading, Tc_100, FWhole;

void setup(void) {
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(2,16);              // rows, columns.  use 2,16 for a 2x16 LCD, etc.
  lcd.clear();                  // start with a blank screen
  lcd.setCursor(0,0);           // set cursor to column 0, row 0
 
    if ( !ds.search(addr)) {
      lcd.clear(); lcd.print("No more addrs");
      delay(1000);
      ds.reset_search();
      return;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      lcd.clear(); lcd.print("CRC not valid!");
      delay(1000);
      return;
  }
}

void getTemp() {
  int foo, bar;
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);

  for ( i = 0; i < 9; i++) {
    data[i] = ds.read();
  }
 
  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
 
  if (SignBit) {
    TReading = -TReading;
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25
  Whole = Tc_100 / 100;          // separate off the whole and fractional portions
  Fract = Tc_100 % 100;
  if (Fract > 49) {
    if (SignBit) {
      --Whole;
    } else {
      ++Whole;
    }
  }

  if (SignBit) {
    bar = -1;
  } else {
    bar = 1;
  }
  foo = ((Whole * bar) * 18);      // celsius to fahrenheit conversion section
  FWhole = (((Whole * bar) * 18) / 10) + 32;
  if ((foo % 10) > 4) {            // round up if needed
       ++FWhole;
  }
}

void printTemp(void) {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp is: ");
  lcd.setCursor(0,1);  
 
  if (SignBit) { 
     lcd.print("-");
  }
  lcd.print(Whole);
  lcd.print(" C / ");
  lcd.print(FWhole);
  lcd.print(" F");
}

void loop(void) {
  getTemp();
  printTemp();
  delay(1000);
}

Friday, November 26, 2010

CdS Light Sensor

I've been playing with my Cadmium Sulfide (CdS) photoresistors, and have put together a basic light sensor. I'm outputting raw values, so there is no correlation with solar insolation. If anyone knows some cool formulas that would convert the output to sun hours, I'd love to play with them. The wiring is documented in the code as follows:




#include <LiquidCrystal.h>

/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2

Cds Connections:
CdS Pin 1 to +5v
CdS Pin 2 to Analog Pin 0
10k ohm resistor pin 1 to Analog Pin 0
10k ohm resistor pin 2 to Gnd
*/

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13;    // pin 13 will control the backlight
int sensorPin = 0;
int val = 0;


void setup() {
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20, 4);              // rows, columns.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                   // start with a blank screen
  lcd.setCursor(0,0);            // set cursor to column 0, row 0
  lcd.print("Light level is:");
}



void loop() {
  val = analogRead(sensorPin);
  lcd.setCursor(0,1);
  lcd.print (val);
  delay(100);
   }

Saturday, November 13, 2010

The $2 Thermistor Temperature Sensor

A thermistor makes for a very inexpensive temperature sensor, under $2 for the thermistor and the 10k ohm resistor, not counting the $45 for the Arduino and LCD display:



#include <LiquidCrystal.h>
#include <math.h>

/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2

Thermistor Connections:
Thermistor Pin 1 to +5v
Thermistor Pin 2 to Analog Pin 0
10k ohm resistor pin 1 to Analog Pin 0
10k ohm resistor pin 2 to Gnd
*/

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13;    // pin 13 will control the backlight



void setup(void) {
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20, 4);              // rows, columns.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                   // start with a blank screen
  lcd.setCursor(0,0);            // set cursor to column 0, row 0
}

double Thermistor(int RawADC) {
  double Temp;
  // See See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  return Temp;
}

void printTemp(void) {
  double fTemp;
  double temp = Thermistor(analogRead(0));  // Read sensor on Pin 0
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temperature is:");
  lcd.setCursor(0,1);
  lcd.print(temp);
  lcd.print(" C, ");
  fTemp = (temp * 1.8) + 32.0;    // Convert to Fahrenheit
  lcd.print(fTemp);
  lcd.print(" F");
  if (fTemp > 68 && fTemp < 78) {
    lcd.setCursor(0,3);
    lcd.print("Very comfortable");
  }
}

void loop(void) {
  printTemp();
  delay(1000);
}

Thermistors, Ethernet Shields, and More

Yesterday I received a package in the mail from Hacktronics. Call it an early Christmas present. Inside was a package of Thermistors, 10k ohm resistors, a breadboard, and a Ethernet/Micro SD card Shield. Stay tuned for a variety of projects (including web based access to our weather station) based on these devices, and check out the tutorials listed on the product pages.

Monday, November 8, 2010

Garduino Upgrade, Now with more Twitter!

I found a new Instructable that's pretty amazing. Lot's of Arduino goodness!

From http://www.instructables.com/id/Garduino-Upgrade-Now-with-more-Twitter/

A couple months ago I came across two great instructables. The first was the Garduino, an arduino controlled garden to help you grow plants at home. The second was the Tweet-a-Watt, a project that teaches you how to monitor your home power usage using Xbees and Twitter. I read about both these projects here at Instructables and in Make Magazine, Vol 18.

I thought it would be great to combine both these projects and build myself an indoor garden that I could monitor from work via Twitter. Thus began an adventure in gardening and electronics that taught me a lot and took me much longer than perhaps it should have. Fortunately for you I'm going to write down all the steps so you can get started right away. Maybe you'll follow up with this project and upgrade your garden or use this as a guide to start on a similar project. Either way, I hope you'll let me know what you get up to.

If you're ready then head to the next step and begin the process!

Sunday, November 7, 2010

Light Sensors

I've been working on a project that will allow me to determine the number of sun hours available in a given spot, and track that over time, as a component of solar power installation design. The idea is to get a light detector in the sun, record the number of hours it is lit at full intensity, and map that to photovoltaic equivalence. One could use a pv cell, but there are other alternatives. The CdS cell, photodiode and others come to mind. We will try each of these methods and post our results, meanwhile, here is a great tutorial on the options:

http://www.electronics-tutorials.ws/io/io_4.html

Light Sensors are used to measure the radiant energy that exists in a very narrow range of frequencies basically called "light", and which ranges in frequency from "Infrared" to "Visible" up to "Ultraviolet" light. Light sensors are passive devices that convert this "light energy" whether visible or in the infrared parts of the spectrum into an electrical signal output. Light sensors are more commonly known as "Photoelectric Devices" or "Photosensors" which can be grouped into two main categories, those which generate electricity when illuminated, such as Photovoltaics or Photoemissives etc, and those which change their electrical properties such as Photoresistors or Photoconductors. This leads to the following classification of devices.

For more info, see http://www.ecs.umass.edu/ece/m5/tutorials/CdS_Flex_Sensor.html

Saturday, November 6, 2010

Water Usage Tracking

Here is a great project for monitoring water usage, and affecting usage behavior using graphical feedback:

From http://labs.teague.com/?p=722

Since we wanted to have an internet connected data-stream of our water usage, we decided to try out the YellowJacket Arduino with built-in WiFi. Data was then sent to the server at regular intervals when the water source was in use (from 1-15 seconds depending on the wireless setup and resolution desired). Using a GET request with ID and usage information, the server was then able to store and retrieve sensor data. The complete circuitry and code (see download link below) were both conceptually straight-forward and easy to implement.
Related Posts Plugin for WordPress, Blogger...