Thursday, October 15, 2009
Marquee Display
Friday, May 15, 2009
Hygrometer: Back on track
Here it is in action;
It shows temperature, relative humidity, atmospheric pressure and height from sea level.
If you could refer my previous photo of the hygrometer, the reading was around 62% and that was in January. After 5 months, the reading is 76% for the same temperature. This explains the hot humid condition we are experiencing currently.
I have to format the output in a suitable way which I'm working on currently. At the same time, I must think a way to use the other three sensors too...
Tuesday, April 21, 2009
Altimeter - Contd...
Thursday, March 19, 2009
Altimeter
Pressure is given by
P = (Vout/Vs+.095)/0.009 kPa
Where Vs, supply voltage = 3v
Vout, Output voltage measured from ADC
Altitude is given by
H = -ln(P/Po)*R*T/g
Three variables have to be measured:
T - average temperature in degrees Kelvin
Po - atmospheric pressure at ‘zero’ level
P - atmospheric pressure at current level
Remaining values are fixed constants:
R – universal gas constant = 286
g – gravitational acceleration = 9.81
Assuming Po=101.325 kPa and T=303.15K (30C)
The device reported H = 52.5m
Accuracy of this value is largely depending on the resolution of the ADC.
10-bit resolution of the ADC is not even near to get a reasonable accuracy of the altitude. One unit change in the ADC measurement will change 10m of height. To obtain 1m sensitivity, I need at least 12-bit ADC. So I ordered 12-bit ADCs from Maxim-IC and waiting until they arrive for the final product.
Tuesday, March 03, 2009
PIC Relay – 230v
This simple PIC circuit can be used to pre-program the on/off time of 230v electrical appliances. The PIC is programmed as a clock and at specified times, it can turn on/off a relay to control the appliance. I found a broken power guard (which protects electrical equipments from over and under voltage) in my old parts ‘yard’ at home. It was good source for the relay, diods, step down transformer, voltage regulator, the plastic container and even the LEDs. This relay is having good characteristics since these power guards were produced mainly to protect refrigerators. Only drawback in this design is that it doesn’t have a user interface. If you want to change the on/off time, you have to do it using the program. (I was too lazy to add a display unit for the device) It is being tested with our refridegerator and is working fine. I put the fridge to turn off at midnight for about four hours.
/*
* Project name:
PIC Relay
* Copyright:
Chandana Inc.
* Description:
PIC Relay - 230v
* Test configuration:
MCU: PIC16F88
Oscillator: XT, 04.0000 MHz
SW: mikroC v8.0
* NOTES:
Time might not be accurate.
*/
unsigned int countdown ; // interrupt counter
unsigned char update ; // update output
unsigned char secs, mins, hrs ; // tally variables
unsigned char ticks, correction,mode;
char oldstate_min, oldstate_hr, PowerOK, Powerchange, OutputStatus;
void interrupt()
{
if (--countdown == 0)
{
countdown = 8000; // 8000 x 125us = 1 second
update = 1; // flag to update clock output
}
PIR1.TMR2IF = 0; // clear interrupt flag
}
void Clock24()
{
if (++secs == 60) // check each tally for rollover
{ secs = 0;
if (++mins == 60)
{ mins = 0;
if (++hrs == 24)
hrs = 0 ;
}
}
update = 0;
}
void Initialize()
{
CMCON=7;
secs = 255;
mins = 23;
hrs = 15;
update = 1;
countdown = 8000;
INTCON.GIE = 1; // enable GIE
INTCON.PEIE = 1; // enable PEIE
T2CON = 0; // prescaler=0; postscaler=0; Timer2=off
TMR2 = 0; // clear timer2
PR2 = 124; // TMR2 resets when matching PR2
PIE1.TMR2IE = 1 ; // interrupt enabled
PIR1.TMR2IF = 0 ; // interrupt flag cleared
T2CON.TMR2ON = 1 ; // start Timer0
}
void main() {
Initialize();
PORTA = 0;
TRISA =0b00010;
PORTB = 0;
TRISB = 0;
oldstate_min=0;
oldstate_hr=0;
mode=0;
PowerOK=0;
Powerchange=0;
OutputStatus=1;
do
{
if (update == 1) // advance seconds?
Clock24(); // yes...then output
if (Button(&PORTA,1,1,1))
{
PowerOK=1;
//mode=0;
}
if (PowerOK && Button(&PORTA,1,1,0))
{
PowerOK=0;
PowerChange=1;
mode=1;
}
if (Powerchange && PowerOK) //power restore
{
Powerchange=0;
mode=0; //back to normal
}
if (mode==0)
{
if (OutputStatus==0) //turn off
{PORTA.F0=1;
PORTA.F2=1;
PORTA.F3=0;}
else
{PORTA.F0=0; //Turn ON
PORTA.F2=0;
PORTA.F3=1;}
}
else
{
PORTA.F0=0;
PORTA.F2=0;
PORTA.F3=0;
}
} while(1); // endless loop
}//~
Thursday, January 29, 2009
Oops...
But hey... I got a new project... this time, I have to be extra cautious because it involves 230v. A small mistake can be deadly. Will post the details later...
Friday, January 09, 2009
Humidity Sensor
These pictures show how small it is...
After that I had to wait another couple of weeks for the LCDs to arrive. I bought (actually I won) a 20x4 LCD character display from eBay for $9.5 including shipping. Since the program is a bit heavy, I had to use PIC16F88 which has 4k of memory. First I tested the display and it worked fine. Then I attached the SHT11 according to the guidelines given in the data sheet (with pull-up resistor and conditioning capacitor). At first it didn't work but after several attempts it worked and displayed the temperature and relative humidity. To verify the temperature figure, I hooked up another temperature sensor; DS18B20; one-wire device from Dallas. Wrote a quick and dirty procedure to display the temperature along with the rest. The difference between the temperature figures of two sensors are almost negligible. It didn't exceed 1C anytime. Based on this I assume the Relative Humidity is also correct.
Wednesday, October 22, 2008
PIC CLOCK - WITH ALARM
The demand for the alarm clock is satisfied finally. It is the same circuit and the same program as before. Only difference is that it stores alarm settings in EEPROM and having a buzzer. Unfortunately, the buzzer was not loud enough. So I’m thinking of having something louder. I’ll be able to find something from my kid’s toys collection since he’s got all types of music cars, broken and lying around.
PIC CLOCK - MATRIX DISPLAY
The display is created using a LED matrix. This is because I couldn’t find a suitable size seven segments in the market. Display comprises of four 4x7 matrices with a colon and a decimal point which is driven by two MAX7221. RTC is DS1307 with DS32KHz crystal. Temperature sensor is DS18S20. The brain of the clock is gigantic 40 pin PIC16F877A with 8k code space. Everything is assembled inside a plastic box file. Working with the two display drivers (MAX7221) was not that difficult but they didn’t work without the two 0.1uF capacitors close by. Program was slightly modified to accommodate two display drivers with the new numeric font. I designed several fonts and finally settled with the one shown.
Friday, September 12, 2008
PIC CLOCK FINAL VERSION
1. Displaying the Time, date, month and year
2. Displaying the Temperature
3. Display Time, Date & Month and Temperature Alternatively
4. Battery backup
5. Display illumination reduced at night (From 10pm to 6am)
6. Highly accurate. (DS1307 RTC and temperature compensated crystal DS32kHz)
The following video shows how the clock is in action. It displays Time, date and temperature alternatively. All the parameters (hour, minute, second, date, month, year etc.) can be set by selecting the appropriate mode and increment buttons. Display blinks when entered into the change mode. There are modes to display Time, Seconds, Date , Year and Temperature continuously. Everything is fixed inside a floppy disk box. I'm gonna wrap it with something to hide the internals, may be with a dark sticker.
Some pictures of the clock in different angles;
Parts List
Defining the SPI & I2C connection in PORTB. Display driver MAX7221 uses SPI while DS1307 RTC uses I2C.
void InitMain() {
Soft_Spi_Config(&PORTB, 4, 5, 3);
Soft_I2C_Config(&PORTB, 0, 1);
}//~
Initializing the RTC.
void ds1307_init(){
char seconds=0;
Soft_I2C_Start();
Soft_I2C_Write(0xD0); // WR to RTC
Soft_I2C_Write(0x00); // REG 0
Soft_I2C_Start();
Soft_I2C_Write(0xD1); // RD from RTC
seconds = Bcd2Dec(Soft_I2C_Read(1)& 0x7F); // Read current "seconds" in DS1307
Soft_I2C_Stop();
Delay_us(3);
Soft_I2C_Start();
Soft_I2C_Write(0xD0); // WR to RTC
Soft_I2C_Write(0x00); // REG 0
Soft_I2C_Write(Dec2Bcd(seconds)); // Start oscillator with current "seconds value
Soft_I2C_Start();
Soft_I2C_Write(0xD0); // WR to RTC
Soft_I2C_Write(0x07); // Control Register
Soft_I2C_Write(0x80); // Disable squarewave output pin
Soft_I2C_Stop();
}//~end of function
Initialize MAX7221
void max7219_init1() {
PORTA &= 0xFD; // SELECT MAX
Soft_SPI_write(0x09); // BCD mode for digit decoding
Soft_SPI_write(0xFF);
PORTA |= 2; // DESELECT MAX
PORTA &= 0xFD; // SELECT MAX
Soft_SPI_write(0x0A);
Soft_SPI_write(0x03); // Segment luminosity intensity
PORTA |= 2; // DESELECT MAX
PORTA &= 0xFD; // SELECT MAX
Soft_SPI_write(0x0B);
Soft_SPI_write(0x03); // Display refresh
PORTA |= 2; // DESELECT MAX
PORTA &= 0xFD; // SELECT MAX
Soft_SPI_write(0x0C);
Soft_SPI_write(0x01); // Turn on the display
PORTA |= 2; // DESELECT MAX
PORTA &= 0xFD; // SELECT MAX
Soft_SPI_write(0x00);
Soft_SPI_write(0xFF); // No test
PORTA |= 2; // DESELECT MAX
}
Display the values using MAX7221
void Write_7219(int x, int y) {
PORTA &= 0xFD;
Soft_SPI_write(x); // send i to max7219 (digit place)
Soft_SPI_write(y);
PORTA |=2;
}
Reading & writing to the RTC
unsigned short read_ds1307(unsigned short address)
{
Soft_I2C_Start();
Soft_I2C_Write(0xd0);
Soft_I2C_Write(address);
Soft_I2C_Start();
Soft_I2C_Write(0xd1);
data=BCD2DEC(Soft_I2C_Read(0));
Soft_I2C_Stop();
return(data);
}
void Write_DS1307(unsigned short Address, unsigned short _Data) {
Soft_I2C_Start(); // start a serial transfer
Soft_I2C_Write(0xD0); // which device, 1101000 = DS1307, + direction bit (R=1,W=0)
// thus 11010000 = 0xD0 ie write to DS1307
// need to tell the DS1307 which address is to be written to
Soft_I2C_Write(Address); // send the address to be written to the DS1307
Soft_I2C_Write(_Data); // send actual data to be written into Address on the DS1307
Soft_I2C_Stop(); // finished serial transfer (and release the I2C bus)
}
Read Temperature (DS18S20) & Display
void Read_temp()
{
ow_reset(&PORTB,2); // onewire reset signal
ow_write(&PORTB,2,0xCC); // issue command to DS1820
ow_write(&PORTB,2,0x44) ;
delay_us(120);
ow_reset(&PORTB,2);
ow_write(&PORTB,2,0xCC); // issue command to DS1820
ow_write(&PORTB,2,0xBE);
delay_ms(500);
j1 = ow_read(&PORTB,2); // get result
_Decimal = j1 & 0x01 ;
j1 = j1 >> 1 ;
}
void display_temp()
{
Read_temp();
j = j1%10;
j = j+0x80;
Write_7219(2,j);
j = j1/10 ;
Write_7219(1,j);
if (_decimal==0)
Write_7219(3,0x00);
else
Write_7219(3,0x05);
Write_7219(4,0x0F);
}
To display time, date and to edit the parameters, I wrote separate modules using the above basic building blocks. If somebody needs the schematic and the complete source / hex, drop me an email or leave a comment with the email address. I used Mikroelektronika forum (http://www.mikroe.com/forum/) heavily and almost all the above coding segments are taken from the forum. Therefore, full credit goes to all the people who contributed to the forum.
Wednesday, August 27, 2008
PIC Clock - with DS1307
Wednesday, July 30, 2008
LED (OIL) LAMP
Here is the video
Here is the code in MikroC
unsigned short j, oj,i;
void InitMain() {
PORTB = 0x0; // set PORTB to 0
TRISB = 0; // designate PORTBpins as output
PWM_Init(5000); // initialize PWM module
}//~
void main() {
CMCON=7;
initMain();
j = 127; // initial value for j
oj = 0; // oj will keep the 'old j' value
PWM_Start(); // start PWM
while (1) { // endless loop
j=rand(); // Generate Random Number
if (j>=255)
j=254;
if (j==0)
j=1;
if (j>oj)
{
for (i=oj;i<=j;i++)
PWM_Change_Duty(i); //Smoothen the level change
}
else
if (j{
for (i=oj;i>=j;i--)
PWM_Change_Duty(i);
}
else
PWM_Change_Duty(j); // set new duty ratio,
oj = j; // memorize it
PORTB = oj; // and display on PORTB
Vdelay_ms(200+j); // slow down change pace a little
}
}//~!
PIC Clock - Final Version
• Battery backup; when the mains power is not available, it automatically gets power from the batteries and keeps the clock ticking.
• Ability to work totally on batteries. i.e. When the mains power is not available, it automatically switches into battery mode and the display goes blank. But if you want to see the time, you can get back the normal display manually.
Here are some pics
(Video quality is not that great but clear enough to see that the clock is running :-) )
Friday, May 23, 2008
PIC Clock
It shows Time (Hour, Minute) and Seconds alternatively. It has two buttons to advance hours and minutes. An Interrupt routine is used to calculate the base time and to multiplex the four seven segments. The program is written in C and compiled using MikroC compiler. I got lot of ideas from so many people and used code samples from various resources. Specially the MikroC comes with very useful code samples. Here is the program listing. It is not optimized yet. You'll find unused variables here and there. Comments and suggestions are welcome.
#include "Display_utils.h"
char kraj;
unsigned short zz, v, j, countsec,displaysec;
//unsigned int i;
unsigned short por[4];
unsigned char sec, mins, hrs, ticks, correction;
char oldstate_min, oldstate_hr;
void interrupt() {
if(INTCON.T0IF)
{
ticks++;
correction++;
TMR0=101; //96; //102
if (correction==180) // Correction routine
{
ticks--;
correction=0;
}
}
PORTA = ~0;
PORTB = por[v];
PORTA = ~zz; // turn on appropriate 7seg. display
zz <<= 1;
if (zz > 8u)
zz = 1; // prepare mask for digit
v++ ;
if (v > 3u)
v = 0; // turn on 1st, turn off 2nd 7seg.
//Delay_ms(1);
//TMR0 = 0;
INTCON = 0x20;
}//~
void main() {
OPTION_REG = 0x84;
j = 0;
v = 0;
zz = 1;
TMR0 = 101;
INTCON = 0xA0; // Disable PEIE,INTE,RBIE,T0IE
PORTA = ~0;
TRISA = 0;
PORTB = 0;
TRISB = 0;
sec=0;
mins=0;
ticks=0;
correction=0;
hrs=0;
oldstate_min=0;
oldstate_hr=0;
do {
if (ticks==200)
{
sec++;
countsec++;
ticks=0;
//if (PORTB.F7==1)
// {
// PORTB.F7=1;
// }
// else
// {
// PORTB.F7=0;
// }
//}
if (sec>59)
{
mins++;
sec=0;
//}
if (mins>59)
{
hrs++;
mins=0;
//}
if (hrs>23)
{
hrs=0;
}
}
}
}
TRISB=0b00000011;
if (Button(&PORTB, 0, 1, 1))
oldstate_min = 1;
if (oldstate_min && Button(&PORTB, 0, 1, 0)) {
mins++;
if (mins>59)
mins=0;
oldstate_min = 0;
}
if (Button(&PORTB, 1, 1, 1))
oldstate_hr = 1;
if (oldstate_hr && Button(&PORTB, 1, 1, 0)) {
hrs++;
if (hrs>23)
hrs=0;
oldstate_hr = 0;
}
TRISB=0b00000000;
if (countsec==5)
{
countsec=0;
if (displaysec==1)
{
displaysec=0;
}
else
{
displaysec=1;
}
}
if (displaysec==0)
{
por[0]=mask(hrs/10u);
j=(char)(hrs%10u);
por[1]=mask(j);
por[3]=mask(mins/10u);
j=(char)(mins%10u);
por[2]=mask(j);
}
else
{
por[0]=mask(5);
//j=(char)(mins%10u);
por[1]=mask(11);
por[3]=mask(sec/10u);
j=(char)(sec%10u);
por[2]=mask(j);
}
} while(1); // endless loop
}//~
Display_utils.h file
//-------------- Returns mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
case 11 : return 0x79;
} //case end
}//~
Thursday, February 21, 2008
PIC Programming
The first step was to build a programmer (burner). I saw different types of programmers but thought of building a JDM type one. It has the advantage of operating without an external power supply and is much simpler to build. It takes power from the PC serial port. The disadvantage is, modern laptops cannot provide the required voltage level. Since most of the laptops (including mine) do not have a serial port, it has no effect.
Found the following circuit and built it on a vero board. It can program PICs upto 40 pins so there wont be any problem for a long time. (Full credit goes to the designer of the circuit, I just build his circuit)

