Sunday, February 14, 2010

Boiling Potatoes For Baked Potato Soup

LM35+LCD+web+MySQL - 3) Schema


tempLM35.zip (tutti i file)
D al momento che l'LM35 nel contesto in cui lavora al più potrà generare circa 0,5V (10mV/°C => 50°C) si è usata come tensione di riferimento quella interna (1.1V) del micro ATmega,per avere una risoluzione migliore.
Infatti con Vref=1,1V ed essendo l'ADC da 10bit abbiamo così 1 LSB = 1,074mV il che assicura una risoluzione di circa 0,1 °C migliore di quella propria del sensore.
In the program loop, it was decided to use three distinct functions for the three respective tasks: the
first, to measure the temperature: readTemp () running
20 readings of the voltage supplied by the sensor, calculates for each temperature and in the end it is the arithmetic mean, this is to have a better estimate of the extent, this value will be the return value of the function, which is stored in the variable temp.
the second, sending the temperature to the serial port: sendTempToSerial ()
takes as input parameter the temperature acquired by readTemp () and sends the serial (USB) only comes when a conventional character (ch) PC


the third, to send the temperature LCD sendTempToLCD () as the previous , takes the temperature acquired by readTemp () and sends the LCD connected locally to Arduino. The refresh takes place with a time of about 0.5s, which has proved a good compromise
So, if you are not interested to see the temperature on the LCD or vice versa will not use the PC side, the loop will be able to "comment on" the function that does not care. NB The sketch works by Arduino release 18 From this release, in fact, changes were made to the implementation of the methods print () / println () Print the class, which now allow to specify (in the second input parameter) the number of digits after the decimal point for course the floating point numbers. If you work on previous releases (and you do not want to upgrade to 18) you can always copy the new interface and implementation file:
Print.cpp
and Print.h release of about 18 previous http://arduino.googlecode.com/svn/trunk/hardware/arduino/cores/arduino/Print.cpp http://arduino.googlecode.com/svn/trunk/hardware/arduino / cores / arduino / Print.h Personally, I have followed this path on my release 17 (17 is the path to the. / Hardware / cores / arduino) and everything worked perfectly. Here's the sketch:
/ * * Sketch: LM35.PDE * Motivation: Measurement of room temperature (indoor) using LM35 sensor
* Author: Francesco Parisi (fparisi at tiscali dot it), (fparisi at gmail dot com) * Last rev.: 1.5 * Date: 09-Feb-2010

* Note: The scale LM 35 is T = K * V, where:
* K = 100 [° C / V] coeff.angolare scale

* V the voltage generated dall'LM35 (10mV / ° C) * T is the temperature in ° C * / / * Include the library for the management of the LCD * /
# include \u0026lt;LiquidCrystal.h>
/ * Match pin LCD \u0026lt;-> Arduino digital pin * /

# define

RS 12 # define EN 11 # define D7 2 # define D6 3
# define D5 4 # define D4 5 / * Number of analog pin is connected to the 'LM35 * / # define ANALOGPIN
5 / * Global Definitions * / double vref = 1.1 ; / / Vref of the ADC (that extension is 1.1 V) LiquidCrystal
lcd ( RS, EN , D4, D5 , D6, D7 ) / / 'lcd' is a variable of type LiquidCrystal * /
/ * * Setting up the hardware / void setup () { / * * Common Settings / analogReference (
INTERNAL ) / / to the ADC we use the internal Vref of 1.1 V (better precision) analogRead ( ANALOGPIN )

/ / First read "empty" (see page. datashett ATmega168 47)

/ * Set up to 'LCD (2x16) * / lcd . begin
(2 , 16); / * Setting for sending data to the serial port * / Serial .

begin
(

9600) ; / / open a serial stream of 9600 bps } / * Reads the temperature * /

double readTemp () {
double temp = 0.0 ; // valore convertito in temperatura (°C) int val
= 0 ; // valore quantizzato dall'ADC [0..1023] int nread = 20 ; // numero di letture

double
somma
= 0.0 ;

// somma delle letture for ( int i = 0 ;

i \u0026lt;nread ; i + +) {

val = analogRead ( ANALOGPIN )


/ / read the data of the voltage on pin 'voltagePin'

temp =
(100.0


* * vref
   val)  
/
1024.0 ;
/ / converts in ° C
sum + = temp ;
/ / add to the temperature read sommaf
delay (
50);
/ / wait 50ms}
return

( sum / nread); / / returns the average temperature
}
/ * Leave the temperature when it comes to the serial nature defendant * / void
sendTempToSerial ( double temp ) {char
incomingByte = 0 ; / / First byte of input from the serial stream
char ch
= 's' ; / / character agreed if ( Serial . available ()
> 0 ) {
incomingByte = Serial
.
read

();

// Leggi il primo carattere in arrivo dal PC via seriale/USB

if (
incomingByte )
// se è quello convenuto...
println


(
temp
);


// ...manda la temperatura al PC via seriale/USB

}




/ * Leave the temperature on an LCD (4bit mode) * / void

sendTempToLCD


(
double temp) {


lcd .
clear ();
/ / Clear the screen
lcd . noblink
();
/ / No blinking cursor lcd .
SetCursor (
0, 0

)

/ / Position cursor to column 1, line 1 . print
(temp

,

1);
/ / print temperature to one decimal place


lcd
    .
  1. print
    ( ''

    )
  2. lcd . print


    (

    (char
  3. )

    223)
/ / prints '°' LCD


.

print (
'C'
);}





/ * Execute repeatedly ... * / Void

      
loop () {

/ / get the temperature and store them in var. temp.
double temp = readTemp
();
/ / send it to the PC via serial / USB when prompted
sendTempToSerial
( temp);
/ / send it to the LCD
sendTempToLCD
(

temp);}



highlighted code generated by Generator: GNU source-highlight 3.1 by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite

0 comments:

Post a Comment