Hey forum,
Whatever I tried, I cannot get this setup to work.
I would like to make home automation light switch. In the wall socket, there is a push button hooked up to a arduino micro. When pressed, the micro should put a serial message on the 'bus', which is read by an arduino uno, which in his turn triggers a relay.
To simplify the setup, I have written the micro code just to send H and L to the uno, where the latter just turns his onboard led on and off. Should be so straight forward
The arduino micro code
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print('H');
delay(1000);
Serial.print('L');
delay(1000);
}
The arduino uno code
void setup () {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop () {
if (Serial.available()) {
/* read the most recent byte */
int byteRead = Serial.read();
if(byteRead == 'H'){
digitalWrite(13, HIGH);
}
if(byteRead == 'L'){
digitalWrite(13, LOW);
}
}
}
Of course, I have tried:
- using serial1 procedures
- used both serial and serial1
- hooking usb first and last
- making sure they have common ground
- used serial print to debug
- hooked serial wires first and last
- reset when hooked
- shout very loud: aaaaah
- banged my head on the table
I am sure there is something I am overlooking or missing, but again, I cannot figure out what.
Maybe you can help, please
Answer given by Pert post #2
all the code for the micro should be replaced by serial1
The arduino micro code
void setup() {
Serial.begin(9600);
}
void loop() {
Serial1.print('H');
delay(1000);
Serial1.print('L');
delay(1000);
}