This is my first program that works well does what i set out to do and overall I am pretty darn proud of. OK, if it works why am I posting at all? Hoping for suggestions and criticism from everyone. This is a project I am working on for my degree in electronics technology, so I think I have a pretty good grasp on the hardware end of things. What I am completely new to is programming these buggers. I have no experience in any programming language so the last week or so (dedicated to this project and some school and work) has been a little frustrating. I feel I am beginning to make progress though and believe I am ready for some interactive help.
Sorry for all the comments in the code this is serving as part of my lab report so there is quite a bit in there.
this program was created using 100% open software and hardware
thank you to all who are willing to share your thoughts and ideas
making this possible!
sheepdogsoftware.co.uk invaluable resource for learning Arduino programing
ladyada.net/learn/arduino/ lots of great tutorials and examples
Arduino Cookbook by Michael Margolis
code was borrowed from all the above sources and many more
created by bFORTIFIED 03/11/2011 revision 2 (code cleanup)
requires LM35 and 5 LEDs (1 green, 3 yellow, 1 red)
and 5 current limiting resitors
LEDs configured common cathode
this program will measure temperature and display reading
in bargraph form
future plans include:
driving 10 segment led bargraph with shift registers
driving 7 segment led display with temperature reading
driving brushless DC fan with PWM, based on temp reading
expanding system to 4 zones (4 independent temp sensors,
bargraphs, and fans)
const byte sens=A0; // sets analog pin A0 to name "sens"
// LM35 output will be conected here
// the LM35 is a linearly proportional
// temperature sensor (the output increase
// is directly proportional to increase
// in tempeature) for every 1 degree celsius
// the tempeature changes the output will
// change by 10 mV
const byte LED0=2; // assigns LEDs to digital pins 2-6
const byte LED1=3;
const byte LED2=4;
const byte LED3=5;
const byte LED4=6;
pinMode(LED0,OUTPUT); // sets digital LED pins to outputs
setLEDs(1,1,1,1,1); //Turns on all LEDs for 1 second ->
delay(1000); //to check LEDs lighting properly.
setLEDs(0,0,0,0,1); //Turns on and off LEDs in sequence->
delay(500); //to test LEDs and look coool.
delay(1000); /*all LEDs turn off for one second this lets
operator know when the LEDs come back on
this is a legitimate reading*/
int sensVal=analogRead(sens); //sets register "sensVal" to reading ->
//from the temp sensor
float voltage = sensVal * 5.0;//converts "sensVal" to a voltage
voltage /= 1024;
float tempC = voltage * 100; //converts voltage to temp in celsius
float tempF = (tempC * 9/5) +32; //converts temp celsius to temp fehrenheit
if (tempF<75) setLEDs(0,0,0,0,1); //sets LEDs according to temp fehrenheit
if (tempF>=80) setLEDs(0,0,0,1,1);
if (tempF>=85) setLEDs(0,0,1,1,1);
if (tempF>=90) setLEDs(0,1,1,1,1);
if (tempF>=95) setLEDs(1,1,1,1,1);
if (tempF>100) warningFlash(1); //flashes LEDs when temp exceeds 100F
//a function to easily set the LEDs in the preceding if statements
void setLEDs(byte ledReg4, byte ledReg3, byte ledReg2, byte ledReg1, byte ledReg0)
if (ledReg0==0) digitalWrite(LED0,LOW);
if (ledReg1==0) digitalWrite(LED1,LOW);
if (ledReg2==0) digitalWrite(LED2,LOW);
if (ledReg3==0) digitalWrite(LED3,LOW);
if (ledReg4==0) digitalWrite(LED4,LOW);
// a function to easily flash all the LEDs that also calls on the
void warningFlash(byte flashReg)
I have a feeling I could clean up the test sequence in the setup somehow like making it add 1 until it gets to five then subtracting 1 till 0 not sure exactly how to do that thought.
And then would the LEDs be a could way to practice an array? Still not quite understanding the concept of arrays.
Your help is greatly appreciated!
hmmmmm [ code ] and [ /code ] didn't seem to work any ideas on that? trying to put the code in a scrolling text box of its own