Track your accomplishments
Keyboard Maestro: Make Link with Title from Clipboard

Arduino Esplora as a thermostat

I have long been tempted to dive into the world of Arduino, but I'm a software guy who knows nothing about electronics, so the thought of breadboarding and assembling circuits was too high of a barrier for me. Looks like someone who knows better realized this as the new Arduino Esplora includes a good number of fun sensors built-in. This is the perfect sandbox for someone like me, so I eagerly visited my local Radio Shack to buy one. (As a side note, I haven't been in a Radio Shack for years, and I was shocked to see how much of the floor space is dedicated to selling cell phones and cell phone accessories. Yeesh.) My very first Arudino Esplora script (aka "sketch") is nothing fancy, but it's useful. Press the down button on the joypad and the Esplora blinks the current room temperature. Additionally, the LED brightness is determined by reading the current ambient light level in the room Whee! Note that because the Esplora is USB-powered, you can use an iPhone (or iPod, etc) power supply to run it. I've put the source below, but visit the gist version for the latest as I won't be updating this post with any revisions.
#include <Esplora.h>
//Press the Down button on joypad to display current temperature
//The red LED blinks the tens value, the blue blinks the ones value. Green indicates end.
//example: red red red blue blue green is 32 degrees (F)
//the light sensor is used to dim the LEDs in a brightly lit room

//copyleft Jan 01 13 www.gordonmeyer.com

// delay used to blink lights
int flashdelay = 250;


void setup(){
}

void loop() {
  if (Esplora.readButton(SWITCH_DOWN) == LOW) {
    getTemp();
  }
}

void getTemp() {
 int theTemp = (Esplora.readTemperature(DEGREES_F)); 
// Serial.print(theTemp);
 int theTens = (theTemp/10);
 for (int i = 0; i < theTens; i++) {
   flashRed();
 }
 int theOnes = (theTemp%10);
 Serial.print(theOnes);
 for (int i = 0; i < theOnes; i++) {
   flashBlue();
 }
 delay (flashdelay);
 int brt = (Esplora.readLightSensor()/10);
 Esplora.writeGreen(brt);
 delay (flashdelay);
 Esplora.writeRGB(0,0,0);
}

void flashRed() {
  // uses room brightness to set LED level
  int brt = (Esplora.readLightSensor()/10);
 // Serial.println("bright "); Serial.print(brt);
  Esplora.writeRed(brt);
  delay (flashdelay);
  Esplora.writeRGB(0,0,0);
  delay (flashdelay);
}

void flashBlue() {
  int brt = (Esplora.readLightSensor()/10);
  Esplora.writeBlue(brt);
  delay (flashdelay);
  Esplora.writeRGB(0,0,0);
  delay (flashdelay);
}

Comments

The comments to this entry are closed.