Go Down

Topic: Keeping a constant temp using an arduino (Read 104 times) previous topic - next topic

dmannnnn

Nov 13, 2019, 10:24 pm Last Edit: Nov 13, 2019, 10:27 pm by dmannnnn
I'm very new to Arduino so I have absolutely no idea what I'm doing. With that being said, I'm currently trying to build a device that maintains a constant temperature in a beaker of water. I figure that a temperature probe will have to be checked at regular intervals, and if the reading of the probe is under a certain value then it will turn on a heating element for a certain period of time. Past there I'm not really sure where to go in terms of code or hardware.

This is for a science competition where I have to measure the salt content of water. I plan to measure the conductivity of the water and figure salt content from there, do with that information as you'd like.

Edit: I'd like to keep this all to one Arduino to save on money if possible

DangerToMyself

Folks will probably need you to define "constant temperature".

jremington

#2
Nov 13, 2019, 10:51 pm Last Edit: Nov 13, 2019, 10:52 pm by jremington
This is a very difficult project for someone with no experience with Arduino. We strongly suggest that you start at the beginning.

Get an Arduino, learn to blink an LED without using delay, read a switch, measure a voltage, a temperature, etc. in order to learn the language and special features of the Arduino. If you skip those steps, expect endless frustration.

When you have done all that, google "arduino temperature control" for lots of examples. Measuring conductivity is a completely separate topic.

dmannnnn

This is a very difficult project for someone with no experience with Arduino. We strongly suggest that you start at the beginning.

Get an Arduino, learn to blink an LED without using delay, read a switch, measure a voltage, a temperature, etc. in order to learn the language and special features of the Arduino. If you skip those steps, expect endless frustration.

When you have done all that, google "arduino temperature control" for lots of examples. Measuring conductivity is a completely separate topic.
As much as I'd like to, I don't think that I'll have the time to since the actual competition is coming up soon :/

Paul_KD7HB

You will have lots of time later on.

Paul

jremington

Consider hiring someone to do the work for you, then. You can post on the Gigs & Collaborations forum section.

johnwasser

I bet a search for "arduino thermostat" will show a bunch examples that will be useful to you.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

saildude

Unless you are willing to put some effort into the code yourself - not likely you will get someone to write the code here unless you pay them.

The examples don't take that long to work through - and for temp measurement that is about half way through I think, doing the examples/tutorials will actually save you quite a bit of time over begging for help here - the basics are not that hard - if you are willing to do some work yourself and try - most of the people that help here are very helpful and patience (sp?) -

Blackfin

You need to have some basics to do this (what will your heater be? how much power? powered by mains? isolation/safety? can you wire stuff? do you know what SPI is and which pins of an Arduino are used? etc)

There are modules you can get do do sensor interfacing. For example, Adafruit's MAX31855-based thermocouple amp:

https://www.adafruit.com/product/269

You'd need that and a K-type thermocouple for this example (compiles...not tested...)

It's purposely vague on how to control the heater. I simply use a "relay" but you'd need to determine what the physical implementation is (keeping in mind safety, power etc)

Code: [Select]
#include <SPI.h>
#include "Adafruit_MAX31855.h"

#define HIGH_TEMP_LIMIT     30.5        //oC    upper limit (heat-off)
#define LOW_TEMP_LIMIT      29.5        //oC    lower limit (heat-on)
#define SAMPLE_INTERVAL     100ul       //mS    mS between temperature samples

#define ERROR_LED_BLINK     150ul       //mS    mS on or off time of LED for sensor error

#define RELAY_OFF           HIGH        //#     may have to change depending on setup/wiring
#define RELAY_ON            LOW
#define LED_OFF             LOW         //#     level to turn off LED
#define LED_ON              HIGH

const byte pinRelay = 2;                //pin#  relay coil control
const byte pinLED = LED_BUILTIN;        //pin#  built-in LED for heat/error indication
const byte pinTC_CS = 4;                //pin#  chip-sel for MAX31855

//create a thermocouple instance
Adafruit_MAX31855 thermoCouple( pinTC_CS );

float
    fTemperature;
unsigned long
    tNow,
    tSample;
bool
    bLEDState;
   
void setup()
{
    pinMode( pinRelay, OUTPUT );            //set relay control to output
    digitalWrite( pinRelay, RELAY_OFF );    //ensure it's off
    pinMode( pinLED, OUTPUT );              //same with LED
    digitalWrite( pinLED, LED_OFF );
    bLEDState = false;                      //false = off, true = on
   
    //
    tSample = millis();
   
}//setup

//state names
#define SENSOR_FAILURE      0   //sensor failure detected state
#define HEATER_OFF          1   //heater off state
#define HEATER_ON           2   //heater on state
//
void loop()
{
    static byte
        stateHeater = HEATER_OFF;

    tNow = millis();

    //if sensor failure detected (nonsense returned)...
    if( stateHeater == SENSOR_FAILURE )
    {
        //just blink the LED quickly
        if( (tNow - tSample) >= ERROR_LED_BLINK )
        {
            tSample = tNow;
            bLEDState ^= true;
            digitalWrite( pinLED, bLEDState );
        }//if
    }
    else
    {
        //is it time for a sample?
        if( (tNow - tSample) < SAMPLE_INTERVAL )
            return;

        tSample = tNow;
        //take a reading, make sure it's valid
        fTemperature = thermoCouple.readCelsius();       
        if( isnan( fTemperature ) )
        {
            //reading is not valid; enter safe state (heater off, blinking LED)
            stateHeater = SENSOR_FAILURE;
            digitalWrite( pinRelay, RELAY_OFF );   
            digitalWrite( pinLED, LED_OFF );
            bLEDState = false;
           
        }//if
        else
        {
            //is the heater on or off now?
            switch( stateHeater )
            {
                case    HEATER_OFF:
                    //off...has solution cooled below the lower limit?
                    if( fTemperature <= LOW_TEMP_LIMIT )                   
                    {
                        //yes; turn the heater and LED on
                        digitalWrite( pinRelay, HEATER_ON );
                        stateHeater = HEATER_ON;                //move to "on" state
                        digitalWrite( pinLED, LED_ON );
                        bLEDState = true;
                       
                    }//if
                   
                break;
   
                case    HEATER_ON:
                    //on now...has solution warmed to the upper limit?
                    if( fTemperature >= HIGH_TEMP_LIMIT )
                    {
                        //yes; turn off the heater and LED
                        digitalWrite( pinRelay, HEATER_OFF );
                        stateHeater = HEATER_OFF;               //move to "off" state
                        digitalWrite( pinLED, LED_OFF );
                        bLEDState = false;
                       
                    }//if
                   
                break;
               
            }//switch

        }//else
       
    }//else
   
}//loop

DangerToMyself

You don't need to control the temp via an Arduino. Just get one of these temperature controllers for about $15. Then all you need is a heater that can plug into it. Maybe one for a very small aquarium. Maybe $30. Probably less. (With limited time, why make yourself more work figuring out how to get an Arduino to do this part too?)

Where you're going to run into problems is with reading the salt content. Salinity probes are pricey. Usually over $100. Folks have interfaced a few with Arduinos in the past. Do a search for "Arduino salinity" and get a few hits.

Then you'll need a way to visualize the measurements. So, add in some sort of small LCD screen.  It won't be "easy". But there are examples in the IDE that would help get you started.

There's quite a bit involved, so don't think to yourself this is going to be a walk in the park. Especially with a time limit. If you only have a few weeks, find a different project. A few months? It might be doable if you eat sleep and breath this project.

Go Up