Controlling more than one output via serial & php

Hello guys,

i'm new and I already searched the forums, but i wasn't able to find something regarding my question. Okay. I don't own an arduino board yet but i want to learn about how to program it, to begin just when it arrives.

so what i want to do is following. i want to control 5-10 (25amps) relays over serial port, using php on a linux server. i have read some tutorials on how to interface php with the arduino board but all of them are utilizing only one output.

i know how to open a connection and write one ascii 1 to the serial port. and i can understand how the arduino code works to process the ascii 1 it just got.

now i want to know, how to identify other pins in the arduino code and in php. are there any tutorials regarding this?

You'll need a few transistors to drive the relays... the Digital pins can't do it alone.

On the software side:

Lets say I have relays plugged into pins 8, 9, 10, 11, and 12. If I wanted to turn 8, 9, and 11 on, I could write

8,1 9,1 10,0 11,1 12,0

to the serial port. Then you could write some arduino software to parse that.

so for one relay i have to write

for example 8,1

8 and 1 to an array and have a for loop scanning all pins for a change right?

8 and 1 to an array and have a for loop scanning all pins for a change right?

You're trying to control the pins according to received serial messages, I thought - why would you want scan pins for a change?

hm. i dont really understand how to take those messages from the serial port, and parse them in my arduino code..

i do

void loop() { if (Serial.available() > 0) { usbnumber = Serial.read(); }

if (usbnumber > 0) { digitalWrite(ledPin, HIGH); } }

so at first i open the connection and listen on that for changes. if theres something higher then 0, i set the ledpin to high.

the thing i dont understand is, which code i need to use for multiple pin-possibilites

//edit:

i just got another idea. is it possible to get the 8,1 or something as a string from the php code? i could then write some

String instruction = String(4)

void loop() { if(instruction.contains(8,1) { set power to pin 8; } }

right?

Take a look at the C case-switch http://www.arduino.cc/en/Reference/SwitchCase

For example:

int usbnumber;

//Define pin names above
void loop() {
    if (Serial.available() > 0) {
        usbnumber = Serial.read();
switch (usbnumber) {
    case 5:
//Send a 5 to turn on pin 5
    digitalWrite(5,HIGH);
      break;
    case 50:
//Send 50 to turn off pin 5
    digitalWrite(5,LOW);
      break;    
case 13:
//Send 13 to turn on pin 13
    digitalWrite(13,LOW);
      break;
    case 130:
//Send 130 to turn off pin 13
    digitalWrite(13,LOW);
      break;
    }
  
  }
}

Then just send integers over serial, and change/add to the case loop however you please.