Pages

About Lan Ahmad

My photo
Pendang, Kedah, Malaysia
It's all about my real life!!!

Solar Charging Battery Calculation

Salam. Hari ini saya akan ajar tentang cara pengiraan cas bateri menggunakan solar. Beberapa kritiria yang perlu diketahui. Disini saya akan menunjukkan contoh pengiraan tersebut.

Battery Capacity (Biasa ada tulis dekat bateri):
Battery 12V, 5Ah

Solar Specification:
12 Volt, 3W. So dari spec solar ni, kita dapat tentukan Current, I menggunakan rumus P=IV. Selepas pengiraan, I = 0.25A.

Untuk bateri dicas penuh menggunakan solar (12V, 3W):

T=Battery Capacity/Current Solar
T=5Ah/0.25A
T=20h (20 jam)

20 jam masa yang diperlukan oleh solar untuk cas penuh bateri. 20 jam ini tidak termasuk loss pada wayar dari solar ke bateri dan faktor lain-lain yang boleh mempengaruhi masa cas. Jika terdapat loss, masa charging akan meningkat. Pengiraan adalah seperti berikut:

Assume I = 0.2125A (Loss 15%)

T=Battery Capacity/Current Solar
T=5Ah/0.2125A
T=23.5h @  23 hour 30 minute

Ultrasonic Sensor (HC-SR04)



Descriptions:
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. It offers excellent range accuracy and stable readings in an easy-to-use package. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). Similar in performance to the SRF005 but with the low-price of a Sharp infrared sensor.

Specifications:

  • Power Supply :5V DC
  • Quiescent Current : <2mA
  • Effectual Angle: <15°
  • Ranging Distance : 2cm – 500 cm/1" - 16ft
  • Resolution : 0.3 cm



Sample Program Code:

 #include <16F876a.h>   
 #FUSES NOWDT, HS, NOPUT, PROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG   
 #use delay(clock=20000000)   
 #define use_portb_lcd true  
 #include "flex_lcd.c"  
 int16 distance, time;     // Defining variables   
 // Defining the pins   
 #define trig pin_A0   // Change as you wish, can use any pin in the MCU   
 #define echo pin_A1   // Change as you wish, can use any pin in the MCU   
 void main()   
 {   
 lcd_init();                // initiating the LCD   
 delay_ms(50);  
 printf(LCD_PUTC, "\f Sonar test");// for LCD & MCU restart troubleshooting   
 delay_ms(300);               // Boot-up delay, for troubleshooting   
 setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);   // initiating timer   
 while(true)   
 {  
 output_high(trig);             // ping the sonar   
 delay_us(20);              // sending 20us pulse   
 output_low(trig);   
 while(!input(ECHO))            // wait for high state of echo pin   
 {}   
 set_timer1(0);              // setting timer zero   
 while(input(ECHO))            // Wait for high state of echo pin   
 {}   
 time=get_timer1();            // Getting the time   
 distance=time*0.028 + 1.093 ;      // Calculating the distance   
 lcd_gotoxy(1,1);  
 printf(lcd_putc, "\fTime :%Lu",time); // Display the time  
 lcd_gotoxy(1,2);  
 printf(lcd_putc, "\fDistance = %Lu", distance); //Display distance  
 delay_ms(1000);   
 }   
 }  

8 August 2012 - Thursday

Interrupts



#include <pic.h>
#device adc=8
#use delay (clock=20000000)
#fuses hs,nolvp,nowdt,noprotect,nobrownout
#use rs232(baud=9600, bits=8, xmit=pin_C6, rcv=pin_C7, parity=n, stream=GSM)
#byte porta=5
#byte portb=6
#byte portc=7
#include "flex_lcd.c"
#include <string.h>

int status_ok=0;
int counter_read=0;
char string[70];
int mem1;

//--Interrupt--

#int_RDA
void serial_int()
{
   string[counter_read]=getc();
   counter_read++;
   if(counter_read==69)
      counter_read=0;

   if (string[--counter_read]=="+" && string[counter_read]=="C" && string[counter_read++]=="M")
   {
      mem1=counter_read+5;
   }
 
   if((string[counter_read]=="O") && (string[counter_read++]=="K"))
   {
      status_ok=1;
   }
}