This is how the final one looks like;
Then needed the software to connect the hardware to the PC. After reading many comments, I wanted to settle with IC-Prog. It is a great software which supports many types of programmers including the JDM. It also has a hardware test option to verify the hardware. Initially it didn't verify my hardware correctly and after so many sleepless nights, I found the bug. I have connected the Serial port incorrectly; more precisely, I have swapped the left hand side and the right hand side of the port. After rearranging, it worked like a charm.
I tested the programmer and the PIC using the famous "hello world" LED blinking program which ended quite successfully. Then I wrote a counting program using two seven segment LEDs with 16F84. Two segments are in multiplexed mode. The following video shows it in action.
These are my future plans with PICs.
- Build a clock with small digits (desktop clock)
- Build a wall clock with a big display
- Include the stealth mode to the clocks. i.e. it will retain its time when there is no mains power. I hope to use a real time clock IC like DS1307 or DS1302 with a battery backup.
- Include a thermometer function to the clock to display the room temperature. For this, I will use DS1820 IC.
Although I already have necessary hardware i.e PICs, clock ICs, temperature ICs (I got them from Dallas Semiconductors as samples), writing software takes a lot of time. Therefore it is impossible to figure out how long it will take to complete the above things. May be before next Christmas... :-)
Tuesday, March 20, 2007
Acer Aspire


