0

I'm working on a project which consists of 2 different function. since the arduino only can do 1 function so i decide to use 2 arduino instead. my idea is 1st arduino will give a output and the sketch on the 2nd arduino will run Only after the input given from the 1st arduino. So can i make a digital output which will be send to the input of 2nd arduino?

if it could be, i already make a code for the 2nd arduino which will be run after there was an input from the 1t arduino:

//define the input/output pins
#define FLOAT_SWITCH_PIN 2
#define PUMP_1_PIN 4
#define LED_PIN 7
#define output1starduino 3
//setup runs once
void setup()
{


  pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
  pinMode(output1starduino, INPUT_PULLUP);

  //setup output pins for relays/pumping station and LED board
  pinMode(PUMP_1_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

}

//loop() runs indefinitely 
void loop()
{

  if(digitalRead(output1starduino) == HIGH) // output from 1st arduino
  if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
  {
     digitalWrite(PUMP_1_PIN, HIGH); //turn on the pump
     digitalWrite(LED_PIN, HIGH);    //turn on the LED
  }


  {
     digitalWrite(PUMP_1_PIN, LOW); //turn off the pump
     digitalWrite(LED_PIN, LOW);    //turn off the LED
  }
} 

as i write on the line, the "output1starduino" which an digital output from the first arduino. Is this the right way for me to write if i want the program here to run only right after the output from 1st arduino given?

*** this is the code of first arduino which will be sent to the 2nd arduino

int motorPin = 3; // motor pengisian (m1)
int blinkPin = 4; //
int motor1 = 5;// motor pembuangan
int motorklorin = 6;// pam topap 
int switch1 = 2;// switch float
int indicator1 = 7; 
int indicator2 = 8;
int indicator3 = 9;
int output1starduino = 2;
void setup()
{
  pinMode(motorPin, OUTPUT); 
  pinMode(blinkPin, OUTPUT); // penujuk fasa pengisian
  pinMode(motor1, OUTPUT);
  pinMode(motorklorin, OUTPUT); // MOTOR UNTUK topap
  pinMode(switch1, INPUT_PULLUP);// PELAMPONG
  pinMode(indicator1, OUTPUT);// lampu penunjuk fasa pembuangan
  pinMode(indicator2, OUTPUT);// lampu penunjuk topap
  pinMode(indicator3, OUTPUT);// lampu menunggu
  pinMode(output1starduino, OUTPUT); // KELUARAN KE ARDUINO 2
}


void loop()

{
  digitalWrite(motorPin, HIGH); // turn on the motor
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(motor1, HIGH);// on lampu
  digitalWrite(motorklorin,HIGH);
  delay(1000);        // 

  digitalWrite(motorPin, HIGH);  // 
  digitalWrite(blinkPin, HIGH);  // penunjuk fasa pembuangan hidup
  digitalWrite(motor1, LOW);// motor pembuangan jalan (air start turun/pembuangan
  digitalWrite(motorklorin,HIGH);
  delay(180000);        //tempoh pembuangan 

  digitalWrite(motorPin, LOW); // turn on the motor (motorisi balik air jalan/pengisian
  digitalWrite(blinkPin, LOW); // 
  digitalWrite(motor1, HIGH);// filling motor on
  digitalWrite(indicator1, HIGH); //indicator
  delay(150000);        // duration filling


  digitalWrite(motorPin, HIGH);  // turn off the motor
  digitalWrite(blinkPin,HIGH);  // turn off the LED
  digitalWrite(motor1, HIGH);// 
  digitalWrite(output1starduino, HIGH);
  delay(100000);        // multiply by 60000 to translate minutes to milliseconds
  }
  • One arduino can do many functions. My asks data over modbus, calculates and sets pwm, makes some http requests, serves web pages from SD card and ajax requests, handles 4 relays, reads a current sensor and a temperature sensors, lights leds, checks a button, calculates consumption, writes events to eeprom, csv log and consumption stats to SC card... github.com/jandrassy/Regulator/tree/master/Regulator – Juraj Aug 15 '18 at 19:05
1

An arduino may not be as fast as a PC or phone, but it is VERY fast indeed (16,000,000 operations /sec). Unless the code for arduino #1 is incredibly complex, the one arduino should be able to do it all on its own. P.S. Please post the code for Arduino #1

  • i just edited the post.. feel free to give a check! – Asrul Asyraff Aug 16 '18 at 3:49
  • The Arduino should easily be able to do that on its own. – Rowan Radosav - McRae Aug 19 '18 at 22:20
-1

Combine them like this - I moved the duplicate pins to other pins

//define the input/output pins
#define FLOAT_SWITCH_PIN 2
#define PUMP_1_PIN 4
#define LED_PIN 7
#define output1starduino 3

byte motorPin = 11; // motor pengisian (m1)
byte blinkPin = 12; //
byte motor1 = 5;// motor pembuangan
byte motorklorin = 6;// pam topap 
byte switch1 = 2;// switch float
byte indicator1 = 13; 
byte indicator2 = 8;
byte indicator3 = 9;
byte output1starduino = 10;

//setup runs once
void setup()
{

pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
pinMode(output1starduino, INPUT_PULLUP);

//setup output pins for relays/pumping station and LED board
pinMode(PUMP_1_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);

pinMode(motorPin, OUTPUT); 
pinMode(blinkPin, OUTPUT); // penujuk fasa pengisian
pinMode(motor1, OUTPUT);
pinMode(motorklorin, OUTPUT); // MOTOR UNTUK topap
pinMode(switch1, INPUT_PULLUP);// PELAMPONG
pinMode(indicator1, OUTPUT);// lampu penunjuk fasa pembuangan
pinMode(indicator2, OUTPUT);// lampu penunjuk topap
pinMode(indicator3, OUTPUT);// lampu menunggu
pinMode(output1starduino, OUTPUT); // KELUARAN KE ARDUINO 2


}

//loop() runs indefinitely 
void loop()
{

if(digitalRead(output1starduino) == HIGH) // output from 1st Arduino
{
digitalWrite(motorPin, HIGH); // turn on the motor
digitalWrite(blinkPin, HIGH); // turn on the LED
digitalWrite(motor1, HIGH);// on lampu
digitalWrite(motorklorin,HIGH);
delay(1000);        // 

digitalWrite(motorPin, HIGH);  // 
digitalWrite(blinkPin, HIGH);  // penunjuk fasa pembuangan hidup
digitalWrite(motor1, LOW);// motor pembuangan jalan (air start turun/pembuangan
digitalWrite(motorklorin,HIGH);
delay(180000);        //tempoh pembuangan 

digitalWrite(motorPin, LOW); // turn on the motor (motorisi balik air jalan/pengisian
digitalWrite(blinkPin, LOW); // 
digitalWrite(motor1, HIGH);// filling motor on
digitalWrite(indicator1, HIGH); //indicator
delay(150000);        // duration filling


digitalWrite(motorPin, HIGH);  // turn off the motor
digitalWrite(blinkPin,HIGH);  // turn off the LED
digitalWrite(motor1, HIGH);// 
digitalWrite(output1starduino, HIGH);
delay(100000);        // multiply by 60000 to translate minutes to milliseconds
}

if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
{
 digitalWrite(PUMP_1_PIN, HIGH); //turn on the pump
 digitalWrite(LED_PIN, HIGH);    //turn on the LED
}


{
 digitalWrite(PUMP_1_PIN, LOW); //turn off the pump
 digitalWrite(LED_PIN, LOW);    //turn off the LED
 }
} 
  • Duplicate pins might need some more cleanup. – CrossRoads Oct 15 '18 at 13:37
  • Why the downvote? – CrossRoads Oct 15 '18 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.