HI,
Could anyone help me, please?
I just tried my codes with the sensors but it did not work as I wanted. It runs for 10 times with one sensor only. I want both output ones. As if, 3000 time it will ON after contact with first sensor and then wait until it contact with second sensor then turn off .
flow chart will be like,
(Start > Magnetic Sensor 1 ON -> Solenoid Valve ON --> Magnetic Sensor 2 ON ---> Solenoid Valve OFF ) 3000 times.
First of all I declared the global variables
/*Declaring Global variables*/
int sensor_1_pin = 2; //hall effect sensor output connected to Ard
int sensor_2_pin = 3; //hall effect sensor output connected to Ard
int led = 7; //Declared LED
int sensor_1_value = 0;
int sensor_2_value = 0;
int cycle = 3000;
int v = 0;
void setup (), has been described as it is simply just declared the pinModes.
/*Declaring Setup
void setup()
{
Serial.begin (9600);
pinMode(sensor_1_pin, INPUT);
pinMode(sensor_2_pin, INPUT);
pinMode(led, OUTPUT);
}
My main issue is the loop. Last two weeks, I tired a lot to sort it out. there are 3 issues and those stuck me for ages.
Issue 1: when I brings the sensor1 closure to the Magnet, it LED turn on until I remove it but I want to remain it on until the (second sensor) sensor2 come close to the Magnet.
Issue 2: When I brought the sensor1 close to the magnet, it runs for 3000 times until i remove it. But I want the led will turn on and then sensor 2 will be closure and led will turn off. AND OVERALL, it WILL COUNT as 1 CYCLE.
Issue 3: the following code give me value like "Sensor 1 Value = 1" and "Sensor 2 value =1".... No idea why??
void loop()
{
//read and store sensor value (1 or 0)
sensor_1_value = digitalRead(sensor_1_pin); //Collect Sensor 1 Value from the sensor 1 pin
sensor_2_value = digitalRead(sensor_2_pin); //Collect Sensor 2 Value from the sensor 1 pin
Serial.print ("Sensor 1 value = ");
Serial.println (sensor_1_value);
Serial.print ("Sensor 2 value = ");
Serial.println (sensor_2_value);
//if sensor 1 value doesn't match sensor 2 value
if (sensor_1_value != sensor_2_value)
{ if (v<cycle)
{//if sensor 1 value is HIGH
if(sensor_1_value == HIGH)
{digitalWrite(led, HIGH);
Serial.print ("Sensor 1 value = ");
Serial.println (sensor_1_value); }
//if sensor 2 value is HIGH
else if(sensor_2_value == HIGH)
{ digitalWrite(led, LOW);
Serial.print ("Sensor 1 value = ");
Serial.println (sensor_1_value);}
}
v++; }
sensor_1_value = sensor_2_value;
}
Please help anybody. I am hopeless.