My Notebook arrived yesterday. It's Acer Apire 5630 series Core 2 Duo 1.66 GHz (T5500 processor) , 15.4" Wide Screen, 1GB RAM, 160 GB HD, WiFi, 1.3 MP WebCam, 5-in-1 card reader etc. Not that flashy with compared to the notebook I dreamed from Apple (macbook). My poor cash flow prevented me from going for it. This one was $1025 (roughly SLR 115,000) and bought from Amazon. Still couldn't play around with it that much and haven't tested WiFi, LAN and Modem yet. There's a bluetooth button but specs don't say anything about it.
Today I saw the same one with 2GB RAM and nVidia GO 7000 for a lesser price ($999) in amazon. Sigh...
Tuesday, February 27, 2007
Tech-GSM, two thumbs up...!
I bought a Kingston Data traveler II 2GB pendrive for Rs 3850/- which I found very competitive pricing even when compared with the price given in Amazon.com (only Rs.150 difference). I chose DT II merely because of the data R/W speed which is mentioned as 7 MB/s write and 11 MB/s read. The maximum waiting time to write the entire capacity is less than 5 minutes. (cool...)
To my surprise, they delivered it in the same day I confirmed the order. And the product is Original Kingston which I verified via the Kingston website. Two thumbs up for Tech-GSM guys...
Thursday, June 22, 2006
Camera Mouse...!
Friday, January 06, 2006
iPod shuffle

