wireing: TX uno --> Rx1 mega
Rx uno --> Tx1 Mega
common ground
servo--> pin 9 uno
problem:
if i type in s1 close or s1 open in the serial or serial1 monitor of the Arduino mega, it doesnt work
if i type in s1 close or s1 open in the serial, but rewire the wires as:
Tx uno --> Rx0 mega
Rx uno --> Tx0 mega
it does work.
if i rewrite the code a little and i make the uno master and the mega slave it also works fine without rewireing. Can someone tell me where i went wrong making the uno slave and the mega master ? maybe a tip or a correction ?
I never use those functions anyway. Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
Also, while it is NOT the cause of your problem, it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.
When you connect the Uno to Serial on the Mega it will receive the data direct from the Serial Monitor.