if/ else / softwareSerial / rs485 / motion light network

Ive been fighting this allot… built this awesome program to control 8 ch light dimmer… now I want to network 8 arduino nanos around the hous with motion sensors that simply energize 1 input on digital 2 pin. when the pin is HIGH, I want it to satisfy an if statement,… to then “RSserial.write” a specific character that is linked to a specific channel back at the main controller to dim that light on, and then when channel goes LOW, another character will instruct the main to dim that specific light off.

attached image of main controller and video link of what it does with remote, and code.

the communication is going across pair in cat5 cable. but the if statement seems to not matter at all in the program… tried a regular if statement, and trying to nest an if, else, statement within an if statement.

if there’s anybody out there with the know how. please help… I’ve accomplished some awesome things on this project but this one has my brain racked.

Master NANO sends out an A… which will be recognized by one SLAVE in the line up… which will then return either an L or a H to inform the master whether its motion sensor is HIGH, or LOW… just a tester. the master will send a B for next slave… an so on… and so on… this will help keep traffic down as only one is able to talk when instructed to. plus the high low letters that are returned will all have to be different letters so each one is assigned to specific channel on dimmer module.

thanks guys.

picture links—

RS485_MASTER_modified.ino (2.71 KB)

RS485_SLAVE_modified.ino (2.13 KB)


picture links---

Pictures are attached to the post. We don't load picture from temporary services like dropbox and co.

What exactly is your problem?

If you have a timer interrupt every 83 microseconds (that's about 12kHz!) you should ensure that the ISR doesn't use more than 83µs to do it's job. If you have 8 potential triac fires which every one might have a delay of 8µs (BTW, delayMicroseconds() accepts only integer arguments), together with the digitalWrite()s you may be clearly over 83µs.

Remember: pulseIn() won't return a correct result if it was disrupted by one or more of your overly long ISR calls.

Dont' use the String class on AVR Arduinos.

Never use SoftwareSerial in a productive environment. If ever possible use the hardware serial interface (Serial). Do your debugging with LEDs connected to one of the free pins.

That code:

    // Wait for the transmission to complete.
    int bufferDelay = (baudRate / 10) * 2 + 100;

is simply bullshit. Every serial interface (even the software emulation) has a flush method for this. The delay calculation was completely wrong anyway.