Arduino: First approach

Arduino LEDs and Temperature sensor

Arduino LEDs and Temperature sensor

In the last years I have got in touch with many people enthusiast of a small integrated micro-controller called Arduino. For those of you that never heard about it, Arduino is an assembled electronic board centered around the ATmega328 (a programmable micro-controller with 32KB of flash Memory). The Arduino board is an Italian open source prototyping project (www.arduino.cc) developed mainly for artists, designers and for those people like us at Echomaterico interested into “interactive architecture” (interactions between environment and architecture).  

  

Here is the first of a series of future experiments that i am going to held with Arduino. I actually feel like a child playing with the electronic version of what is known as “The Chemistry Set”! Few weeks ago i have received my Arduino Beginner Kit and soon i started to play around with it. The intention is to study and analyze the potentialities of such a micro-controller for interactions between environmental variables and sustainability issues in architectural fields. The task is not straight forward and it will require time for testing and prototyping, so be patient .. any outcome will be posted.  

I will aim to apply Arduino within the following fields of analysis: Indoor Comfort Temperature measurement and visual communication with the user,  Photovoltaic Power output and Solar radiation, Daylight analysis measurement and management.  

The Pictures in this post refers to the first trial on measuring the Indoor temperature, obtaining also a sort of visual alert using 10 red LEDs. The circuit senses the Indoor temperature of the room and reports the output on my Mac, showing at the same time a dynamic “switch-on” of 6 LEDs. The Arduino is connected through a usb cable and data are transmitted in real time to the MAC. Touching the sensor with my fingers increases the temperature causing other two or three LEDs to switch on.  

Since i am not familiar, still, with the Arduino language, i simply modified and joined together two open-codes that you’ll find at the end of this post.  

Simple circuit with 10 LEDs and a Temperature Sensor on the top right side

Testing separately the two scripts i am able to collect interesting outcomes, and i suggest you as well to have fun with them.  

Using the sensor apart from the LED’s array i have been able to measure the indoor temperature and to get on my screen the results (around 21, 22 Celsius) The sensor though seams to be not so accurate in its instantaneous reaction to rapid dynamic changes of the temperature. In a coming test the following sensor will be used: LM35 Precision Centigrade Temperature Sensor.  

Unfortunately my attempt in joining together the code of the Temp. sensor with the one of the LED Array didn’t outcome the correct temperature measurement. As you can see in the following picture, the temperature i have got is only around 2 degree C or maximum 3!!!. I will have therefore to understand what’s wrong with it … maybe some variable is not converted correctly… i’ll let u know soon.  

  

I am sure i did many mistakes, but i will keep going in learning Arduino. Here are the two base Codes .. give it a try!  

Credits:  

Enrico Crobu 

/*LED bar graphTurns on a series of LEDs based on the value of an analog sensor.
This is a simple way to make a bar graph display. Though this graph
uses 10 LEDs, you can use any number by changing the LED count
and the pins in the array.This method can be used to control any series of digital outputs that
depends on an analog input. The circuit:
* LEDs from pins 2 through 11 to ground created 26 Jun 2009
by Tom Igoe
  http://www.arduino.cc/en/Tutorial/BarGraph
*/  

// these constants won’t change:
const int analogPin = 0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element’s index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}

  

 
/*TEMPERATURE SENSOR An open-source LM35DZ Temperature Sensor for Arduino. This project will be enhanced on a regular basis
(cc) by Daniel Spillere Andrade , http://www.danielandrade.net
http://creativecommons.org/license/cc-gpl
*/int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
void setup()
{
Serial.begin(9600); // start serial communication
} void loop()
for(i = 0;i<=7;i++){ // gets 8 samples of temperature  samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(50); 
 

 

tempc = tempc/8.0; // better precision
tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit 
 

if(tempc > maxi) {maxi = tempc;} // set max temperature
if(tempc < mini) {mini = tempc;} // set min temperature 
 

Serial.print(tempc,DEC);
Serial.print(” Celsius, “); 
 

Serial.print(tempf,DEC);
Serial.print(” fahrenheit -> “); 
 

Serial.print(maxi,DEC);
Serial.print(” Max, “);
Serial.print(mini,DEC);
Serial.println(” Min”); 
 

tempc = 0;  

delay(50); // delay before loop
 

Leave a Reply

Anti-Spam Protection by WP-SpamFree