Here all complete code:
This will be serial on/off pin 13 and pin 11&10.
1.When i send 0 or 1 serial data, pin 13 will be HIGH and LOW
2.When i send 2 serial data, pin 13 will HIGH and pin 11.
-Pin 13 i hook with 1k resistor and bc548 transistor to control relay. For pin 11 i hook with Green LED and 220 ohm resistor.
-Pin 13 on the relay and pin 11 on the LED, i plan to used pin 11 as sensing if pin 11 High then it wait for LOW at Pin 2.
-After pin 2 connected with ground and sense as LOW, pin 12 will on and pin 13 off.
-Final process is if pin 4 sense Low the pin 12 off.
*I want to digitalRead pin 11 and 10 to separate the input program sequence for each serial data received.
//Setup atmega328-p serial communication and inout pin
void setup()
{
Serial.begin(9400);
//Setup input pin------------------------------------------------------------------------------------
pinMode(2, INPUT); //Sensor 1 litle
pinMode(3, INPUT); //Sensor 2 litle
pinMode(4, INPUT); //Sensor OverFlow
//Setup output pin------------------------------------------------------------------------------------
pinMode(10, OUTPUT); //Sensing 2.8 Litle
pinMode(11, OUTPUT); //Sensing 3.5 Litle
pinMode(12, OUTPUT); //PUMP2
pinMode(13, OUTPUT); //PUMP1
//Set all output as low/off----------------------------------------------------------------------------
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
//Initialise i as 0, so it start cointing from 0 to infinite
int i=0;
//Using loop function for all operation
void loop()
{
Serial.println(i++);
//-----------------------------------------------------------------------------------------------------
//AUTO Sensing following selected autofilling - each sensor
if (digitalRead(11)==HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
{
if (digitalRead(2)==LOW) // wait for 2.8 litle sensor detected oil then
{
digitalWrite(13, LOW); // pump1 stop
Serial.println("13 low");
delay(100); // give some time space before next process
digitalWrite(12, HIGH); // Start pump2 to pump oil to gearbox cointainer
Serial.println("12 high");
}
}
//------------------------------------------------------------------------------------------------------
//AUTOFILLING 3.5LITLE PROCESS
if (digitalRead(10)==HIGH) // && digitalRead(10)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
{
if (digitalRead(3)==LOW) // wait for 3.5 litle sensor detected oil then
{
digitalWrite(13, LOW); // pump1 stop
Serial.println("13 low");
delay(100); // give some time space before next process
digitalWrite(12, HIGH); // Start pump2 to pump oil to gearbox cointainer
Serial.println("12 high");
}
}
//------------------------------------------------------------------------------------------------------
//Over flow sensor detection function
if (digitalRead(4)==LOW)
{
digitalWrite(12, LOW);
Serial.println("12 low");
delay(100);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
Serial.println("11 and 10 low");
}
//------------------------------------------------------------------------------------------------------
//Serial speed
delay(200);
//Wait for serial android data recived------------------------------------------------------------------
if (Serial.available())
{
int msg = Serial.read();
//Evan from android, sub p will wait in loop mode to operate as ordered
//START PUMP1
if (msg == '0')
{
digitalWrite(13, HIGH); //PUMP1 manual start
Serial.println("Pump1 start");
}
//STOP PUMP1
if (msg == '1')
{
digitalWrite(13, LOW); //PUMP1 manual stop
Serial.println("Pump1 stop");
}
//2.8 Litle filling
if (msg == '2')
{
digitalWrite(11, HIGH); //Sensing for 2.8 litle function ON
digitalWrite(13, HIGH); //Pump 1 start to pump oil from main tank1 to Measure tank2
Serial.println("Sensing auto filling 2.8");
}
//3.5 Litle filling
if (msg == '3')
{
digitalWrite(10, HIGH); //Sensing for 3.5 litle function ON
digitalWrite(13, HIGH); //Pump 1 start to pump oil from main tank1 to Measure tank2
Serial.println("Sensing auto filling 3.5");
}
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.