Runing small program in main loop - timealarm

Hi Everybody, I need little advice / clue: I´m reading string of radio button values to run summer or winter mode (it’s just different time when vent is on or off) of my home ventilation.

           if (Pe > 1){

            if (readString.substring(Pe,(Pe+3)) == "P=1") {  //turns on winter mode
              digitalWrite(prdpin, HIGH);                    //winter mode running
              PRDON = true;
            if (readString.substring(Pe,(Pe+3)) == "P=0") {  //turns on summer mode
              digitalWrite(prdpin, LOW);                     //summer mode running
              PRDON = false;

Now I need write code for these modes, some sub loops ?. Can anybody give me some example to work with? Thanks

Create a variable that says what "mode" you are in.

In your main loop, check what the variable is set to and run the appropriate code.

I'm at a loss. I don't understand what you need advice for. You've already done what you needed to do by setting the digital pin, why would you need any other loops?

I'm switching between summer and winter mode with this, but I there is no code for each mode.

Mikee, I'm sorry, but that doesn't help any. You said you were turning on a vent, and with a proper relay, the digital pin can do that for you. Turn the pin on, it closes a relay and the vent starts running. Turn the pin off and the relay opens and the vent shuts down.

If you need to do something else, what? Do you have any other code for this project? Any overall description? Something.

Sorry, I‘m explaining it bad way and it is one error in there. I wanted to run it over one relay, like - NC contact as summer mode and NO for winter. I must add one more relay (separate summer and winter), because I want to create switching scheme for each mode. Example: As soon the winter mode is on (this I already have in my code), vent should be running (relay should switch): 2hours on, 3 off, 2on, 5 off... Summer mode will be different – another fan speed, longer „on” and shorter „off“ times.

I'm starting to understand, but remember that I can't guess what you want to do, you have to actually tell me.

But, look in the arduino playground for the Time library and the TimeAlarm library. With these two libraries you can set up the arduino to know the time, then you can set alarms to do things like turn on the relay at a given time or for a given duration. So, set the time, then set up alarms based on the day and time, then set an alarm for the duration to turn it back off. You can do this based on the actual day you want something to happen or you can set it up to operate on outside temperature...whatever you need.

I have alarms that change the temperature inside my house based on the time of day. For example at 7:00PM, I set the house up for night time, then at 8:00AM, I set the temperature for daytime. I turn my hot water heater off during the day so that it doesn't run unnecessarily when no one is using hot water. You loop code can do practically nothing once you set the alarms up and they're easy to change if you want to.

Does this help?

OK, I’ll try it this way, I can realy use time alarm to switch something depending on outside temperature. I just ordered RTC so “maybe tomorrow :)”.
Thanks a lot draythomp

Yes, you can do outside temperature by simply putting a sensor outside under an eave or something. You can also get the weather off the internet and do it that way.

Have fun.

Dear Mikee...

Were you saying you needed a way to tell if it is summer or winter? That you wanted your system to do AUTOMATICALLY, by itself, what it now does if you help it by pressing a button?

If so... well done for building your program using "black box" modules, where "somehow" inside the black box, and answer to "is it summer" is generated... but the main part of your program doesn't care about those details.

For the particular question you want the system to have an answer for... "Is it summer? Winter?" I would suggest a toggle switch! Twice a year, you flip it, and from then on, the system operates in the right mode, until the seasons change again, and you flip it back to the right season setting.

But, of course, that's no fun! So yes, a real time clock chip is the answer.

I would add a button to the system. Suppose it is May, and you have your system set to switch to "summer" operation on May 1st. But this year, summer is late, and on May 5th, you feel... Brrr... I want the heating system on "winter", even though it is supposed to be on "summer", by the calendar.

One press of the button would say "go to the other season for a day". Two presses: For two days. Etc.

The core of my question was to create time switching schedule for this two modes. Ventilation should run differently during summer (I´m fighting with high humidity in house) than winter (less ventilation needed because air gets too dry). All over this I´m using „Shock ventilation“ (5 min full vent power) used after showering…
Detecting winter /summer or better said outside temperature is for switching between air inlets in to the house. I´m using one on facade and other one is grounded register 30 meters from house. I want to switch between them automatically with valve and servo depending on outside temperature. See sketch in attachment.
But first I´m going to fight with RTC and time alarms and then comes the servo.

I'm still not entirely clear on what you're trying to do. Is this the requirement: pick which intake to use depending on the temperature. Run the venting fan for different cycles in the summer/winter and have an button to override the schedule to run the venting after you shower?

Mikee, after you experiment with timers, and get an understanding, come back to the forum and talk with us about temperature sensors and humidity sensors. You could use both of these in your house. Also, you can even sense airflow so you'll be sure the exhaust hasn't been plugged by something.

This will be a nice project.

Hi There, So I´m back again. After my RTC arrived (Tiny RTC DS1307 Shield) I spend like 4 hours to trying set up the time. Then I found some advices on forum so I left it during night without battery and started next day after I came from work again. Unfortunately problem is not gone after RTC had „passed out“ without battery. After another 3 hours of experiments I found out that: On beginning I was trying to set up the time with Ethernet shield on arduino and it wasn’t working. Then I detached Ethernet shield and I adjusted the time without problem. I tried some alarm settings – modified example code from library to switch some led and worked well, even then I unplugged RTC from arduino and later plugged it back. After I connected Ethernet shield back my time was gone (readings of time starts always at 18.09.00 2037), even after I put Ethernet shield down. I’m using UNO, W5100 Ethernet shield, connected with USB cable to laptop, RTC DS1307 Shield. Wiring as in adafruit tutorial. Is it voltage from usb cable? Can somebody tell me what I’m doing wrong?

Hi draythomp, Hi all,
I’m trying to run my alarms, but I can’t compile it. It writes that names of my time functions (M1, M2…) are not declared in this scope. I can’t find problem, can you help me? When I’m testing it in library example it works.
Code is in Add, - to many characters

Workingcode6m13.ino (14 KB)

You have declared those functions inside the loop function. C++ does not permit nested functions - move them outside loop, like your getTemperature function. Mind you, since they only consist of a single statement each, you might just get rid of the functions and leave the digitalwrite statements that they contain.

Thanks wildbill,
I took it out:

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RCSwitch.h>
#include <Time.h>
#include <TimeAlarms.h>

#define ONE_WIRE_BUS 3 

float tempC;

OneWire oneWire(ONE_WIRE_BUS);         // setup a onewire instance to communicate with any onewire devices 
DallasTemperature sensors(&oneWire);   // pass onewire reference to Dallas Temperature
RCSwitch mySwitch = RCSwitch();

DeviceAddress TN = { 0x28, 0x44, 0x33, 0x9D, 0x01, 0x00, 0x00, 0xAA };
DeviceAddress TO = { 0x28, 0x49, 0x45, 0x9D, 0x01, 0x00, 0x00, 0x11 };
DeviceAddress TP = { 0x28, 0xAE, 0x2E, 0x9D, 0x01, 0x00, 0x00, 0xDC };
DeviceAddress TV = { 0x28, 0xB7, 0x22, 0x9D, 0x01, 0x00, 0x00, 0x30 };
DeviceAddress TOUT = { 0x28, 0x3E, 0x3B, 0x9D, 0x01, 0x00, 0x00, 0xC3 };

byte    mac[] =     { 0x90, 0xA2, 0xDA, 0x00, 0x8D, 0x42 };   
byte    ip[] =      { 192, 168, 1, 104 };                     
byte    gateway[] = { 192, 168, 1, 1 };                       
byte    subnet[] =  { 255, 255, 255, 0 };                                  
EthernetServer  server(80);         
int     vedpin = 5;                // ventilation pin 
int     heatpin = 6;               // heating pin 
int     prdpin = 7;                // program/mode pin 
int     gatepin = 8;               // gate opener pin                             
int     sensorPin = A0;            // light sensing analog
int     sensorValue = 0;           // integer for the analog sensor
int     PIRstate = 0;              // variable for PIR sensor status
int     llight = 9;
int     PIR = 14;                   // PIR
int     motorlevel = 0;            // motor
String  readString = String(30);   // string for fetching data from address
boolean GADON = false;             // status flag gate
boolean HEDON = false;             // status flag heating  
boolean PRDON = false;             // status flag ventilation program
boolean VEDON = false;             // status flag ventilation 
boolean LLIGHT = false;            // status flag livingroom ligh

void setup()
  Ethernet.begin(mac, ip, gateway, subnet ); 
//******************************************time and alarm set********************************************
  setTime(18,00,00,3,7,13);    // time from arduino
  Alarm.alarmRepeat(6,30,00, M1 );        
  Alarm.alarmRepeat(7,30,05, M2 );        
  Alarm.alarmRepeat(8,30,10, D1 );        
  Alarm.alarmRepeat(9,30,15, D2 );       
  Alarm.alarmRepeat(14,30,20, D3 );  
  mySwitch.enableTransmit(9);                   // transmitter is connected to arduino Pin #9
  mySwitch.setPulseLength(360);                 // pulse length
  pinMode(gatepin, OUTPUT); 
  pinMode(heatpin, OUTPUT); 
  pinMode(prdpin, OUTPUT); 
  pinMode(vedpin, OUTPUT); 
  pinMode(llight, OUTPUT); 
  pinMode(PIR, INPUT); 
  //tu bolo  byte client_ip[4];   
  sensors.setResolution(TN, TEMPERATURE_PRECISION);
  sensors.setResolution(TO, TEMPERATURE_PRECISION);
  sensors.setResolution(TP, TEMPERATURE_PRECISION);
  sensors.setResolution(TV, TEMPERATURE_PRECISION);
  sensors.setResolution(TOUT, TEMPERATURE_PRECISION);
   void getTemperature(DeviceAddress deviceAddress)   // function to get the temperature for a device
  tempC = sensors.getTempC(deviceAddress);
  sensorValue = analogRead(sensorPin);
           Alarm.delay(1000); // wait one second between clock display
          void M1(){
          digitalWrite (vedpin,HIGH);
          void M2(){
          digitalWrite (vedpin,LOW);
          void D1(){
          digitalWrite (vedpin,HIGH);
          void D2(){
          digitalWrite (vedpin,LOW);
          void D3(){
          digitalWrite (vedpin,LOW);

but I still have some error at lines:

           Alarm.delay(1000); // wait one second between clock display

It says:

Workingcode6m13:91: error: expected constructor, destructor, or type conversion before ';' token
Workingcode6m13:92: error: expected constructor, destructor, or type conversion before '.' token
Workingcode6m13:93: error: expected declaration before '}' token

The compiler is complaining that these two lines:

           Alarm.delay(1000); // wait one second between clock display

Are not in a function. The closing brace after them is likely annoying it too.