I'm working on a network of Arduino Pro Mini on a Xbee wireless network. I have a C# program monitoring all the units listening to the Serial data. Each unit (Arduino Pro Mini) has two functions.
1:) Controls a relay of a hamper door.
2:) listens to a limit switch condition (Open/Close) to determine if the hamper door is open.
When I send a command to the network, each of them hear the same command. Is there an ID each chip has that I can use in the if event function to send command directly to each chip individually. There can be as many as 100 chips in the network. so I was thinking there's got to be a way to ID each chip individually so I can program an event which only listens to the command meant for it.
Example:
Chip 1 receives command to open door:
Chip 2 - 99 receives command to keep doors locked while door 1 is closed.
When chip one door limit switch senses the door is shut, an all clear goes over the network to allow each of the doors to be accessible yet remain locked until access is granted to that hamper door.
Perhaps something like this:
#include <EEPROM.h>
char sID[7] = "CD1002";
char receivedChar;
boolean newData = false;
int LEDRed = 2;
int LEDBlue = 3;
void setup() {
Serial.begin(9600);
for (int i=0; i<6; i++) {
// EEPROM.write(i,sID[i]);
sID[i] = EEPROM.read(i);
Serial.print(sID);
Serial.println(" is ready for command!");
digitalWrite(LEDRed, OUTPUT);
digitalWrite(LEDBlue, OUTPUT);
digitalWrite(LEDRed, LOW);
digitalWrite(LEDBlue, HIGH);
}
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.println(receivedChar);
Serial.println(sID);
if(receivedChar == 98){ //receive Command for CD1000 "b"
if(sID == CD1002){
digitalWrite(LEDBlue, HIGH);
digitalWrite(LEDRed, LOW);
Serial.println("Third Floor");
}
}
else if (receivedChar == 97){ // All Clear!
digitalWrite(LEDBlue, HIGH);
Serial.println("All Clear");
}
else{
digitalWrite(LEDRed, HIGH);
}
newData = false;
}
}
except the sID looks like it has to be converted to a string. Not sure the syntax for that.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.