Like many people know I am bothered about the electricity consumption of my flat.
For a while now people have been talking about ambient orbs to help monitor their power usage. There are one or two very good guides for producing these on the interent. I decided to go from scratch with an Arduino. Yesterday I finally bought an RGB Full Colour LED for £2.99 from Maplin. I am fairly sure it would have been cheaper at RS but they were closed. This was to be paired with my arduino I have had since Xmas.
This evening I prototyped some code on my Arduino(See at the end) and wired up the Red and Green pins. Blue wasnt required for my intended range. Pin 9 is green and pin 10 is red.
I have linked this into my own RSMB and it reads the live feed from my currentcost device. The number is then echoed down the serial connection with the colour of the light being determin with the following formula.
Red: Current Power Usage /1500 * 255
Green: 255- (Current Power Usage/1500*255)
Though this doesnt change in nice clear cut stages I liked the idea of a constant natural progression.
I still am fine tunning this so watch this space.
Code for the arduino
float value = 400; //initial value
float maxBoundary = 1500; //Value at which PURE red is shown
char incomingByte;
int count = 0;
char genValue[5] = “”;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(”Starting Orb”);
analogWrite(11, 0); //Blue is always 0
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// if ((incomingByte >=0)&&(incomingByte <10)) {
genValue[count] = incomingByte;
count++;
if (count == 5){
count =0;
Serial.println(genValue);
value = atof(genValue)-100; //take off a 100 because realistically at the moment it wont go below 350
if (value<0) value=0;
}
}
}
float displayValue = value/maxBoundary;
float displayValue255 = displayValue*255;
if (displayValue255 > 254 ) displayValue255 = 255;
analogWrite(10, displayValue255); //red //This is a Analgoue output from a digital pin on the arduino
analogWrite(9,255-displayValue255); //green
delay(500);
}
