Hello,
Im working on a project whereas an ultrasonic sensor will detect someone walking into the bathroom, send the distance variable from the detecting Arduino to another Arduino, which will display "TrIG" on a 4 7 segment, set a timer, and when the timer runs out (aprox. 10 mins.), the displaying Arduino will send back a message telling the detecting Arduino to turn a servo. I've connected the 4 7 segment successfully, attached the detecting Arduino (of whom will be nicknamed "Bob" for now) to the displaying Arduino (of whom will be nicknamed "Joe" for now), connected servo and ultrasonic sensor to Bob, but I don't know how to get them to communicate to one another.
Bob's Code:
/*
Welp this is Part 2... Part 1 is here:
https://create.arduino.cc/editor/itsfoxy87/6366fdf0-89c5-4fb3-8dfe-0def763fa54c
I used two Arduino UNOs: One for Part 1 and another for Part 2 (so voltage is equal for
both parts AND so i can use both at the same time)
--------
| Servo|_______Red wire to 5v on Arduino
----⨷ |_______Yellow or Brown wire (or whatever colour wire that is in the middle) to Pin 10 on Arduino
|(kind |_______Black Wire to GND on Arduino
| of) |
--------
*/
int pos = 0; // variable to store the servo position
#include <Servo.h>
Servo myservo; //Tells Arduino that a servo exists
void setup() {
myservo.attach(11); //Tells Arduino where the servo is so it can be controlled
int pos = 0;
}
void loop() {
for (pos = 90; pos <= 0; pos += 1) { // goes from Spray to Idle Mode
// in steps of 1 degree
myservo.write(pos); // tell servo to go to set position above
delay(3600000); // waits 1 hour until servo moves to dispense liquid
}
for (pos = 0; pos >= 90; pos -= 1) { // goes from Idle to Spray Mode
myservo.write(pos); // tell servo to go to set position above
delay(1000); //Keeps Spray Mode on (pushes the trigger) for 1 second before returning to Idle Mode
}
}
Joe's code will be found in the link at the top of the code.
