Eric
Published

My First Mesh Project

Publish messages through your local mesh network using the tools that come in the Argon development kit!

BeginnerProtip30 minutes903
My First Mesh Project

Things used in this project

Hardware components

Resistor 220 ohm
Resistor 220 ohm
×2
LED (generic)
LED (generic)
×1
Photodiode, 45 °
Photodiode, 45 °
×1
Argon
Particle Argon
×1
Xenon
Particle Xenon
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Particle Console
Optional: Use to observe light on and light off value through 'analogvalue' variable.

Story

Read more

Schematics

Photodiode circuit

The photodiode will be in series with a 220 Ohm resistor. Unlike an LED, the shorter leg of the photo diode should be put on the 3.3V. Between the photodiode and the 220 Ohm resistor is where you will measure the value. Use a wire to connect this point to 'A0'.

LED Notifier Circuit

From D6 to Ground, put an LED and 220 Ohm resistor in series. This LED will turn on when the photodiode circuit detects light.

Code

Photodiode Detection code (gateway or node device)

C/C++
IMPORTANT: For me, when my light was on the average value was ~150, and it was ~20 when the light was off. In the setup() there is a commented variable that you can use in the Particle Console to determine the value of your light when on and off. Alternatively, you can try different threshold values through trial and error.

Flash this code to the device that has the photodiode circuit. When the photodiode detects light, it will publish a message through the mesh network. The other device's code will turn on D6 and thus the LED that you will have wired up. If you do not have an LED, you could modify the code to turn on D7 (the on board LED).

Comments are mainly for newer users. If you've used non-mesh devices before, you can probably figure this
int photosensor = A0; // This is where your photoresistor or phototransistor is plugged in. The other side goes to the "power" pin (below).
//Analog pins A0-A5 are inputs, so there is no need to explicitly declare this pin as an input in our setup() loop

int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor or phototransistor.

void setup() {
    // This is here to allow for debugging using the USB serial port
    Serial.begin(9600);
    
    //The comment below can be used to create a variable. You can view the value of this variable in the particle console to determine what value is appropriate for the if else statement in the loop.
    
    //Particle.variable("analogvalue", &analogvalue, INT);
    
}

void loop() {
    // check to see what the value of the photoresistor or phototransistor is and store it in the int variable analogvalue
    /*Use the Particle Console to see what the average analogvalue is when your light source is on and off. For me, when the light is on
    the average analogvalue is ~150, and when off analogvalue is ~20 thus making 100 a good threshold choice*/ 
    analogvalue = analogRead(photosensor);
    if (analogvalue>100) {
       Mesh.publish("light on", "main office");
    //If our analogvalue is >100, this means the light is on, and we are going to publish our "light on" message
    }
    else if (analogvalue<=100){
       Mesh.publish("light off", "main office");
    //If our analogvalue is <=100, this means the light is off, and we are going to publish our "light off" message
    }

    // This prints the value to the USB debugging serial port (for optional debugging purposes)
    Serial.printlnf("%d", analogvalue);

    // This delay is just to prevent overflowing the serial buffer, plus we really don't need to read the sensor more than
    // 10 times per second (100 millisecond delay)
    delay(100);
}

LED Notifier (gateway or node device)

C/C++
This code handles the updates from the photodiode code through the mesh network. If the light is detected as on in the photodiode circuit, this code turns on the LED in the other circuit. The LED will be turned off if the photodiode detects no light.
int led = D6;

void setup()
{
  // This is here to allow for debugging using the USB serial port
  Serial.begin(9600);
  //Declare D6 pin as output
  pinMode(led, OUTPUT);
  //Subscribe to any "light on" message published in our mesh network and name our handler
  Mesh.subscribe("light on", LightOnHandler);
  //Subscribe to any "light off" message published in our mesh network and name our handler
  Mesh.subscribe("light off", LightOffHandler);
}

//Once subscribed to a published message, our handler takes the actions necessary when the message is published on the mesh network
void LightOnHandler(const char *event, const char *data)
{
  //If light detected on the argon, turn on LED on the Xenon
  digitalWrite(led,HIGH);
}
//Once subscribed to a published message, our handler takes the actions necessary when the message is published on the mesh network
void LightOffHandler(const char *event, const char *data)
{
  //If no light detected on the argon, turn off LED on the Xenon
  digitalWrite(led,LOW);
}

Credits

Eric

Eric

1 project • 1 follower
RF Engineer. Athlete.

Comments

Add projectSign up / Login