//--Main Funtion --

void main()
{
lcd_init();
delay_ms(500);

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

lcd_putc("\fat");
fprintf(GSM, "AT\n\r");
if(status_ok==1)
{
   status_ok=0;
   lcd_putc("\fat+cmgf=1");
   fprintf(GSM, "AT+CMGF=1\n\r");
 
   if(status_ok==1)
   {
      status_ok=0;
      lcd_putc("\fcomplete");
   }
}
}

Target for tomorrow:
- Interrupts
-Get +CMTI from GSM Modem

7 August 2012 - Tuesday

Testing PIC16F876A 28-Pin board to check RS232 Communication and LED C4 run properly. RS232 is use to connect PIC board to GSM Modem. If RS232 can't send data to GSM and receive data from GSM modem. To test this PIC board, i need to write program code that can observe the incoming character from PIC board.

#include <pic.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect, nobrownout
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)

void main()
{
int count=0;
while(true)
{
printf("\f**Welcome to Malaysia**\n\r");
printf("**counter value is %u **", count);
count+=1;
delay_ms(1000);
}
}

Then, PIC need to check the outgoing character from PC to PIC.
#include <pic.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect
#byte portb=6
#byte portc=7
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)
#include "flex_lcd.c"

int mystatus=0; //here can't declare byte coz not detected by compiler
char mydata;

void main()
{
int count=0;

lcd_init();
printf("Enter your character : A or S or Z or X");
lcd_gotoxy(1,1);
lcd_putc("Testing");

while(true)
{
if(kbhit()) //monitor incoming charactor from RS232
{
   mydata=toupper(getch()); //receive charactor dan save in mydata
   printf("\n\rYou entered: %c",mydata); //display on hyper terminal
   count++;
   mystatus=1;
}
if (mystatus==1)
{
if(mydata=='A')
{ output_high(pin_c4);
  lcd_gotoxy(1,2);
  lcd_putc("led on");
} //led on
if (mydata=='S')
{ output_low(pin_c4);
  lcd_gotoxy(1,2);
  lcd_putc("led off");
} //led off
if (mydata=='Z')
{ output_high(pin_c3);
  lcd_gotoxy(1,2);
  lcd_putc("relay on");
} //buzzer on
if (mydata=='X')
{ output_low(pin_c3);
  lcd_gotoxy(1,2);
  lcd_putc("relay off");
} //buzzer off
mystatus=0;
}//end if
}//end while
}//end void main

6 August 2012 - Monday

receive sms

GSM Modem Overview


A GSM modem is a wireless modem that works with a GSM wireless network.  The main difference between GSM modem and dial-up modem is the medium of sending and receiving data. Dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves.

A GSM modem can be an external device or a PC Card / PCMCIA Card. Typically, an external GSM modem is connected to a computer through a serial cable (RS232) or a USB cable.  Like a GSM mobile phone, a GSM modem requires a SIM card from a wireless carrier in order to operate.

Computers use AT commands to control the GSM modems. Both GSM modems and dial-up modems support a common set of standard AT commands. In addition to the standard AT commands, GSM modems support an extended set of AT commands. These extended AT commands are defined in the GSM standards. With the extended AT commands, GSM modem can do:

  • Reading, writing and deleting SMS messages.
  • Sending SMS messages.
  • Monitoring the signal strength.
  • Monitoring the charging status and charge level of the battery.
  • Reading, writing and searching phone book entries.

The number of SMS messages that can be processed by a GSM modem per minute is very low - only about six to ten SMS messages per minute.

Source : Developer's Home

3 Ogos 2012 - Friday

Receive SMS for GSM Modem

AT command
Meaning
+CNMI
New message indications
+CMGL
List messages
+CMGR
Read messages
+CNMA
New message acknowledgement

Read Receive SMS on GSM Modem
Hyper Terminal : List SMS from SIM

2 Ogos 2012 - Thursday

Hyper Terminal: Message Indication


Hyper Terminal: Delete Selected SMS from SIM