Scheduled Relays

This project will show you how to schedule to drive the outputs on a MKR Relay Proto Shield using a MKR1000!

Feb 6, 2017

13693 views

5 respects

Components and supplies

1

Arduino MKR1000

1

Arduino MKR Relay Proto Shield

Apps and platforms

1

Arduino IDE

1

Arduino Web Editor

Project description

Code

Comments

Only logged in users can leave comments

Immagine
Immagine

ssuperina

3 years ago

Hi, I was trying make relay 1 go HIGH for the predefined time (const int onMinutes) and have the relay 1 go LOW but hen relay 2 go HIGH for the same length (const int onMinutes) and eventually go LOW. I could not sort it with delay or millis functions so I thought to ask for help. :) Thanks.

Immagine
Immagine

Anonymous user

8 years ago

Interesting but there is an improvement in your code. You are a web server, to which we send parameters through a query, you do not need to recover these parameters by brute forcing them ... It's a lot of work for a simple task. // flag used to check if the request has been received Bool requestFound = false; // search for the sent time For (int hours = 0; (hours <24) && (requestFound == false); For (int minutes = 0; (minutes <60) && (requestFound == false); minutes ++) ... } } In this example i did it with 'onMinutes' parameters which represent a delay, just create a method which comes to read the query, it makes much more sense. Of course you can pass the parameter sought in parameter of this method to retrieve any param, typing in String the method, and casting the return of the function in the type expected. I think that if we have to present an example of communication with the webserver, it is more interesting to introduce this kind of method: int getRequestDelay(String request){ String paramName = "delay="; String stringValue = ""; int stringLength = paramName.length(); int pos = request.indexOf(paramName); int start = pos + stringLength; for (start; start < request.length(); start++){ char thisChar = request[start]; if(isSpace(thisChar) || thisChar == '&'){ break; } else { stringValue += thisChar; } } return stringValue.toInt(); }