Hello!
I’ve been playing around with an Arduino Uno for a while.
I have written a project that I want to realize.
Basically there will be 3 inputs, a light sensor, a NO/NC sensor and a DCF timer.
The DCF timer is based on Dcf77 | Thijs.Elenbaas.net
Outputs of the Arduino will be two different relais and a LCD
What I have achieved so far:
- the DCF examples from the link above are working on my arduino, hardware and software
- I’ve been able to get text on the 16*2 LCD, display the state change of the NO/NC sensor on the LCD, and switch the two relais (with the same behaviour though)
Unfortunately, I’m a bit stuck now, so I hope anyone wants to give me some hints on how to proceed.
In sequence this are going to be the next steps:
- based on the NO/NC contact getting high, the two relais should be switched, one for 2 seconds, and one for 2 minutes
When the NO/NC contact gets triggered again, the timer of the ‘2 minutes’ relais should be reset, and 2 minutes should start counting again.
The ‘2 seconds relais’ should be triggered again for 2 seconds (assuming the trigger doesn’t happen within the first 2 seconds) - If that works I’d like to connect the light sensor (which could be seen as a second NO/NC sensor) and program several conditions together with the first sensor to switch the relais in a certain defined behaviour
- After that I would like to connect the DCF module, and again change the behaviour of the 2 relais based on time, and the 2 sensors
- Last step will be that certain information (still to be defined) will be displayed on the LCD for troubleshooting purposes
I added the code I have so far.
Any help is appreciated, first for the first step, getting the two relais to behave differently based on one NO/NC input
(without the delay() statement, as I know that’s not a good way of doing that)
Thanks in advance!
#include <LiquidCrystal.h>
LiquidCrystal lcd (12 ,11 ,5 ,4, 3 ,2);
const int switchPin = 6;
int SwitchState = 0;
int prevSwitchState = 0;
void setup() {
lcd.begin(16, 2);
pinMode (switchPin, INPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
lcd.print("Initialisation");
lcd.setCursor(0, 1);
lcd.print("sensor module");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status PIN:");
lcd.setCursor(0, 1);
lcd.print("No alarm");
}
void loop() {
SwitchState = digitalRead(switchPin);
if (SwitchState != prevSwitchState) {
if (SwitchState == LOW) {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status PIN:");
lcd.setCursor(0, 1);
lcd.print("No alarm");
}
if (SwitchState == HIGH) {
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status PIN:");
lcd.setCursor(0, 1);
lcd.print("ALARM NO/NC");
delay(10000);
}
}
prevSwitchState = SwitchState;
}