The Positive You

No Comments

The Positive You!is about your relationship with yourself, your individuality, attitude, strengths as well as fears, worries and even disappointments. It reveals how fragile you are as a human being and yet how powerful you can be. With its straight forward approach, rich quotations, real life cases and humor, it makes you realize how strong your mind is. Your attitude dictates whether you see the good or bad in your life, and that you are in control and no one else.

SCREW IT, LET’S DO IT

No Comments

This is a very nice book; written by Richard Branson. (Owner of Virgin Group (Over 360 Companies). He shares a lot of his wisdom in this book, the wisdom that made him the successful man he is now. We need to read such books, especially after long day of dealing with people that just try to put you down. I have read this book a long time ago, and just remembered it now after few situations that I faced at work; where some people just want to prove that I didn’t deserve to get promoted!. This is exactly one of things that this book discuss, and helps you to ignore such people, and just keep going by having the spirit of “SCREW IT, LET’S DO IT!”.

Salah Al-Din Al Ayoubi

No Comments

I found a book (Arabic) about Salah Al-Din, and he is a very famous Muslim Leader. He led Islamic opposition to the Franks and other European Crusaders in the Levant. At the height of his power, he ruled over Egypt, Syria, Mesopotamia, Hejaz, and Yemen. It’s nice when you start reading such book, where it takes you back to the glory days, and you learn some how some of the manners of such great guy. It’s rare to find such kind of person; and we really need such person on our side of the world.

25 Success Stories

No Comments

This is a very interesting book to read, it has 25 success stories for people who knew what to do, and knew that they were not supposed to give up.

The book is available for free at the author website: http://www.shabayek.com/ . The author name is Raouf Shabayek, and he has many other interesting books. I would really advise you to read this book; along with the other books over there. I started reading the other books; and they are really nice.

PHP & MySQL Tutorial – Part 0.5

No Comments

Hello New Programmer..

So you are interested in learning PHP & MySQL !. Well I have some good news for you, I’ll try to place here a series of tutorials, where you start from scratch, even if you had never did any web application programming before; you would be able to just start and get some results soon.

Some of the information over here took me a long time to get, especially that when I first started learning PHP; I did by try and error, and by reading stuff from here and there.

Ok, get ready for now, and the most important thing, is to believe that you can do it!! And believe me; yes you can.

Before We Start

You might be wondering right now if you will have to pay any amount as a requirement to build your webpage!. You probably would be thinking that you should buy a domain on the internet! Well the good news is that you can do it all for free!!.

PHP and MySQL are open sources, that means they are free!. The first thing we would do now, is to install on your PC what is required to get started.

The first time I tried to install PHP and MySQL (and Apache Server ~we will discuss this) turned out to be a nightmare (actually they were nightmares!!) Finally I found one magical solution that made my life much easier. That was a free software called WAMP which would install everything and get you ready into programming in less than 5 minutes!.

This software will install Apache server on your PC, this Apache is the application that will turn you PC into a web server (literally).

For now, go to the below link, download this program and just install it on your PC. (And trust me, nothing wrong will happen)

http://www.wampserver.com/en/download.php

After installation is completed, you will see a small a new white icon in your system Tray. This icon should turn completely white (Not yellow, nor red).

Having this icon white means that you are ready to Rock & Roll!

What is all about?

Before we dig into the subject, it’s good to know what type of different web pages you usually face while browsing the net. There are mainly two types of web pages, static and dynamic.

Static Pages are just as their name indicates, they are static!! This means there is no interaction between the user and those pages, their display is usually fixed, and fields to enter any information, (Such as name, email, etc…). Beside that their contents will change only if the person who made them opened those files and updated them.

Such kind of web pages are fine if you were planning to have fixed contents on your website. Such as making a site to display one story and that’s it.

The website will be made using HTML script. To make such a page you don’t really need to learn the HTML script. An easy way to do it, is to use Microsoft Word, crate whatever document you like, and then finally save it as HTML. This saved file can be used as website file.

Well, for today we are going to try create a static web page, and we will use our newly installed WAMP server to demonstrate how it’s going to be used later on.

Open Microsoft Office

On a new file type down:

Hello World !!

Use any font and size you like.

Then FileàSave AsàWeb Page (*.html, *.htm) name the file as index.html

Save the file on the desktop for now. (Note: You might get a warning letter, just click yes).

Copy the index.html file that you had just created, and copy it to the below folder on your PC.

C:\wamp\www

Well, as you guessed, this folder is inside the newly magical installed program, and www folder would represent your web server root folder! (Cool right!).

Now, go to your web browser (Internet Explorer or FireFox) and write down the below address:

http://localhost/

And voila!!

Fine below some answers for the questions that you had been thinking about:

 

Why http://localhost/ Well the server is installed on you PC, and the default address for it would be localhost (Local Host).
Why

index.html

Notice that you had typed the address as http://localhost/only without specifying the file name. Well files with index are the default files to be displayed when you enter the web address name. This means when you visit a website let us say www.antcircuits.comthe first web page to be displayed has the name index. (More details about this later).

 

As an exercise for you now, try to make another web page, and call it test.html

You should place it in the same folder i.e. C:\wamp\www

And then to access it through your web browser, you will need to type the below address:

http://localhost/test.html

I believe this is enough for today, next tutorial we will start little bit with PHP.

Keep the good work, and don’t forget to brush your teeth before you sleep!. And if you have idiots at your work place, just try as much as possible to ignore them!.

PHP & MySQL Tutorial – Part 1

No Comments

The first Article of this series was called Part 0.5 since that it didn’t discuss PHP. And somehow it was catchyJ.

In this article we will start little bit with PHP coding, but before that we need to discuss something very important. Please follow the below to the end, and later on you will get the full image. (Just be patient, and try to follow things step by step).

In the last article you had created one file called index.hml. Get that page loaded again by using your browser, and going to http://localhost/ . (Note: Make Sure that WAMP is running!).

In the Internet Explorer Page, right click and then click “View Source”.

There you would see the HTML codes of the page.

<html><head>

<meta http-equiv=Content-Type content=”text/html; charset=windows-1252″>

<meta name=Generator content=”Microsoft Word 14 (filtered)”>

<p class=MsoNormal>Hello World !!</p>

</body>

</html>

Note: If you applied any formatting on the Hello World, you will see more codes over there. The common thing is that you would see Hello World!!.

Where That Came From?
Well, Microsoft Office Took care of generating that code for you. You can see that somewhere within those codes, you Hello World!! Does exist.

 

Fine, I need you to do one more thing, which is opening the index.html using note pad. You will find that the same HTML codes are over there.

PHP way!

Now, open Notepad (StartàProgramsàAccessoriesàNotepad)

Write the below over there:

<html><head>

<body>

<?php echo(“Hello World!!”); ?>

</body>

</html>

Save the file as index.php, and copy that file to c:\wamp\www directory.

Note: Delete index.html please!

 

Now, using Internet Explorer; go again to http://localhost/

Again, right click, and View Source. Below HTML code will be shown:

<html> <head> <body> Hello World!! </body> </html>

 

Remember now, you wrote something in your php file saying echo, right?

But here you cannot see it!! Where has that gone! Well, your server had translated that into HTML !.

Now, remember the below; since this will remain with you for the rest of your life as a PHP programmer!

PHP script is inserted between thestart up tag <?php

and the closing tag ?>

Ex: <?php echo(“Hello World”); ?>

You web page should include at least the following HTML codes (It can work without them, but results are not guaranteed!).<html>

<head>

<body>

</body>

</html>

Contents of the webpage will be placed between <body> and </body> tags.

 

<? Can be used instead of <?php as a short form. (But this will require some modification which we will carry on in the next tutorial (Well, I need to keep you excited for the next one, right?)

 

echo is the first PHP function that you had used. It’s used to print out whatever entered between the parenthesis.

Example: echo(“I am an PHP Programmer”); à will display è I am an PHP Programmer

 

Don’t forget the semi colon at the end of every PHP command.

 

What Had Happened!

Please read the below carefully, and it’s ok to read it twice or trice! The below is really important to grasp at this stage, thus things will be clear forever. (Ok not everything will be clear, we are just talking about PHP and coding; don’t expect this to make behavior of crazy and psycho people you meet in life clear!).

When you entered http://localhost/ in you browser and Enter was hit, your browser sent a request to fetch the index page located in the localhost server. (Which is your PC that is running Apache server!)

(Note: If you don’t know what Server means, please do some googling, that’s what google was made for!)

Apache server will find that the index page is in PHP format (remember; you saved the file as index.php)

The server will not pass the index file as it is this time (Not like what happened when we had index.html). The server will process the php file, and generate the HTML codes based on the PHP codes existing in your PHP file. (In this case, the output of <?php echo(“Hello World!!”); ?> was Hello World!!

The HTML codes will be sent to your browser.

FIN!.

 

Ok, I hope that you were not expecting to have a webpage similar to google.com from the second tutorial; the journey is still long, and a lot of hard work to be carried out! Wait for the next tutorials, and please feel free to contact me if you have any questions or suggestions.

Data Logger

1 Comment

After many trials, finally I was able to complete this small project which had been in my mind for a long time.

A data logger that store information on SD card. Using PIC18F4550, and one SD card socket I was able finally to complete this project. One Analogue input was added to the board where any analogue sensor can be placed over there. (As of now I am using a temperature sensor (NTC).

The PIC program was made using MikroC. (This made programming PIC much simpler, and saved a lot of time with its gerat libraries)

Below the final circuit picture.

My plan now is to write a small application that would get the logged data, and based on scaling information entered to the software; correct values would be calculated and plotted.

Please let me know if you were trying to build a similar project, and I’ll help you as much as possible.

Code:

// MMC module connections
sbit Mmc_Chip_Select           at LATA5_bit;  // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISA5_bit;
// eof MMC module connections
long int temp_res;
const LINE_LEN = 16;         ///012345678901234
char file_contents[LINE_LEN] = "XX,XXXXXXXXXXXX";
int temp;
char           filename[] = "TempLogF.TXT";
int i;
unsigned short loop, loop2;


char txt[12];

void M_Create_New_File() {

  Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
  Mmc_Fat_Assign(&filename, 0xA0);          // Find existing file or create a new one
  Mmc_Fat_Rewrite();       
  PORTD=0xFF;                 // To clear file and start with new data
  for(loop = 1; loop <= 9999; loop++) {
   PORTD=0b10100000;
  Delay_1sec();
    Delay_1sec();
    Delay_1sec();

     PORTD=0b01000000;



    file_contents[0] = loop / 10 + 48;
    file_contents[1] = loop % 10 + 48;
    
    temp_res = ADC_Read(2);
    LongIntToStrWithZeros(temp_res, txt);
    file_contents[3] = (temp_res / 1000) + 48;

    for(i=4;i<=14;i++)
    file_contents[i] = txt[i-4];

    Mmc_Fat_Write(file_contents, LINE_LEN-1);   // write data to the assigned file
    Mmc_Fat_Write("\r\n", 2);   // write data to the assigned file
   // Mmc_Fat_Write('\n', 1);   // write data to the assigned file
    Delay_1sec();
    Delay_1sec();

  }
}



// Main. 

void main() {
  ADCON1 = 12;                  // Configure AN pins as digital
  CMCON  |= 7;                     // Turn off comparators
  TRISD=0x00;
  TRISA=0b00001111;
   
   PORTD=0b10100000;
   Delay_1sec();
   Delay_1sec();
   PORTD=0b01100000;
   Delay_1sec();
   Delay_1sec();



  // Initialize SPI1 module
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
   Delay_ms(10);

   if (Mmc_Fat_Init() == 0)    // reinitialize spi at higher speed
  {
  PORTD=0b11100000;
    SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    M_Create_New_File();

    PORTD=0b11100000;
   
    while(1)
    {
         PORTD=0b11100000;
         Delay_1sec();
         Delay_1sec();
         PORTD=0x0;
         Delay_1sec();
         Delay_1sec();
     }
  }
  else {
        PORTD=0b01000000;


  }

}

Download Hex File (Finally!!)

Vibration Sensor

No Comments

Finally, and after many attempts to get some results, I got a nice graph on my computer coming from a small vibration sensor that I bout from ebay. It was a big challenge for me (and there are more challenges to come); since that it had been the first time for me to deal with USB port programming, for both Microcontroller and PC.

My aim of this project is to have a vibration data logger, along with possibility to view real time vibrations on the PC.

Best way to work with any project is to divide it into parts, the first part was to establish communication between a Micrcontroller & PC. Utilizing PIC18F4550 gave the possibility for that. Below a schematic for the circuit that I used to get this done.

After a number of trials, I was able to get the data coming out from the chip to the PC.

The Microcontroller was programmed as HID (Human Device Interface); but still it is possible to send and receive data that way. (And no need to write a special driver for your device).

 

 

Next step was reading the data coming from the vibration sensor. At this stage I struggled a lot, geting wrong information on the PC after many trial would just get you crazy. Finally I decided to wake up, and read more. Going through some books once again, and most important thing was going through PIC18F4550 datasheet helped me to figure out where I went wrong!. (I am used to deal with PIC16F778, but configuration bits for the timer were different on PIC18F4550).

After getting my Micrcontroller fixed, finally I started getting realistic values (The more I vibrate the sensor, the higher the values I was getting. (Hurrraaaaayyyyyyy).

 

Below a photo for the sensor that I used for this project (The Vibration Sensor), It’s really a very simple sensor, with three terminals only, Output, Vcc, and Gnd.

The only information I was able to find about this sensor is below:

* Digital input module
* Can sense the weak vibration signals
* Switch life: up to 10 million seconds
* Open circuit resistance: 10Mohm

The Digital Vibration Sensor is a digital Plug and Play sensor blocks. It can sense the weak vibration signals, which can be realized with the shock interaction with relevant works.

Product Performance:
* The conductive pin will make an instant turn-on (ON) state when touched by the outside force to achieve the proper vibration force, or an appropriate speed from the (partial) energy.
* No direction, any angle may burst.
* The switch is suitable for small-current circuit (secondary circuit) or (IC) of the trigger.
* At room temperature and normal use the next switch service life is up to 10 million times (times/1sec).

But many thanks to Mr. Sarfraz Dairkee who explained to me exactly how this sensor worked, and what kind of output would be expected from it. And he was really the main person that encouraged me to keep going with this project.

After getting realistic information, it was time to write a PC application that would plot the information. So far, I had been using a USB Terminal software used for monitoring data flow between PC and USB port.

I used my loved programming language C#.NET to write this program, and again, I started without clue on how to do that; but a lot of reading, digging, and googling always help!.

Below some photos for the circuit, and the monitoring program. As of now I am able to read proper values from the sensor, and I am able to send the information to the PC. The next step would be storing data on an SD card. This I have already started working on, but as usual, nothing is so simple. First obstacle was the 32MB SD card that I had. It turned out that it was not possible to read data to this card using PIC18F4550!. Today I am planing to get out and by a new 1GB card. More about this in Part 2.

Loaded Bins Detection Using Ultrasonic Sensor

No Comments

This project was really nice to work on. Beside having it implemented; having all the staff motivated to work with something new; gave good feeling. We have one machine that washes bins automatically when charged in the bin conveyor system as dirty. Those bins are supposed to be empty, since that one machine at the entrance of the bin washer would turn the bins upside down; and again at the exit another bin turner would turn the bins back to their original position. This “Turning” is required otherwise bins would get out from the bin washer full with water.

The main problem since start up; was having operators sending loaded bins as dirty.. Thus you can imagine what would happen to plates, spoons, etc.. when the bin is being turned upside down. Without forgetting the damage caused to the bin turner and the conveyors.

 

One solution that we thought about was installing an ultrasonic sensor that would detect presence of items in the bin. During one lucky night I found one ultrasonic circuit on ebay that made the entire thing possible. That circuit had a microcontroller that could be programmed to give an output when the measured distance is below a certain value. (That could be configured too.). Below a photo for this ultrasonic circuit along with its technical details:

Features:

  • Ultrasonic display module use small microcomputer system controller ,use STC 10F04XE, fully compatible with 51 microcontroller
  • IO port output pins, two switch output terminal, three key features, three digital display.
  • With DS18B20 temperature compensation circuit Contact Interface
  • Ultrasonic Ranging Module can be used directly measured the distance, you can set the distance alarm.
  • The system can provide ranging program can display panel of the schematic diagram.
  • Wide-voltage : DC 6~12V
  • Work current : 45mA
  • Range : 0 ~ 400 cm
  • Maximum measurement distance : 500cm
  • Test object : about the size of 6cm
  • Size: 45 * 44 * 12 mm

 

Switch Output:
  • this module’s outputs can be user-defined
  • Press and hold S1 button for 3 seconds, showing LLL
  • Press the S1 key, displays a number (eg 001), Is the smallest measurement distance. When the measured distance is less than this value,OUT2 will output a high level(4.5V)
  • this value can adjustable, use S2 + , use S3 –, to change.
  • When setting the minimum measured value end, then click the S1 key, the display appears HHH, can set Max distance value, Press the S1 key, displays a number (eg 200), Is the max measurement distance. When measuring the distance is greater than this value, OUT1 will output a high level (4.5V). this value can adjustable, use S2 + , use S3 –, to change.
  • when setting is end. press the S1 key,Save this value. With power-down memory function.

Thus the entire idea was to place the sensor above the bin at the entrance of the bin turner. Identifying the measured distance in case of empty bin would be our reference and set point for the sensor. If detected distance is less than that; that would mean presence of items inside the bin!!

The other challenge was avoiding the bins edges (for sure measured distance when the edge passes below the sensor would be less than our setpoint. For that purpose a retro reflective sensor was also installed.

Interfacing the output coming from the sensor with the retro reflective senors along with our bin conveyor system to stop the bin in case of detecting a loaded bin; required a small interface circuit to be designed for this purpose.

When a loaded bin was detected; the N.O output was used to cause the system go into Maintenance Mode; and thus stop. That would also reflect on the monitoring system at the control room.

Currently our bin turner is safe from any intruders!! and the funniest part is when our trap stops some bins loaded with chocolate bars loaded by mistake as dirty bin.!!!

Power Monitoring Project – Part 2

1 Comment

Guess what!! The entire project was completed, and it’s running right now!!!

ModBus windows application had been completed, and it’s doing as expected. (Writing data into MySQL database).

Another thing is the web application, which had been implemented using CakePHP

In this article I’ll just discuss about the web application and discuss what kind of information it’s displaying.

 

Below the main menu which will be used to navigate throughout the system:

First icon is HOME, which will just send you back to the home page of the Monitoring System.

This icon is for Comparison, where it shown a pie for power consumption of all the connected equipment .

This icon will display live power consumption graph for the selected equipment. The displayed graph in the system will keep refreshing every 60 seconds. And hovering the mouse above the graph will display the consumption in Kh.

 

Clicking on this icon will display a summary for the selected equipment power consumption, and power cost. It will show cost for one day, last 7 days, and last 30 days.

 

Utilization of each machine can be monitored easily; since that have machines switched off would for sure reflect on the power readings. This information is displayed using this icon.

 

Finally this function is used to display power consumption during a defined interval.

Kindly note that if you need to work on a similar project; I am ready to share all information you require. Just contact me.