Status: Fully working
This is a project which connect a Maxim/Dallas Semiconductor microlan to a computer. The goal is to let the computer check if there's daylight in the apartment, and if there isn't some bulbs will be turned on.
Schematics:
PC Interface - DS2480B
Relay circuit - 1 channel, DS2405
Relay circuit - 2 channels, DS2406
Testcircuit (which also measure light) - DS2450
Measure temperature - DS1820
Led-controller - DS2405 with Mos-Fet
Pressure sensor MPXA4115
Pictures:
Picture of DS2405&Mos-Fet with 10mm white led
DSS2450 4-input A/D with resistor and an LDR.
Placed in a window to measure if it's daylight or dark outside and thereby help the computer decide if the led's and lamps should be on or off.
DS2450 & LDR covered in schrinktube.
Another picture of DS2405&Mos-Fet with 10mm white led, even smaller this time!
Scripts:
The first script runs every hour and checks what time it is. If the current hour is equal to Ton, a zero is written to the DS2405 who then turns on the connected lamp. Later when the current hour equals Toff a one is sent to the 2405 and the lamp is turned off. This script is placed in /etc/cron.hourly.
#!/bin/bash
Ton="17"
Toff="01"
HourNow=`date +'%H'`
if [ "$Ton" = "$HourNow" ]; then
echo 0 > /mnt/owfs/05.DC4F21000000/PIO
echo 0 > /mnt/owfs/05.231F14000000/PIO
fi
if [ "$Toff" = "$HourNow" ]; then
echo 1 > /mnt/owfs/05.DC4F21000000/PIO
echo 1 > /mnt/owfs/05.231F14000000/PIO
fi
Script #2:
This script reads the values from a 2450's A/D's and logs them to a file. For every read the hour of the read is logged.
#!/bin/bash
HourNow=`date +'%H'`
echo $HourNow >> /tmp/lightlevel
echo -n A >> /tmp/lightlevel
cat /mnt/owfs/20.A4F901000000/volt.A >> /tmp/lightlevel
echo >> /tmp/lightlevel
echo -n B >> /tmp/lightlevel
cat /mnt/owfs/20.A4F901000000/volt.B >> /tmp/lightlevel
echo >> /tmp/lightlevel
echo -n C >> /tmp/lightlevel
cat /mnt/owfs/20.A4F901000000/volt.C >> /tmp/lightlevel
echo >> /tmp/lightlevel
echo -n D >> /tmp/lightlevel
cat /mnt/owfs/20.A4F901000000/volt.D >> /tmp/lightlevel
echo >> /tmp/lightlevel
PHP code
To do more advanced things it's easier to use a more powerful programminglanguage. I used command line PHP to enable some 1-wire devices depending on lightlevel and time of day:
1-wire PHP software
Links:
Maxim/Dallas SemiconductorOWFS - One Wire FileSystem. Access the onewire devices through a virtual filesystem (For Linux).