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/RegulatorJuraj– Juraj ♦2018年08月15日 19:05:49 +00:00Commented Aug 15, 2018 at 19:05
2 Answers 2
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– Asrul Asyraff2018年08月16日 03:49:41 +00:00Commented Aug 16, 2018 at 3:49
-
The Arduino should easily be able to do that on its own.user35284– user352842018年08月19日 22:20:43 +00:00Commented Aug 19, 2018 at 22:20
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– CrossRoads2018年10月15日 13:37:53 +00:00Commented Oct 15, 2018 at 13:37
-
Why the downvote?CrossRoads– CrossRoads2018年10月15日 16:30:20 +00:00Commented Oct 15, 2018 at 16:30