Emily GoodwinMarisa Nahrwold
Published

Santa Has Come!

Instead of camping out all Christmas Eve night, use our Sants Has Come sensor to alert you when a present has been placed under the tree!

BeginnerFull instructions provided5 hours188
Santa Has Come!

Things used in this project

Hardware components

Argon
Particle Argon
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
3 mm LED: Red
3 mm LED: Red
×4
3 mm LED: Green
3 mm LED: Green
×5
Through Hole Resistor, 10 ohm
Through Hole Resistor, 10 ohm
×9
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Ultrasonic Sensor Circuit Diagram

This shows the circuit diagram used for the ultrasonic sensor. The Particle Argon pinouts are shown on the left, and the lines indicate where the specific pinouts are connected to on the ultrasonic sensor. There is also a green LED which was used to indicate the 'LED blink' message was received by the LED display.

LED Display Circuit Diagram

The LED display went off when the ultrasonic sensor detected a present. Similarly to the other circuit diagram, the Particle Argon pin outs are located on the left side of the diagram, and the LEDs are shown on the right side.

Code

Ultrasonic Sensor Code

C/C++
This was the code that was used for the Ultrasonic sensor, which was connected to the first Particle. The code has comments throughout to show how it works and to signify what certain portions of the code control.
// The library below was used so data that came from the sensor could be used to calculate distance in cm

// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>

//The output pins from the sensor, LED, and digital output pins from the Particle were defined below. The variable, cm, was also defined as a double so it would output decimal values. 
double cm = 0.0;
int trigPin = D4;
int echoPin = D3;
int led = D6;


HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);

// The LED was defined as an output, and the Particle was told to subscribe to the blinkled event, which would publish "blink" or "off" depending upon if the second Particle was told to turn its LEDs on. 
void setup() 
{
    Spark.variable("cm", &cm, DOUBLE);
    pinMode(led,OUTPUT);
    Particle.subscribe("santa_has_come_blinkled49", blinkled);
}

/* -----------------------------------------
An 'If' statement was used to publish an event called "present" when an object was detected less than 30 cm away from the sensor. This event would trigger the second Particle to light up the LED display. 
If the event "stolen" was published, the second Particle would not turn on the LED display. "stolen" would be published when there was no object detected in front of the ultrasonic sensor, or if an object was not within the 30 cm range. 
------------------------------------------*/
void loop() 
{
    cm = rangefinder.getDistanceCM();
    if (cm<30){
        Particle.publish("merry_christmas_santa_came", "present", PRIVATE);
        }
    else {
        Particle.publish("merry_christmas_santa_came", "stolen", PRIVATE);
        }
    delay(4000);
}

/* -----------------------------------------
A second 'If' statement was used to control the LED connected to this Particle. When the ultrasonic sensor detected a present, it would publish the event, "present." This would tell the LEDs on the second Particle to turn on. The second Particle would then publish an event called "blink" which indicated the message was received and the LEDs were on. This would cause the LED connected to this Particle to turn on to signify that this Particle knew the other one turned on the LEDs. 
If this Particle published "stolen," the LEDs connected to the other Particle would not turn on, so it would publish the event "off" which would tell this Particle to keep the LED off, indicating the LED display was also off. 
------------------------------------------*/
void blinkled(const char *event, const char *data)
{

  if (strcmp(data,"blink")==0) {
    digitalWrite(led,HIGH);
  }
  else if (strcmp(data,"off")==0) {
    digitalWrite(led,LOW);
  }
  delay(4000);
}

