Sunday, November 1, 2009

Control Physical World Through Computer (Step by Step) - Part 2/3



4- Tools

To start dealing with hardware, it is better if you have some tools to help you, such as

Breadboard:

coolcode6

It will help you to put your wires and pins; it contains connected line (5 pins for example) with the same value so you can read it from many places.



Adapter

coolcode7

As we know, any digital device will need a VCC and Ground to work, any adapter will give you this, and it will be better if it comes with voltage controller (some devices needs more or less voltage).

Regulator

coolcode8

It is just to keep fixed voltage even if the voltage goes up, for example you can have 5V Regulator to give you 5V even if you use 9V battery.

Sample of Output Devices

  • Seven Segment: Represent Numbers using 8 LEDs.

  • Buzzer: Alarm instead of light in LED.

  • Screen: Advanced Screens using the same concept of seven segment.

  • Stepper Motors: Controlling Movement in the motor using digital signals.

Sample of Input Devices

  • KeyPad: Convert numbers or characters to binary digits.

  • Sensors: Fire Sensors, light sensors, water... etc which send custom signal when some physical event happen.

Sample of Controlling Devices

  • Buffer: Allow Signal to move whatever it is if the controller pin is equal to (One).

  • Relay: The same as buffer, but it can deal with 110/240V.

  • Microcontroller: Advanced Electronic Board, consists of multiple input, output and processing controls.

Relay and Controlling Electric Devices

By the end of this part, you must be able to control any electric device in your home. The general idea with any electric device is very simple, you have plugged cable to the power, if you cut the cable the device will switched off, if you reconnect it again it will work.

coolcode11

What we will try to do is just to put some controls, which will allow electricity to move or not depends on some value we will read it from computer. This Control as we said before can be Relay.

coolcode12

Example

There are many types of relay, each relay comes with its one datasheet, and we will choose one and explain using his datasheet.

coolcode13

In our relay we have 2 pins for controlling, and 3 pins in each side, when the control is (One) it will move the power from pin (1) to (3) in each side, else it will connect pin (1) to (2). This is how it will response:

coolcode14

There are some other types. This is one sample of it:

coolcode19

Now, back again to our work, we will use the relay instead of switch, and it will take the commands from pin2 form parallel port as VCC, and any ground (pin 25 as example):

coolcode15

Now try to run your application again, and enjoy. Just as a reminder again, open visual studio, import new inpout32.dll and write down this declaration:

 

using System.Runtime.InteropServices[DllImport("inpout32.dll", EntryPoint="Out32")]public static extern void Output(int adress, int value);

 

And to open the first data pin:

Output(888, 1);

 

For second pin type 2, third one is 4 and forth is 8 and so on. Now start implement any routine for that or for any electric device, open it through modem by calling, it is now just regular programming.

Security

In the previous example, we were connecting out electric circle directly to our parallel port, which is not safe. We must use some security circle in the middle. For example, we can use buffer gate between our parallel port and electric device in this way:

coolcode16

But we will face a problem that the output ampere from buffer will not be enough to deal with the relay, so we will add transistor to pass the power, and we will take outside VCC source to the relay:

coolcode17

 

Simplify

As we observed in the last security circle, we will have a lot of wires. And in real application, it will be very difficult to handle all of this in safe way. As a solution, electronic manufactories provide us something called (Parallel Port Interface).

coolcode18

This board consists of 8 relays with security circle, it will need only one General VCC and one Ground, and controls for each relay. It will work directly.

Algorithms

Sometime we will need to deal with more than 8 devices. For that purpose and other needs, we need to start reading about other gates. In this example, we will try to Control 8 devices using only 3 pins. for this purpose we will use Decoder. This is chart:

coolcode20

0 comments:

Post a Comment