The latest addition to my gadget collection, the iPod shuffle, arrived yesterday. Its a cool device in every aspect; size, design, quality,... everything is perfect. It may hold more than 100 songs I assume (its a 512MB) and the battery may last 12 hours according to the manual. Re-charging is possible only when it is connected to a PC via the USB. It supports a wide variety of music formats including mp3, aac, wav etc. Sound quality is good but lacking Bass Power. Its really light weight, not even an ounce. I am braining these days to find a method to connect it to my car audio.
Tuesday, October 25, 2005
My Desktop Thermo

I made this cool desktop thermo using DS1820 which is plugged into DS9097U – DB9 Com Port adapter. I got these samples from Maxim Dallas Semiconductors a long time ago but couldn’t find enough time to play around. The program is done using C# after so many trial and error efforts. It is based on the OneWireAPI.dll which can be downloaded here. The program nicely sits inside the system tray and displays the temperature when the mouse pointer hovered on to the icon. (the icon is made by me which is not in great shape…).

I have two units of DS1820s at home which are plugged into the same port, one is on the CRT (it heats up a lot; so that I can turn on the fan) and the other one lying on the desk monitoring the room temperature. The one shown in the picture is the unit in my office. (otherwise, how could I be at 23.94 Celsius; normally it’s 28-30 Celsius outside). If anyone interested about this, I am willing to share my knowledge. (even the software).