/* -----------------------------------------
SOURCES

We referenced the code from this website and used the author's useage of an ultrasonic
sensor to understand how to use it in our project.

Hrisko, Joshua. "Wiring and Coding." Internet of Things WiFi and Bluetooth Mesh Network with Particle Argon and Xenon Boards. 
    Maker Portal. Maker Portal, November 11, 2018. Accessed November 18, 2020. 
    https://makersportal.com/blog/2018/11/11/internet-of-things-bluetooth-and-wifi-mesh-network-with-particle-argon-and-xenon-boards. 

This video was used to figure out how to wire the ultrasonic sensor to the Particle. 

"Ultrasonic Sensor HC-SR04 and Arduino Tutorial." Youtube, uploaded by How to Mechatronics, July 26, 2015. Accessed November 15, 2020.
    https://youtu.be/ZejQOX69K5M
------------------------------------------*/

LED Display Code

C/C++
The code below was used to program the second Particle, which was connected to the LED display. There are comments throughout the code to explain what each part means and is supposed to do.
// The LEDs and the digital outputs used on the Particle are defined below. 
int led2 = D2; 
int led3 = D3; 
int led4 = D4;
int led5 = D5;
int led6 = D6;
int led7 = D7;
int led8 = D8;
int led9 = A0;

//The LEDs are defined as outputs and the Particle is told to subscribe to the other Particle.

void setup() {
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    pinMode(led5, OUTPUT);
    pinMode(led6, OUTPUT);
    pinMode(led7, OUTPUT);
    pinMode(led8, OUTPUT);
    pinMode(led9, OUTPUT);
    
    Particle.subscribe("merry_christmas_santa_came", ledBlink);
    
}

void loop() {


}

/* -----------------------------------------

An 'If' statement was used to tell the Particle to enable the LED display if a present was detected by the other Particle. If there was a present, the other Particle would publish an event called "present," which this Particle would detect and tell the LEDs to come on until an event, "stolen" was published by the first Particle. 
If the LEDs were told to turn on, this Particle (with all of the LEDs) would publish an event called "blink," which told the first Particle to turn on an LED, which would signify that this Particle received the "present" message and that the LEDs had turned on. 
If the first Particle did not detect a present, an event called "stolen" was published. This Particle would not turn the LEDs on, and would publish an event called "off" to tell the LED on the other Particle to stay off. 

------------------------------------------*/

void ledBlink(const char *event, const char *data)
{
    if (strcmp(data, "present")==0){
        digitalWrite(led2, HIGH);
        digitalWrite(led3, HIGH);
        digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
        digitalWrite(led8, HIGH);
        digitalWrite(led9, HIGH);
        Particle.publish("santa_has_come_blinkled49", "blink", PRIVATE);
    }
    
    else if (strcmp(data, "stolen")==0) {
        digitalWrite(led2, LOW);
        digitalWrite(led3, LOW);
        digitalWrite(led4, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        digitalWrite(led7, LOW);
        digitalWrite(led8, LOW);
        digitalWrite(led9, LOW);
        Particle.publish("santa_has_come_blinkled49", "off", PRIVATE);
        
    }
   delay(4000); 
}


/* -----------------------------------------
SOURCES

We referenced the code from this website and used the author's useage of an ultrasonic
sensor to understand how to use it in our project.

Hrisko, Joshua. "Wiring and Coding." Internet of Things WiFi and Bluetooth Mesh Network with Particle Argon and Xenon Boards. 
    Maker Portal. Maker Portal, November 11, 2018. Accessed November 18, 2020. 
    https://makersportal.com/blog/2018/11/11/internet-of-things-bluetooth-and-wifi-mesh-network-with-particle-argon-and-xenon-boards. 

This video was used to figure out how to wire the ultrasonic sensor to the Particle. 

"Ultrasonic Sensor HC-SR04 and Arduino Tutorial." Youtube, uploaded by How to Mechatronics, July 26, 2015. Accessed November 15, 2020.
    https://youtu.be/ZejQOX69K5M
------------------------------------------*/

Credits

Emily Goodwin
1 project • 0 followers
Contact
Marisa Nahrwold
1 project • 0 followers
Contact
Thanks to Joshua Hrisko.

Comments

Please log in or sign up to comment.