Posts Tagged ‘ Guide

Arduino LCD HD44780 + LM335 Temperature Sensor

This was the next logical step in my home monitoring project.  I’ve simply added an LM335A temperature sensor to the breadboard and have the output being posted to the LCD every second.

 

First the drawing:

The next step was to write the code that reads the temperature on Analog Pin 0, then writes it the LCD.  This could not have been easier.

 

Code:

#include <LM335A.h>
#include <LiquidCrystal.h>
float raw;
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
 
LM335A InsideTemp(0); //pass the analog input pin number
void setup() {
  lcd.begin(16, 2);
}
 
void loop() {
  lcd.clear();
  //user must call ReadTemp before any valid temp data is available
  raw = analogRead(0);
  InsideTemp.ReadTemp();
  lcd.print(InsideTemp.Fahrenheit());
  lcd.print((char)223);
  lcd.print("F");
  lcd.setCursor(0, 1); // bottom left
  delay(1000);
}

Working project:

 

 

Things are coming along on the home monitor.  I’ll soon be using some multiplexers and 8bit shift registers to help reduce the number of pins used on the arduino.  Keep checking back for more updates!

Arduino LCD HD44780 Simple Tutorial

Connecting any LCD using the HD44780 standard to an arduino is extremely simple.  I’ve created a quick schematic showing how to connect the 16×2  HD44780 to an arduino.  I’ll be using this setup in my future projects, so this is simply for future reference.

 

Arduino LM335 Temperature Sensor Tutorial

Getting started with the LM335 Temperature sensor can be a bit tricky.  I ran into some problems when I started getting incorrect data.  I googled around for the problem, and all of the schematics and drawings at the top of google were incorrect.  They either had a static resistor on the data pin, or they show the data pin on the arduino directly connected to the LM335 Temperature sensor’s data pin.

The trick to correctly calibrating the temperature sensor is to connect a 10k potentiometer to the data pin.  Once the potentiometer is wired in place, you can calibrate the LM335 to read the correct temperature.  The correct wiring of the LM335 can be seen below:

 

 

 

 

 

Once everything is wired up, I simply used the lm335a.h library written by greenrobotics.net.  This is a nice library, a quick test sketch can be seen below here:

// Example using the LM335A library for reading temperatures
// Created by Jonathan Merrill, February 20, 2010.
// http://www.greenrobotics.net
//  Released into the public domain.
 
#include 
 
LM335A InsideTemp(0); //pass the analog input pin number
void setup() {
Serial.begin(57600);
Serial.println("starting");
 
}
 
void loop() {
  delay(3000);
  //user must call ReadTemp before any valid temp data is available
  InsideTemp.ReadTemp();
  Serial.print("Fahrenheit: ");
  //functions to get the temperature in various unitsfs
  Serial.println(InsideTemp.Fahrenheit());
  Serial.print("Celsius: ");
  Serial.println(InsideTemp.Celsius());
  Serial.print("Kelvin: ");
  Serial.println(InsideTemp.Kelvin());
 
}

Once I get motived, I’ll be sending this temperature data from my home to my blog, here.  I’ll be sure to post more updates as they come.

Flot Example: Format data in Flot readable JSON

I recently started learning the flot library.  Unfortunately, there aren’t any good examples of how to format the data with JSON in a flot friendly manner.  Below is some basic code that should retrieve data from a database, format it and then JSON encode it. I’ve written the example mostly in psuedo-code, most beginners should be able to pick up the key points of the following example.

 

The script below simply returns JSON, you should create this script in a web accessible directory:

getDataforFlot.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$mergedData = array();
 
//Get the first set of data you want to graph from the database
$databaseData1 = someFunctionToGetDataFromDatabase($id);
 
//loop through the first set of data and pull out the values we want, then format
foreach($databaseData1 as $r)
{
    $x = $r['x_value'];
    $y = $r['y_value'];
    $data1[] = array ($x, $y);
}
 
//send our data values to $mergedData, add in your custom label and color
$mergedData[] =  array('label' => "Data 1" , 'data' => $data1, 'color' => '#6bcadb');
 
//Get the second set of data you want to graph from the database
$databaseData2 = someFunctionToGetDataFromDatabase($id);
 
 
foreach($databaseData2 as $r)
{
    $x = $r['x_value'];
    $y = $r['y_value'];
    $data2[] = array ($x, $y);
}
 
//send our data values to $mergedData, add in your custom label and color
$mergedData[] = array('label' => "Data 2" , 'data' => $data2, 'color' => '#6db000');
 
 
//now we can JSON encode our data
echo json_encode($mergedData);
?>

Next, just put the following JQuery into your page to render the data using AJAX:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$(document).ready(function(){
 
    $.ajax({
                // usually, we'll just call the same URL, a script
                // connected to a database, but in this case we only
                // have static example files so we need to modify the
                // URL
                url: "/getDataforFlot.php",
                method: 'GET',
                dataType: 'json',
                success: onOutboundReceived
            });
 
    function onOutboundReceived(series) {
        var length = series.length;
        var finalData = series;
        var options = {
            lines: { show: true },
            points: { show: true, hoverable:true },
            grid: { hoverable: true, clickable: true }
        };
        $.plot($("#YOUR-DIV-ID-HERE), finalData, options);
    }
});

How To Add Additional FTP Users to a Domain in Plesk

This guide will show you how to create a separate FTP login for a specific domain using Plesk. This gives two different users the ability to connect to the same directory with the same permissions.

Click Here to see the full guide.

Windows Firewall: How to setup a Port Range

As most of you know, using the Windows Firewall GUI will not allow you to open a range of ports easily. This becomes a nightmare if you need to open up Passive FTP ports (port #’s 60,000 – 65,000).

Click Here for the full guide.