/*Occupancy detector sensor controlled change . */
#define East 2 //connects to output pin of IR sensor East
#define West 3 //connects to output pin of IR sensor West
#define Control 13 /* connect to play on DF player If it goes high the bells start playing. */
int valcontrol = 0;
void setup() {
Serial.begin(9600);
pinMode(East, INPUT);
pinMode(West, INPUT);
pinMode(Control, OUTPUT);
}
void loop() {
int valEast = digitalRead(East);
int valWest = digitalRead(West);
//if bells are not ringing and neither sensor is tripprd, meaning a train has not enter the crossing,
//the bells do not ring.
if (Control, LOW){
if ((valWest == HIGH) || (valEast == HIGH))
//if a train passes one of the sensors, the bells commence ringing. If it is longer than the distance between
// the sensors, the bells continue to ring.
{
digitalWrite(Control, HIGH);
} else {
digitalWrite(Control, LOW);
}}
//the bells are now ringing. a short train will be between the sensors but the bells should continue to ring.
// even though no sensor detects the train. so:
if (Control, HIGH)
{
if ((valWest == HIGH) || (valEast == HIGH))
{
digitalWrite(Control, HIGH);
}
else
{
if ((valWest == LOW) && (valEast == LOW))
{
digitalWrite(Control, LOW);
}}
} }