Old project

Hi,

During summer I develope a project to measure comfort in a work place. I finally acomplished my goal, but today i wanted to gave it a go. And part of it doesn’t work. The device consist in 3 buttons that measure comfort (temperature, humidity and light) in 3 different spaces. Only one of the buttons work.
/*
Projecte WOPAC
Versió del software: Arduino 1.0.5
Autor: Josep Font
Explicació: El codi font llegeix els valors provinents dels sensors de
temperatura, humitat i llum, i utilitzant un seguit de condicions es presenten
els resultats a partir d’uns LED’s que indiquen si l’espai de treball es
o no comfortable en els diferents aspectes. El usuari només ha de premer el botó
que pertany a la zona de treball, en la qual es troba.
Aquest codi està dissenyat per el prototip per tant només incorpora tres ambients
o zones de treball.
*/
//S’inclouen les llibreries
#include “DHT.h” //Llibreria del sensor DHT11
#define DHTPIN 2 // connectat al pìn 2 (DIGITAL)
#define DHTTYPE DHT11
DHT dht (DHTPIN, DHTTYPE);
//Declaració del pin de la fotoresistència
const int LDR = A0; //connectat al pin A0 (ANALOG)
//Declaració valors inicials polsadors. Els polsadors estàn oberts (0)
int push1=0;
int push2=0;
int push3=0;

void setup () {
Serial.begin (9600);
pinMode (13,OUTPUT); //S’estableixen els 6 pins com a sortides
pinMode (12,OUTPUT);
pinMode (11,OUTPUT);
pinMode (10,OUTPUT);
pinMode (9,OUTPUT);
pinMode (8,OUTPUT);
}

void loop () {
float h = dht.readHumidity (); //Declaració variable h (Humitat)
float t = dht.readTemperature(); //Declaració variable t (Temperatura)

//Inici sensor DHT11 (Sensor temperatura/humitat)
if (isnan (t) || isnan (h)) {
Serial.println (“No funciona (Error)”); //Si els valors són impossibles. Per exemple: valors negatius o per sobre de 100.
//Avisara posant un missatge de error en el monitor sèrie
}

else { //Informació que s’imprimirà en el monitor sèrie
Serial.print (“Humitat: “); //Humitat + (valor humitat)h + %
Serial.print (h);
Serial.print (” %\t”);
Serial.print ("Temperatura: “); //Temperatura + (valor temperatura)t + simbol graus cèlsius
Serial.print (t);
Serial.print (” *C "); }

//Inici Sensor de Llum
int LDRValor = analogRead (LDR); //Declaració valor rebut de la fotoresistència
float voltatge = 0.0048828125*LDRValor; //Variable per saber el voltatge amb relació al valor del sensor
int lux = (2500/voltatge-500)/10; //Equació per trobar els luxos (Valor final)
Serial.print (lux); //Impressió valor luxos al monitor sèrie
Serial.println (" luxos"); //Imprimim luxos per saber la magnitud de la unitat

push1 = digitalRead (5); //Declaració pins dels polsadors
push2 = digitalRead (4);
push3 = digitalRead (3);

//Ambient 1 (Zones treball sedentari) Oficines, classes,…

if ((push1 == HIGH) && (t > 17) || (t < 27)) {
digitalWrite (13,HIGH);
digitalWrite (12,LOW);
}

if ((push1 == HIGH) && (t <17) || (t > 27)) {
digitalWrite (13,LOW);
digitalWrite (12,HIGH);
}

if ((push1 == HIGH) && (h > 30) || (h < 70)) {
digitalWrite (11,HIGH);
digitalWrite (10,LOW);
}

if ((push1 == HIGH) && (h < 30) || (h > 70)) {
digitalWrite (11,LOW);
digitalWrite (10,HIGH);
}

if ((push1 == HIGH) && (lux > 250) || (lux < 500)) {
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
}

if ((push1 == HIGH) && (lux < 250) || (lux > 500)) {
digitalWrite (9,LOW);
digitalWrite (8,HIGH);
}
//Ambient 2 (Zones de pas) Pàrquing, Zona de pas metro, Passadisos,…
if ((push2 == HIGH) && (t > 17) || (t < 27)) {
digitalWrite (13,HIGH);
digitalWrite (12,LOW);
}
if ((push2 == HIGH) && (t <17) || (t > 27)) {
digitalWrite (13,LOW);
digitalWrite (12,HIGH);
}
if ((push2 == HIGH) && (h > 30) || (h < 70)) {
digitalWrite (11,HIGH);
digitalWrite (10,LOW);
}
if ((push2 == HIGH) && (h < 30) || (h > 70)) {
digitalWrite (11,LOW);
digitalWrite (10,HIGH);
}
if ((push2 == HIGH) && (lux > 125) || (lux < 250)) {
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
}

if ((push2 == HIGH) && (lux < 125) || (lux > 250)) {
digitalWrite (9,LOW);
digitalWrite (8,HIGH);
}
//Ambient 3 (Treballs de precisió) Joieria, Treball lineal, Laboratori
if ((push3 == HIGH) && (t > 17) || (t < 27)) {
digitalWrite (13,HIGH);
digitalWrite (12,LOW);
}

if ((push3 == HIGH) && (t <17) || (t > 27)) {
digitalWrite (13,LOW);
digitalWrite (12,HIGH);
}

if ((push3 == HIGH) && (h > 30) || (h < 70)) {
digitalWrite (11,HIGH);
digitalWrite (10,LOW);
}

if ((push3 == HIGH) && (h < 30) || (h > 70)) {
digitalWrite (11,LOW);
digitalWrite (10,HIGH);
}

if ((push3 == HIGH) && (lux > 500) || (lux < 1000)) {
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
}

if ((push3 == HIGH) && (lux < 500) || (lux > 1000)) {
digitalWrite (9,LOW);
digitalWrite (8,HIGH);
}
}

it doesn’t seem a code problem, but i don’t know what else could be

The device consist in 3 buttons that measure comfort

Nonsense. Switches are input devices. They can not measure temperature, humidity, or light.

Only one of the buttons work.

I'm not going to tell you how they are wired, or which one actually works...

Im using sensors to measure light, temperature and humidity. I'll check myself don't worry

Well, this are not the first 2 post that you make, I see that you have 73 post at this time. So I don't understand why you never had read the forum rules, specially this part:

The device consist in 3 buttons that measure comfort (temperature, humidity and light) in 3 different spaces. Only one of the buttons work.

It looks to me as though you are only reading data from one sensor. If that is the case how are you measuring comfort in 3 different spaces ?

Do you perhaps mean that you are displaying comfort in 3 different places ?
The program is crying out for arrays to be used to avoid the need for the repeated code.

Thanks to reply UKHeliBob,

Im reading data from a photosensor, and a DHT-11 (TEMPERATURE, HUMIDITY) sensors. I tried to create a non-repetitive code but i don't have a really good knowledge that is my first project with arduino. I mean that i can measure the comfort of 3 different places or type of working.

I mean that i can measure the comfort of 3 different places or type of working.

Then you will need to read 3 different sensors and put the results in array variables for use in the display.

You don't say which "button" actually works. If this project worked before, I'm guessing it's a wiring problem. Maybe with the DHT11 (since that provides two of the functions).

Near-duplicate post deleted.
Do not cross-post, it wastes time.