Using Multiple buttons to control a temperature sensor A/C relay

Hello All,

It's my first post on these forums and after a while of searching I can't seem to find exactly what I am looking for. I am new to Arduino, but have pretty decent knowledge of micro controllers, wireless, and electronics in general.

I am working on a project to design a stand alone, temperature controlled, A/C SS Relay for the purposes of controlling an old space heater/electric water heater from my solar power rig (for a cabin). I have the circuit designed and the wiring logistics are not a problem. I am using a one wire Temperature Probe and an LCD shield with the 6 push buttons for the sake of having a stand alone unit that can output to power the relay (activating a transistor to pull power down to the relay and switch it on/off using digital out on A0), the relay is then connected to a standard NEMA outlet to provide an outlet of AC power that turns on/off as required, since the devices plugging in do not have the correct logic built in to take a direct digital input.

My question is: when I am coding for my buttons, do I need to factor in a debounce feature that can accomodate all 6 buttons simltaneously? or should I pass something to the debounce, one button at a time?

My variables and initialization look like this:

//----------------- Import Libraries ---------------------
//one wire and Dallas temp are not standard and must be added to the arduino compiler software
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>

//----------------- DEFINE CONSTANTS ---------------------
// DS18S20 Temperature chip i/o
OneWire probe(8);  // set up to read temperature on pin 8 and assign variable name probe
DallasTemperature sensors(&probe); // Tell dallas library to read one wire probe

int led = 13; // Pin 13 has an LED connected on most Arduino boards.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //initialize the LCD with standard Pin diagram

//Initialize Buttons all will change once my shield shows up and I identify the buttons properly
int tempup = 10; //this will CHANGE when the sheild shows up and button mappings can be identified (increase set temp for relay)
int tempdown = 9; //this will CHANGE when the sheild shows up and button mappings can be identified (decrease set temp for relay)
int cf = 7;
int start = 8;
int off = 1;
int hc = 6;

int relay = A0; //this will CHANGE when the sheild shows up and button mappings can be identified (Relay trigger)
 
//----------------- Declare Variables --------------------

int SetTemp = 24; //start temperature setting at 24 degrees celcius
float CurrentTemp = 0; //temperature initialization for the temperature sensor
int farenheitTemp = 0; //variable initialization for later converting temp sensor data to farenheit

//initialize all inputs for variables associated to buttons 
boolean power = LOW; // start/STOP(off) pin variable
boolean hotCold = LOW; //Initialize Heating or cooling mode for HC button, low for heat and high for cooling default
boolean tempType = LOW; // celcius/farenheit temp selector
boolean increaseTemp = LOW; //boolean value to track weather temp should go up next loop or not
boolean decreaseTemp = LOW; //boolean value to track weather temp should go down next loop or not

//temp values to track button presses throughout code will be reset to low after each loop
boolean temp1 = increaseTemp;  
boolean temp2 = decreaseTemp;
boolean temp3 = tempType;
boolean temp4 = power;
boolean temp5 = hotCold;

Do I even need the temp variables to track buttons along the way? or is it easier to do this another way? Turns out that I tried to do something larger than most people for my first project.

I appreciate any help and feedback. Let me know if anything I've posted is unclear.
Astralus

activating a transistor to pull power down to the relay and switch it on/off using digital out on A0)

Hi, you do not use A0, which is an analog input as an output.
Use one of the remaining digital pins, configure it as an OUTPUT to control the transitor that controls your relay.

int relay = A0; //this will CHANGE when the sheild shows up and button mappings can be identified (Relay trigger)

You cannot intialize a variable with another.
it should be

int relay= a number representing the digital output you will be using goes here.

To continue developing your code, do it in small steps, get you LCD working first, then the temperature sensor, then get the sensor to read on the LCD, and keep adding extra features as you go.
Please do not try and write the entire code at once, it will invariably have problems and the more complicated it is the harder it is to debug.

The shield you are getting, if it has a set of buttons on it, will probably use an analogue input to read them, there will not be a digital input for each button.

Tom..... :slight_smile:

Bit of a confusing question there, I may remark.

It sounds as if you are using the DFRobot shield, or a "clone" of same, or at least are going to use that but have not received it.

Some versions of this have a nasty design fault that may damage the Arduino shield to which it is attached, so that could be an extra problem.

The pushbuttons are coded by a resistor chain so they have a priority and only one can be detected at a time as you read them as an analog input. Of course, you have to provide a debounce function for this.

Thanks for the tips Gentlemen. I did not realize that shield sends in data on an analog pin. That is the shield I've purchased and I will investigate the problems you spoke of.

Just to set you at ease tom, it's just some sample from the first draft. I've actually initialized each piece of code in it's own sketchbook so that I can test all features independently, (with serial print statements) and then combine them. The button information is all that was confusing me.

Thanks,
Astralus