Accueil / Arduino / Mini ClockT

02

Avr

2014

Mini ClockT Imprimer Envoyer
Écrit par john_lenfr   

Présentation

Une mini horloge qui donne la température à base des composants suivants:

  • un lcd
  • un shield Le Sablier
  • une Arduino Pro mini
  • un capteur de température LM35DZ



Programmation


/*
 MINI CLOCKT
 V1.0
 http://johnlenfr.1s.fr

/// LCD ///
 LCD1 VSS => Ground
 LCD2 VDD => +5V
 LCD3 V0  => digital pin 6 PWM Contrast
 LCD4 RS  => digital pin 4
 LCD5 RW  => digital pin 7
 LCD6 E   => digital pin 8
 LCD7 DB0 => not connected
 LCD8 DB1 => not connected
 LCD9 DB2 => not connected
 LCD10 DB3 => not connected
 LCD11 DB4 => digital pin 13
 LCD12 DB5 => digital pin 12
 LCD13 DB6 => digital pin 11
 LCD14 DB7 => digital pin 10
 LCD15 LED+ => digital pin 5 PWM Backlight
 LCD16 LED- => Ground
 
 /// LE SABLIER ///
 SDA => analog pin 4
 SCL => analog pin 5
 GRD => Ground
 VCC => +5V
 
*/

#include "LeSablier.h"
#include "LiquidCrystal.h"
#include "Wire.h"

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 7, 8, 13, 12, 11, 10);
// RS, RW, Enable, 4,5,6,7 (Refer to the back of your LCD for details)
// variables for the LCD Screen these constants won't change.  But you can change the size of
// your LCD using them:
const int numRows = 2;
const int numCols = 16;

// Time interval [ms] for display updates:
const unsigned long DISPLAY_INTERVAL = 5000;
static unsigned long lastTime=0;  // in ms
unsigned long time=millis();      // in ms

// variables for LDR
int photocellPin = 1;     // the cell and 10K pulldown are connected to A1
int photocellReading;     // the analog reading from the sensor divider
// LCD Backlight
int LcdLedPin = 5;           // connect LCD +LED to digital pin 5 (PWM pin)
int LcdLedBrightness=255;
// LCD Contrast
int LcdContrastPin = 6;           // connect LCD Contrast to digital pin 3 (PWM pin)
int LcdContrast=80;

// make some custom characters:
byte degree[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

char buf[]={"XX.X"};
float reading=0;
  float voltage=0;
  float temperature=0;


void setup() {
    Serial.begin(9600);
    Wire.begin();
    LeSablier.begin();
    //LeSablier.setAll (6, 16, 2, 13, 19, 34, 00);
    pinMode(LcdLedPin,OUTPUT); // set digital pin 5 to pwm output 
    analogWrite(LcdLedPin, LcdLedBrightness);
    pinMode(LcdContrastPin,OUTPUT); // set digital pin 3 to pwm output 
    analogWrite(LcdContrastPin, LcdContrast);
    // create a new character
    lcd.createChar(0, degree);
  
    lcd.begin(numRows, numCols);// set up the LCD's number of rows and columns 
    lcd.clear(); // clear lcd screen
    lcd.setCursor(0,0); // set the cursor on top left hand corner of the lcd screen
    lcd.print("* MINI  CLOCKT *");
    delay(5000);
    lcd.clear(); 
   
    Temp(); 
    
     
}

void loop() {
  
DateHeure ();

time=millis();

  if (time-lastTime>DISPLAY_INTERVAL)  // if at least DISPLAY_INTERVAL ms have passed
  {
  Temp(); // print current temperature
  lastTime=time;
  }
  
BacklightControl();  
  
}



void DateHeure ()
{
    lcd.setCursor(0, 0);

    lcd.print(LeSablier.getDayStr());
    lcd.print(".  ");
    
    if (LeSablier.getDate() < 10)
    {
    lcd.print("0");
    }
    lcd.print(LeSablier.getDate());
    lcd.print("/");
    if (LeSablier.getMonth() < 10)
    {
    lcd.print("0");
    }
    lcd.print(LeSablier.getMonth());
    
    lcd.print("/");
    if (LeSablier.getYear() < 100)
    {
    lcd.print("20");
    }
    lcd.print(LeSablier.getYear());
    
    lcd.setCursor(0, 1);
    if (LeSablier.getHours() < 10)
    {
    lcd.print("0");
    }
    lcd.print(LeSablier.getHours());
    lcd.print(":");
    if (LeSablier.getMinutes() < 10)
    {
    lcd.print("0");
    }
    lcd.print(LeSablier.getMinutes());
    lcd.print(":");
    if (LeSablier.getSeconds() < 10)
    {
    lcd.print("0");
    }
    lcd.print(LeSablier.getSeconds());

    
    
}

void Temp()
{
    lcd.setCursor(8, 1);
    lcd.print("  ");
    //Serial.println("lm35DZ:");
    //Serial.println(lm35dz());
    dtostrf(lm35dz(), 3, 1, buf); //dtostrf(floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, charBuf);
    lcd.print(buf);
    //Serial.println("buffer:");
    //Serial.println(buf);
    lcd.write((byte)0x0);
    lcd.print("C");
}


float lm35dz(){
  
  analogRead(3);
  delay(10);
  reading = analogRead(3); //LM35DZ connect to Analog pin 3
  //convert the voltage into temperature because the LM35DZ is at 10mV per °C
  voltage = reading * 5.0 / 1024.0;
  temperature = voltage * 100 ;
  return temperature;
}

void BacklightControl()
{
      // gestion extinction LCD le soir à 20h30
    if (LeSablier.getHours()==20 && LeSablier.getMinutes()==30 && LeSablier.getSeconds()==00)
    {
      LcdLedBrightness=1;
      analogWrite(LcdLedPin, LcdLedBrightness);
    }
    
     // gestion allumage LCD le matin à 8h30
    if (LeSablier.getHours()==8 && LeSablier.getMinutes()==30 && LeSablier.getSeconds()==00)
    {
      LcdLedBrightness=255;
      analogWrite(LcdLedPin, LcdLedBrightness);
    }
}


Réalisation




TELECHARGER ARDUINO IDE CODE