Title:   KOCH
Autor:   Andreas Mund
date:    2010/02/09
purpose: Sample for using the ADC hardware as Arduino (R) clone
for details see section "short description"

Software needed:
Arduino IDE, downloadable ad www.arduino.cc

Hardware needed:
6*ADC Board, or any other application with ATMEGA168 µC
with the needed pins available
Note:    Whenever you have questions to this, feel free so send an
eMail to : avr_[_at_]_endi-online.de
eventually will you find additional information on my homepage
At least will you find a suggestion of the PCB and the
shematics needed for this software
Copyright (C) 2010 Andreas Mund, endi-online.de

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA  02111-1307, USA.
short description:

This program advises the 6*ADC board to be used as a digital thermometer and
to control the power of a heating device by use of a (slow) pulse with modulation

Temperature measurement:
The temperature is read by use of a dallas DS1820 which is connected at PIN14 of the ADC
(See "http://www.arduino.cc/en/Hacking/PinMapping168" for details).
The Programming assumes that the DS1820 is connected with
parasite powering, so only two wires are needed to connect the sensor.
Each time when the temperature is read, will it be sent to the serial interface to be
further used on the host computer.

Power setting:
The serial interface can be used to set the PWM ratio of the Output pin no.
Sending a hex character from 0x00 to 0x64 represents the PWM to be
switched on between 0 and 100% of time.

I have added a solid state relay for switching on wall power (240V AC)



#include <OneWire.h>

#define DS_PIN_NR 14
#define HEATER_ON_PIN 17

OneWire  ds(DS_PIN_NR);  // on pin DS_PIN_NR
int i = 0;
byte power = 0;
float temperature = 0.;

void setup(void) {
// initialize inputs/outputs
// start serial port


void loop(void) {

byte present = 0;
byte data[12];
byte addr[8];

if(++i == 100)
int Rest   = i % 10;
int Zyklus = i / 10;

// read temperature, aproximately once per second
if(Zyklus == 0 && Rest == 0)
//  ds.select(addr);
ds.write(0xcc,1);               // skip rom
ds.write(0x44,1);               // start conversion, with parasite power on at the end
if(Zyklus == 9 && Rest == 0)
present = ds.reset();
//  ds.select(addr);   
ds.write(0xcc,1);               // skip rom
ds.write(0xBE);                 // Read Scratchpad for exact temperature calculation

for (int l = 0; l < 9; l++)     // we need 9 bytes
data[l] = ds.read();

int   *temp;
temp = (int*)&data[0];          // temperature is located here, the last bit is 0.5°C
*temp = *temp / 2;              // cut the last bit

// now calculate the temperature more exactly (see Dallas Datasheet for details)
temperature = (float)*temp - 0.25 + (((float)data[7] - (float)data[6]) / (float)data[7]);

Serial.print("Temp:");          // send start sequence
Serial.print(temperature);      // send temperature to serial port to host
Serial.println(" C");           // add the unit

if (Serial.available()) {
// read the most recent byte (which will be from 0 to 100 %):
power = Serial.read();
if(power > 100)
power = 100;
// switch the heating on, according to the power settings
digitalWrite(HEATER_ON_PIN, power > i);