Subscribe to Make Magazine Today!

Make: Projects

New Project: Hot/Cold LEDs

With an Arduino, ultrasonic distance sensor, and some LEDs, we are going to build a classic "hot/cold" project.

New Project: Hot/Cold LEDs

In this project, we will combine an Arduino, a Ping sensor, and a small assortment of components, to build a project that senses distances as "hot/cold." Once built, we’ll walk through the software running our basic "sketch," (what an Arduino program is called) and then experiment with variations of the "hot/cold" theme, all the while using the same circuit.

For the Arduino sketch files provided, the V1 sketch is detailed below. It measures distance from the sensor. The farther you are from the sensor, the "cold" blue LED begins to glow, and then the closer you get to the sensor, the "cold" LED fades away and the "hot" red LED turns up to full brightness!

The V2 sketch is a "capture the ping" game. At first, the "cold" blue LED glows, and every so often, the "hot" red LED will flash. When the red LED is on, try to move your hand in front of the sensor quickly. If you are fast enough, the red LED will flash; if you are too slow (or cheat!), the blue LED will flash.

And finally, the V3 sketch is a simple "hot/cold" switch. When no object is present in front of the sensor, the "cold" blue LED will produce a slow pulse. When it does sense an object, say when you sit down in front of your computer, the "cold" blue LED will turn off and the "hot" red one will shine at full brightness. This switch can be used to trigger other effects, such as waking your computer up from sleep mode.

  • Nick Normal

    Hi Imnot, you can find the version 3 files, which trigger pin 12 to wake up the PC, here: https://github.com/Make-Magazine/HotCold-LEDs/blob/master/HotCold_V3.ino

    Good luck, and let us know if you build this project!

    • miguel

      where it connects pin 12 to wake up the PC

  • http://www.blogshort.com/Woodrow57/tab:info Janelle

    There is also a boom that can be moved up and out of the way when one wants to simply use the
    headphones. Recently many players encounter G27 problem in Shift 2: Unleashed.
    t recognize then check the USB port by connecting another device.

  • Mumble

    I have a question about this. In this guide the ping sensor is programmed to only 30 cm. how can I modify the programming to increase the sensors range?

  • http://gravatar.com/wlarsen10 Whitney

    The link for the variation sketches titled “download the Hot/Cold sketch files for this project.” in the text is no longer a link, I’m having difficulty with the game variation of the sketch and it would be useful to see a working version.

  • Colin Lamb

    Where do you download the program files to run the hot cold sensor?

    • http://twitter.com/MacTechReviews MacTechReviews (@MacTechReviews)
      • https://www.facebook.com/suriel.cantu940610 Suriel Aaron Cantu Garza

        the code of my sensor my sensor hace trig and echo :/

  • Aryan King

    Parts for this project are difficult to find in india!!!!! What to do help Where I can find parts

  • gabi

    u could use this for communicating in morse code with one color dashes and another dots and put your hand in front to change color

  • Leslie

    I tried this out this weekend using this much cheaper proximity sensor ($5 instead of $30): http://www.amazon.com/SainSmart-Ultrasonic-Distance-Mega2560-Duemilanove/dp/B004U8TOE6/ref=sr_1_1?s=electronics&ie=UTF8&qid=1373809322&sr=1-1&keywords=parallax+ping

    The code needs to be modified to account for separate “ping” and “listen” pins.

    I also had to cut the sensing distance in the v3 code in half, because it was sensing the wall 8 feet away and the light was a constant red.

    • https://www.facebook.com/The564mumble Peter Miranda

      wait…so this ping sensor works as the parallex sensor? whats the difference in the two?

  • Chadun

    Does any other model other than parallax ping sensor works on this?

    • Leslie

      Hi Chadun – as I noted in my comment above, the SainSmart sensor worked with just an extra connection and slight modifications to the code, which I can explain in more detail if you need it. I couldn’t find another sensor that was exactly equivalent to the Parallax Ping sensor.

  • http://google vishal

    pls can u give the program codings

    • http://bayfiles.net/file/10csd/MbiD6v/HotCold_V1.ino j4red

      vishal – Here a link some modified code:

      http://bayfiles.net/file/10csd/MbiD6v/HotCold_V1.ino

      It works with the HC-SR04 module commonly found on eBay that has VCC/TRIGGER/ECHO/GND instead of VCC/GND/SIGNAL.

  • Peter

    I think the comments in the code can be a little misleading on how this sensor actually works — I can’t make sense of it as described. The code is:

    // measure distance: listen for “Ping”
     pinMode(SensorPin, INPUT);
     pulseDuration=pulseIn(SensorPin, HIGH);

    I don’t think the user code above is actually measuring distance, nor is it listening for the ping echo. Instead the *sensor* listens for the echo, processes the (probably very fuzzy) signal, and returns a pulse the length of which *represents* the distance. If you were actually listening (like a microphone) and measuring the delay, you wouldn’t do it with pulseIn HIGH. I think the sensor is designed so that pulse duration it calculates *represents* the distance, it is not a direct physical measurement.

  • Henry Campbell

    The ping sensor doesn’t light up I think I have the jumper wires in the wrong place can someone help?

    • Peter

      The LED on mine didn’t light up until I loaded the sketch. I have no idea why.

  • Pingback: Makers Making #WeekendProjects | MAKE()

  • miguel

    HOT COLD LED V3 doesnt work
    any solution?

  • Chris Valentine

    Where are the library files????

  • http://julius-schmiedel.de Julius Schmiedel

    sorry the files got lost somehow. download them here: https://www.dropbox.com/s/7vbryz6htsfth1w/makeHotCold.zip?dl=0

  • Pingback: And the Winner is… | Building & Hacking @ York College (CT 137)()

  • Jaden Davis

    how do I download the file without typing it of of the picture?

  • Pingback: Inspirations and Ideas | 7 weeks project Wearable technology()

  • Pingback: Spy Cipher Screening (° o°)! | Building & Hacking @ York College (CT 137)()

  • Ivan

    Am I missing something? I’ve tried the code made to turn on my computer, the leds do work although it’s not waking up my computer.

    This is what I have:

    // make 3: turn on computer when in front of sensor

    int usbChipPin=12;

    int SensorPin=7;

    int BlueLedPin=6;

    int RedLedPin=5;

    int counter=0;

    int resetCounter=0;

    int ledState=1;

    int ledDirection=1;

    boolean isSend=false;

    unsigned long pulseDuration=0;

    void setup() {

    // make led pin ready

    pinMode(BlueLedPin, OUTPUT);

    // make wake up pin ready

    pinMode(12, INPUT);

    }

    void loop() {

    // make led light steady while sensing, or dim led while idle

    if (counter>0 && isSend == false) {

    analogWrite(BlueLedPin, 200);

    } else if (isSend == false) {

    if (ledDirection == 1) {

    analogWrite(BlueLedPin, ledState);

    if (ledState == 125) { ledDirection=-1; } else { ledState = ledState + 1; }

    } else {

    analogWrite(BlueLedPin, ledState);

    if (ledState < 1) { ledDirection=1; } else { ledState = ledState – 1; }

    }

    } else {

    analogWrite(RedLedPin, 255);

    analogWrite(BlueLedPin, 0);

    }

    // measure distance: send "Ping"

    pinMode(SensorPin, OUTPUT);

    digitalWrite(SensorPin, HIGH);

    delayMicroseconds(5);

    digitalWrite(SensorPin, LOW);

    // measure distance: listen for "Ping"

    pinMode(SensorPin, INPUT);

    pulseDuration=pulseIn(SensorPin, HIGH);

    // if someone is in reach, count up, or reset if not

    if ( pulseDuration 50) { resetCounter=0; }

    } else {

    resetCounter = resetCounter +1;

    if (resetCounter > 100) {

    counter=0;

    resetCounter=0;

    isSend=false;

    analogWrite(RedLedPin, 0);

    }

    }

    // if someone is there for 300 loops, start up pc

    if (isSend == false && counter > 100) {

    // reset usb-to-serial chip

    pinMode(usbChipPin, OUTPUT);

    digitalWrite(usbChipPin, LOW);

    delay(250);

    pinMode(12, INPUT);

    // don’t do it again

    isSend=true;

    }

    delay(10);

    }

Related Supplies at Maker Shed