Hi, I am working on a project to activate a relay module on a timer but also for the relay to activate when I tip the tilt sensor module. I have the timer working for the relay but cant get the tilt sensor to activate the relay. I will post the code. Any help would be appreciated.
Tilt sensor with relay:
const int sigPin = 2; // the number of the tilt switch pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
boolean sigState = 0; // variable for reading the tilt switch status
int control_pin = 7;
unsigned int time_on = 2;
unsigned int time_off = 3;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the tilt switch pin as an input:
pinMode(sigPin, INPUT);
Serial.begin(9600);
pinMode(control_pin, OUTPUT);
}
void loop() {
// read the state of the tilt switch value:
sigState = digitalRead(sigPin);
if (sigState == HIGH)
{
// turn LED on:
digitalWrite(control_pin, LOW);
}
else
{
// turn LED off:
digitalWrite(control_pin, HIGH);
}
digitalWrite(control_pin, LOW);
delay(time_on * 60000);
digitalWrite(control_pin, HIGH);
delay(time_on * 10000);
}