Sunday 28 February 2010

Arduino and TMP36 (temperature sensor)

Here is my first build of a temperature sensor and 7 segment LED connected to an Arduino Duemilanove, the display displays the first digit (10's) and pauses and then displays the second digit (units) pauses and then the decimal point to show end/start of temperature display.     

     

And here is the video:     





     
  

The full source code below

// Arduino - TMP36 and 7 segment LED
// By Chris Hawkins
// February 2010
// Temperature code from http://oomlout.com/TMP36/TMP36-Guide.pdf
//
// using bitRead help from connecting-a-7-segment-led-to-the-arduino-build-it/

// pins that 7 segment is connect to
int ledSegment[] = {
2,3,4,5,6,7,8,9};     

// Analog pin that TMP36 is connect to
int tempMonitor =0;     

// encode the on/off state of the LED segments for the characters
// '0' to '9' and 'DP' into the bits of the bytes
const byte numDef[11] = {
63, 6, 91, 79, 102, 109, 124, 7, 127, 103,128 };     

void setup()
{
Serial.begin (9600);     

// Sets the pinMode for all LEDs
for (int x = 0; x<=7; x++)
{
pinMode (ledSegment[x],OUTPUT);
}     

// enable on by one each LED to test them.
for (int x =0;x<=7;x++){
digitalWrite (ledSegment[x],HIGH);
delay (50);     

}
// disable one by one to finish test of each LED
for (int x =0;x30 ){
setSegments( numDef[3] );
}
// check Temperature is over 20 and below 30
else if (temperature >=20 && temperature =10 && temperature =10){
temperature=temperature -10;
}     

// Print temperature to serial for use in processing
Serial.println(temperature);     

// Delay to display the 10's digit of the temperature
delay (1000);     

// now display unit of the temperature
for (int x = 0;x<=9;x++){
if (int(temperature) == x){
setSegments( numDef[x] );
}
}
// Delay to display the unit digit of the temperature
delay (1000);     

// Now display the decimal point (DP)
setSegments( numDef[10] );     

// delay to show DP
delay (2000);     

}     

void setSegments(byte segments)
{
// for each of the segments of the LED
for (int s = 0; s < 8; s++)
{
int bitVal = bitRead( segments, s ); // grab the bit
digitalWrite(s+2, bitVal); // set the segment
}
}     

float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}     


todos's : make code work easily with temperature greater than 30
Next project add two 7 segment LEDs and add shift registers

Thursday 11 February 2010

Arduino in a box



Arduino in a box

Originally uploaded by Christhawkins


Well I mean on a breadboard at the moment but it will be in a box running the Scalextric Lap Counter code.

For prototyping/testing I have used 5v LED's but will us 2.5v LED's in the working model. I have also used a 24mhz Crystal because I haven't got to Maplins yet, so timing is out but works fine for this test.

Next I need to add reset switch..

Sunday 7 February 2010

Scalextric Lap Counter Schematic for Arduino



Scalextric Lap Counter Schematic for Arduino

Originally uploaded by Christhawkins


Here is my Schematic for a Scalextric Lap counter that uses and Arduino and Processing, the Arduino controls the sensors, LED's and buttons and it then relays the information via Serial to the Processing program. I have illustrated on the diagram a optocoulper but I had actual used a slotted Optical Switch (HA221).

Flickr

This is a test post from flickr, a fancy photo sharing thing.