Introduction: Santa Alarm

Picture of Santa Alarm

Christmas is nearly here! Santa is coming!

When I was a kid I always wanted to see Santa for myself. I still do. Using the new RGB color sensor available at DFRobot, I rigged up a simple proximity alarm. I can use this to warn me if someone is in a close range of my Christmas tree putting presents under there. “Why not use a sonar sensor?” I hear you cry. Well, you easily could, but you want an alarm to be discrete and a sonar sensor is quite big and recognisable, whereas this sensor has a small form factor and is less noticeable. It also gives you some scope to utilize the other features this sensor has to offer in future – such a colour recognition or gesture recognition - something I challenge you to do if you have the time and inclination. However, this is just a jumping off point for all you budding tinkerers – take my design and improve it.

Step 1: Function

Picture of Function

This simple proximity alarm has 3 trigger ranges: “near”, “nearer” and “too close”. When each range is triggered, a different alarm sounds and a different light effect occurs. When the near range is triggered, a whaling alarm sounds. When the nearer range is triggered, a different whaling alarm sounds, plus a red LED blinks with it. When the too close range is triggered, a more urgent whaling alarm sounds, plus the LED blinks in a different, more urgent pattern.

Step 2: Hardware

The hardware of this project is pretty simple and suitable for beginners.

I used: 1 x Bluno Microcontroller v2.0

1 x I/O Expansion Shield v7.1(the extra I/O’s are very useful and prevent messy wiring!)

1 x Gesture Sensor

1 x Digital Buzzer Module

1 x 220 Ω Resistor (any will do)

1 x Red LED1 x Breadboard (for prototyping and checking the circuit – any will do.)

Jumper Wires for connections

Step 3: Connection

Picture of Connection

Step 4: Digital Buzzer

Signal: D8

Power: +5v

GND: GND

Step 5: Red LED

Signal: D6

GND: GND

(I have connected a resistor in series near the ground pin so that the LED doesn’t burn out).

Step 6: ​Sensor

SDA: SDA (Arduino)

SCL: SCL (Arduino

VCC: +5v

GND: GND

I have included a Lipo battery in the diagram, you can also power it through a USB cable.

Step 7: Code

I cobbled together the following code to get this working. It’s a mish-mash of code using the sensor’s proximity example as a basis, with some simple features added. Hardly elegant, but it functions well enough.

This code is quite accessible for a beginner, in fact it’s very similar to one of the codes in our Arduino beginner kits. If you’re interested in this project and a better coder than me, why not try improving it? Don’t forget to let us know on the forum if you do!

(Note: I am using the included library for the RGB Color sensor and the Arduino Wire library. You will need to download these in order for the code to compile/upload).

#include

#include

int buzzer = 8;

int redled = 6;

float sinVal;

int toneVal;



// Global Variables

APDS9960 apds = APDS9960();

uint8_t proximity_data = 0;

void setup() {

pinMode(buzzer,OUTPUT);

pinMode(redled,OUTPUT);

// Initialize Serial port

Serial.begin(9600);

Serial.println();

Serial.println(F("------------------------------------"));

Serial.println(F("APDS-9960 - ProximitySensor"));

Serial.println(F("------------------------------------"));

// Initialize APDS-9960 (configure I2C and initial values)

if ( apds.init() ) {

Serial.println(F("APDS-9960 initialization complete"));

} else {

Serial.println(F("Something went wrong during APDS-9960 init!"));

}

// Adjust the Proximity sensor gain

if ( !apds.setProximityGain(PGAIN_2X) ) {

Serial.println(F("Something went wrong trying to set PGAIN"));

}

// Start running the APDS-9960 proximity sensor (no interrupts)

if ( apds.enableProximitySensor(false) ) {

Serial.println(F("Proximity sensor is now running"));

} else {

Serial.println(F("Something went wrong during sensor init!"));

}

digitalWrite(redled, LOW);

}

void loop() {

// Read the proximity value

if ( !apds.readProximity(proximity_data) ) {

Serial.println("Error reading proximity value");

} else {

Serial.print("Proximity: ");

Serial.println(proximity_data);

}

// Wait 250 ms before next reading

delay(250);

if ((proximity_data) > 50) {

for(int x=0; x<180; x++)

{sinVal = (sin(x*(3.1412/180)));

toneVal = 1000+(int(sinVal*1000));

tone(8, toneVal,100);

delay(1);}

digitalWrite(redled, HIGH);

}

else {

digitalWrite(buzzer, LOW);

digitalWrite(redled, LOW);

}

if ((proximity_data) > 100){

for(int x=0; x<180; x++)

{sinVal = (sin(x*(3.1412/180)));

toneVal = 2000+(int(sinVal*1000));

tone(8, toneVal,100);

delay(1);}

digitalWrite(redled, HIGH);}

else {

digitalWrite(buzzer, LOW);

digitalWrite(redled, LOW);

}

if ((proximity_data) > 250) {

for(int x=0; x<180; x++)

{sinVal = (sin(x*(3.1412/180)));

toneVal = 3000+(int(sinVal*1000));

tone(8, toneVal,100);

delay(1);}

digitalWrite(redled, HIGH);

}

else {

digitalWrite(buzzer, LOW);

digitalWrite(redled, LOW);

}

}

Step 8: Project Limitations/Evaluation

As I mentioned, this sensor can also sense colour but it needs a lot of ambient light to do it. Originally I wanted to use this function but it needs to work in low lighting (Santa visits at night) and this sensor needs ambient light for the colour detection to give reliable data.It would have been a cool feature to have it trigger only if the sensor detected a close range AND the colour red - i.e. when Santa is nearby.

Activating some lights (maybe Christmas lights?) would have also been interesting and do-able if I had some more time. Once again, give it a go yourself and see if you can do it!

The Arduino is not a multi-threaded device and prefers to work on one process at a time – as a result making it generate sin values whilst reading proximity data caused its little processor to choke a little, and this is down the way my software is coded. I invite any coders out there to improve upon it – if you do please let me know – learning never ends!

Step 9: Other Potential Applications

Picture of Other Potential Applications

Someone told me that Santa isn’t real. I’ll have to double check this, but if it is true then there are some other applications for this project:

If you’re a parent, you can use it to make sure your kids aren’t sneaking in to your wardrobe and peeking at hidden presents before Christmas day.

You could also use it for other proximity functions – they don’t have to be Christmas related:

Perhaps someone is stealing pennies from your penny jar. Mount it nearby to be alerted when people are near.

Use it as a house alarm for a tiny dolls house. It’s just about the right scale for a miniature house alarm. Use it to keep burglars away!

This is a very basic application for a rather complex sensor, so if you can think of other features or you can improve it tell us on the forum. We love pictures of projects, so if you try this at home make sure you include lots of them!

Comments

DIY Hacks and How Tos (author)2015-12-10

Yes. This year I will catch that elusive Santa!

About This Instructable

600views

6favorites

License:

More by EmmaSong:How To Build a  Basic Arduino RobotHow to Make a Pet WearableHow to Make a Terrifying Halloween Gadget (Arduino-Based)
Add instructable to: