How To Make Battery operated heater


Here is a simple heater circuit that can be operated from a 12V battery. The first part of the circuit is an astable multivibrator build around the two transistors Q1 and Q2 .The ON time of transistor Q2 is set to 0.5 S. The ON time of transistor Q1 can be varied by using the POT R2.The output pulses at the collector of Q2 is used to drive the Darlington power transistor Q3(TIP122).The transistor Q3 drives the heating elements L1 to L3.The net heat produced can be varied by  selecting the desired combination of heating elements at the output circuit sing switches S1 and S2.The net heat can be also varied by varying the duty cycle of the triggering pulse using POT R2.
Circuit diagram with Parts list.



Notes.




  • The circuit can be assembled on a general purpose PCB.
  • The transistor Q3 must be fitted with a heat sink.
  • The elements L1 to L3 can be 10W heating coils.
  • The switches S1 and S2 must be able to withstand at least 5A.
  • The circuit can be powered from a 12V battery.
  • The LED D1 gives a visual indication of the duty cycle of the circuit.

Read More

Automatic Speed Controller For Fan and Cooler

During summer nights, the temperature is initially quite high. As time passes, the temperature starts dropping. Also, after a person falls asleep, the metabolic rate of one’s body decreases. Thus, initially the fan/cooler needs to be run at full speed. As time passes, one has to get up again and again to adjust the speed of the fan or the cooler.
The device presented here makes the fan run at full speed for a predetermined time. The speed is decreased to medium after some time, and to slow later on. After a period of about eight hours, the fan/cooler is switched off.
Fig. 1 shows the circuit diagram of the system. IC1 (555) is used as an astable multivibrator to generate clock pulses. The pulses are fed to decade dividers/counters formed by IC2 and IC3. These ICs act as divide- by-10 and divide-by-9 counters, respectively. The values of capacitor C1 and resistors R1 and R2 are so adjusted that the final output of IC3 goes high after about eight hours.


Fig.1 Circuit diagram  for automatically speed control  for fan / air - collers 

The first two outputs of IC3 (Q0 and Q1) are connected (ORed) via diodes D1 and D2 to the base of transistor T1. Initially output Q0 is high and therefore relay RL1 is energised. It remains energised when Q1 becomes high. The method of connecting the gadget to the fan/cooler is given in Figs 3 and 4.

It can be seen that initially the fan shall get AC supply directly, and so it shall run at top speed. When output Q2 becomes high and Q1 becomes low, relay RL1 is turned ‘off’ and relay RL2 is switched ‘on’. The fan gets AC through a resistance and its speed drops to medium value. This continues until output Q4 is high. When Q4 goes low and Q5 goes high, relay RL2 is switched ‘off’ and relay RL3 is activated. The fan now runs at low speed.



                   Fig.2 Existing arrangement for fan speed control 

Throughout the process, pin 11 of the IC3 is low, so T4 is cut off, thus keeping T5 in saturation and RL4 ‘on’. At the end of the cycle, when pin 11 (Q9) becomes high, T4 gets saturated and T5 is cut off. RL4 is switched ‘off’, thus switching ‘off’ the fan/ cooler.


                       Fig.3 Modified arrangement for speed control

Using the circuit described above, the fan shall run at high speed for a comparatively lesser time when either of Q0 or Q1 output is high. At medium speed, it will run for a moderate time period when any of three outputs Q2 through Q4 is high ,while at low  speed  it  will run for  a  much  longer  time  period  when any  of  the four  outputs  Q5  through  Q8 is  high.

If one  wishes, one  can make the fan run at  the  three speeds  for an equal amount  of  time  by  connecting  three decimal  decode  outputs  of  IC3 to each  of  the  transistors  T1 to T3. One can also get  more than three speeds by  using  an additional  relay, transistor, and associated components, and  connecting  one  or  more  outputs  of  IC3 to it.

In the motors used in certain coolers there are separate windings for separate speeds. Such coolers do not use a rheostat type speed regulator. The method of connection of this device to such coolers is given in Fig. 4.


Fig.4 Speed control arrangement for cooler with different windings for various speed 

The resistors in Figs.2 and 3 are the tapped resistors, similar to those used in manually controlled fan-speed regulators. Alternatively wire-wound resistors of suitable wattage and resistance can be used.
Read More

Control Electrical appliances through telephone lines


Here is a teleremote circuit which enables switching ‘on’ and ‘off’ of appliances through telephone lines. It can be used to switch appliances from any distance, overcoming the limited range of infrared and radio remote controls.

The circuit can be used to switch up to nine appliances (corresponding to the digits 1 through 9 of the telephone key-pad). The DTMF signals on telephone instrument are used as control signals.The digit ‘0’ in DTMF mode is used to toggle between the appliance mode and normal telephone operation mode. Thus the telephone can be used to switch on or switch off the appliances also while being used for normal conversation. The circuit uses IC KT3170 (DTMF-to-BCD converter), 74154(4-to-16-line demult-iplexer), and five CD4013 (D flip-flop) ICs. The working of the circuit is as follows.

Once a call is established (after hearing ring-back tone), dial ‘0’ in DTMF mode. IC1 decodes this as ‘1010,’ which is further demultiplexed by IC2 as output O10 (at pin 11) of IC2 (74154). The active low output of IC2, after inversion byan inverter gate of IC3 (CD4049), becomes logic 1. This is used to toggle flip-flop-1 (F/F-1) and relay RL1 is energised. Relay RL1 has two changeover contacts, RL1(a) and RL1(b). The energised RL1(a) contacts provide a 220-ohm loop across the telephone line while RL1(b) contacts inject a 10kHz tone on the line, which indicates to the caller that appliance mode has been selected. The 220-ohm loop on telephone line disconnects the ringer from the telephone line in the exchange. The line is now connected for appliance mode of operation.



If digit ‘0’ is not dialed (in DTMF) after establishing the call, the ring continues and the telephone can be used for normal conversation. After selection of the appliance mode of operation, if digit ‘1’ is dialed, it is decoded by IC1 and its output is ‘0001’. This BCD code is then demultiplexed by 4-to-16-line demultiplexer IC2 whose corresponding output, after inversion by a CD4049 inverter gate, goes to logic 1 state.

This pulse toggles the corresponding flip-flop to alternate state. The flip-flop output is used to drive a relay (RL2) which can switch on or switch off the appliance connected through its contacts. By dialing other digits in a similar way,other appliances can also be switched ‘on’ or ‘off .’

Once the switching operation is over,the 220-ohm loop resistance and 10kHz tone needs to be removed from the telephone line. To achieve this, digit ‘0’ (in DTMF mode) is dialed again to toggle flip-flop-1 to de-energise relay RL1, which terminates the loop on line and the 10kHz tone is also disconnected. The telephone line is thus again set free to receive normal calls.

This circuit is to be connected in parallel to the telephone instrument.
Read More

Microcontroller-Based Speedometer-Cum-Odometer

Normally, digital speedometers are found only in luxury cars and high-end motorbikes. Even if your motorbike has a mechanical speedometer, what will you do when it gets damaged? First, you need to replace the mechanical worm gear and then the cable.

Anyway, we describe here how to build a digital speedometer-cum-odometer for your motorbike. The circuit uses a microcontroller, an LCD display and some commonly available components. It is a better alternative to the mechanical speedometer and even a beginner with minimal skill level can assemble it.

The features of the digital speedometer-cum-odometer are:

1. Digital readout
2. Speed displayed in km/hour
3. Distance traveled displayed in kilometres
4. Readings saved in non-volatile memory (EEPROM)
5. Reliability due to use of the microcontroller
6. No mechanical wear and tear
7. Home-brewed speed transducer/sensor
8. Self reset to zero after completion of 99,999.9 km
9. Easy to build and fix onto the bike

Calculations

You first need to know the radius of the bike’s front wheel. The calculations here are based on Hero Honda’s Splendor model. The radius of the front wheel is 30 cm. (This can vary with the brand or model.)

Circumference of the wheel= 2πr (where ‘r’ is in cm)
= 2×3.14×30
= 188.4 cm or 1.884 metres

Speed. Let’s assume that in 1 second the wheel
completes one revolution. In other words, in one second, the bike has covered 1.88 metres. Therefore the speed in km/hour:

N×1.88×3600/1000
= N×6.784 or N×6.8
where ‘N’ is the number of revolutions per second.
‘6.8’ is a constant and only ‘N’ varies; for example, if ‘N’
is 5, the speed equals 5x6.8= 34 km/hour.

Distance. The odometer is updated every 100 metres.
To cover 100 metres, the wheel is required to make approximately 53 revolutions (100/1.88). The microcontroller takes care of the tasks of revolutions counting, speed calculation, conversion and display of results.

Circuit description



The circuit of the microcontroller-based digital speedometer-cum-odometer is shown in Fig. 1. The functions of various components used in the circuit are described below.
  
Microcontroller. A 20-pin AT89C2051 microcontroller from Atmel is used here because of its low pin count, affordability and compatibility with CISC-based 8051 family. All the available pins of the microcontroller are utilised in the project. This microcontroller features 2 kB of Flash, 128 bytes of RAM, 15 input/output (I/O) lines, two 16-bit timers/counters, a five-vector two-level interrupt architecture, a full-duplex serial port, a precision analogue comparator, on-chip oscillator and clock circuitry.
  
LCD module. To display the speed and distance traveled, we have used a 16×2 alphanumeric
LCD based on HD44780 controller. The backlight feature of the LCD allows data to be visible even at night.

Serial EEPROM. The readings of the distance traveled are saved in an external serial EEPROM. Here, a 24C02 serial EEPROM based on Philips I2C protocol is used.

I2C bus protocol. The I2C bus consists of two active wires and a ground connection. The active wires, serial data line (SDA) and serial clock line (SCL) are bidirectional.
  
Every device hooked up to the bus has its own unique address, no matter whether it is an MCU, LCD driver, memory or ASIC. Each of these chips can act as a receiver and/or transmitter, depending on the functionality.Obviously, an LCD driver is only a receiver, while a memory or I/O chip can be both transmitter and receiver.
  
The I2C bus is a multi-master bus. This means that more than one IC capable of initiating a data transfer can be connected to it. The I2C protocol specification states that the IC that initiates a data transfer on the bus is considered the bus master. Bus masters are generally microcontrollers. Consequently, all the other ICs are regarded as bus slaves at that instant.
  
Let’s assume that the MCU wants to send data to one of its slaves. First, the MCU will issue a START condition. This acts as an ‘attention’ signal to all of the connected devices. All ICs on the bus will listen to the bus for incoming data. Then the MCU sends the address of the device it wants to access, along with an indication whether the access is a ‘read’ or ‘write’ operation. Having received the address, all ICs will compare it with their own ad-dress. If it doesn’t match, they simply wait until the bus is released by the stop condition. If the address matches, the chip will produce a response called ‘acknowledge’ signal. We have used write operation in this project.

Once the MCU receives the acknowledge signal, it can start transmitting or receiving data. In our case, the MCU will transmit data. When all is done, the MCU will issue the stop condition. This signals that the bus has been released and that the connected ICs may expect another transmission to start any moment.

We have several states on the bus: start, address, acknowledge, data and stop. These are all unique conditions on the bus. In our project, the microcontroller is the master and the serial EEPROM is the slave.
  
The readings are periodically stored in the EEPROM and the previous reading is retrieved from the EEPROM each time the bike is started.
  
Speed sensor. For this project, we make use of a simple home-made speed transducer. The rotation of the wheel is sensed by the combined action of a reed switch and a magnet fixed on the wheel. The sensor sends a pulse to the microcontroller each time a revolution is made.
  
Optocoupler. An optocoupler is used to counter the effects of bouncing when the contact of reed switch is closed.
  
Power supply. The power supply for various parts of the circuit is drawn from the vehicle’s 12V battery after reducing it to 5V using a three-terminal voltage.

Software

The ‘Init_EEPROM’ and ‘Speedo’ source codes of this project are written in Assembly language. These are compiled using an open-source ASEM-51 assembler to generate the Init_EEPROM.hex and Speedo.hex files. The hex files are burnt into the microcontroller chip.
  
Two internal timers of the microcontroller are configured as 8-bit counters to count the number of pulses generated by the speed sensor. One timer is used to measure the distance and the other for speed calculation.
  
A software delay of one second is generated after the speed counter is triggered. The speed count value is obtained from the counter registers. To speed up the process, a look-up data table is stored in the ROM that helps the microcontroller to convert the number of pulses into the corresponding speed values. The program flow-chart is shown in Fig. 2.
  
The ‘distance’ counter is incremented every 100 metres. The wheel has to make 53 revolutions to achieve this. The distance counter is loaded with an initial value of 203 (255-53+1) and is incremented on each revolution. After 53 counts, the timer overflows and generates an interrupt to notify the microcontroller that 100 metres are covered.
  
In the interrupt service routine, the microcontroller updates the corresponding ‘DS1’ distance variable. Instead of saving distance variables after each cycle, the microcontroller saves these readings when the vehicle is athalt (speed is 00.0 km/hour). In other words, when the vehicle is stopped at traffic signals or before the ignition key is turned off, the last reading is saved to the EEPROM. The same reading is again retrieved from the EEPROM when the bike is turned on next time and the readings are updated for each trip.

Construction
The reed switch and a magnet need to be fixed on the front wheel of the motor bike (Hero Honda’s Splendor). A small circular magnet (about 2 cm in diameter), normally used in speakers of small toys, can be used. Fix the magnet to the central drum of the wheel just below the spokes connected to the drum. Secure the magnet using hot glue or Araldite.
     
For fixing the reed switch, a PVC pipe contraption needs to be made so that the magnet and reed switch are aligned as shown in Fig. 3. The materials required to build the contraption are shown in Fig. 4. Cut a 3.2cm diameter PVC pipe measuring 15.2 cm in length perpendicularly into two halves. Use only one half of the PVC pipe. Mount and secure the reed switch using Araldite and cable ties on the plastic handle (normally used in emergency lights). Once it dries up, solder two wires to the two opposite end leads of the reed switch. Fix the plastic handle on the half cut PVC pipe using screws. Now, place the pipe on the front shock-absorber fork such that reed switch faces towards the magnet.


Connect a multimeter, set in continuity mode, to the two wires coming from the reed switch. Rotate the wheel slowly and see whether the reed switch closes when the magnet passes across it. If it does, the multimeter will give a continuity beep. When the magnet moves away from the reed switch, the beep will stop, indicating that the reed switch is open. Make a few trials to find the optimal position for mounting and fixing the PVC pipe such that the reed switch works smoothly. Mark the location on the front shock-absorber fork.

Now you can fix the PVC pipe contraption to the shock-absorber fork using hot glue as shown in Fig. 5. Use liberal amount of hot glue to secure it to the pipe. Carefully route the two wires up to the bike’s handle bar using cable ties to secure the wire. This completes the sensor mounting part.

     
The main circuit and the LCD module can be housed in suitable plastic enclosures, which are readily available in electronic projects shops. These enclosures should have precut slot for easy mounting of the LCD panel. If such boxes are not available, you can use the plastic boxes of electronic chokes by suitably removing some portions for the LCD panel.
  
Power supply can be taken either directly from the bike’s 12V battery or tapped from the console which houses horn, headlight and indicator light switches. For this, you need to remove the switch console and identify positive wire and ground wire using a multimeter. When carrying out this step, remember to turn the ignition key to ‘on’ position. Solder a 60cm two-core wire to the positive and negative terminals inside the switch console. The advantage of taking supply from the switch console is that the ignition key controls the power supply to the main unit without having a separate on-off switch.
  
An actual-size, single-side PCB layout of the microcontroller-based speedometer-cum-odometer is shown in Fig. 7 (View as PDF), and its component layout in Fig. 8 (View as PDF).

Testing

After all the components are soldered on the PCB, program the microcontroller with Init_EEPROM.hex file and place the microcontroller in a 20-pin IC base and switch on the circuit.

In the first line of the LCD, ‘INIT_EEPROM’ appears. After five seconds, ‘00000.0’ is displayed in the second line. This process erases any previous data and sets the initial readings in the EEPROM to zero. Now switch off the supply and program the microcontroller with ‘speedo.hex’ main file. After programming, place the microcontroller back in the circuit and switch on the supply. The LCD will show ‘Kms: 00000.0’ in the first line and ‘Speed- Kms/ Hr: 00.0’ in the second line. Now, the unit is ready to mount on your bike.
  
Connect the two wires coming from the reed switch and the power supply wires to the main unit. Mount the unit at the centre of the bike’s handle bar on top of the ‘U’ clamps that secure the handle bar to the chassis. You can use cable ties to accomplish this. Mounting arrangement of the unit is shown in Fig. 6.

    




Now start the bike, take a test ride and if connections are correct, the speed and the distance will be displayed on the LCD. A protective cover like polythene can be used for the main unit on rainy days.

Download source code.

Download 
actual-size, single-side PCB layout.

Download PCB 
component layout
Read More

How To Make Simple Cable TV Amplifier


This is a very simple cable TV amplifier using two transistors. This amplifier circuit is most suitable for cable TV systems using 75 Ohm coaxial cables and works fine up to 150MHz. Transistor T1 performs the job of amplification. Up to 20dB gain can be expected from the circuit.T2 is wired as an emitter follower to increase current gain.
Circuit diagram.

Notes.





  • The circuit can be assembled on a Vero board.
  • Use 12V DC for powering the circuit.
  • Type no of the transistors are not very critical.
  • Any medium power NPN RF transistors can be used in place of T1 and T2.
  • This is just an elementary circuit. Do not compare it with high quality Cable TV amplifiers available in the market.

Read More

How To Make Infrared motion detector circuit

Here is the circuit diagram of an infrared motion detector that can be used to sense intrusions. Infra red rays reflected from a static object will be in one phase, and the rays reflected from a moving object will  be in another phase. The circuit uses this principle to sense the motion.
The IC1 (NE 555)  is wired as an astable multivibrator. The IR diode connected at the output of this IC produces infrared beams of frequency 5Khz. These beams are picked by the infrared sensor, photo transistor Q1. At normal condition, that is, when there is no intrusion the output pin (7) of IC2 will be low. When there is an intrusion the phase of the reflected waveforms has a difference in phase and this phase difference will be picked by the IC2. Now the pin 7 of the IC 2 goes high to indicate the intrusion. An LED or a buzzer can be connected at the output of the IC to indicate the intrusion.
Circuit diagram with Parts list.


Notes.




  • Comparators IC2a and IC2b are belonging to the same IC2  (LM1458). So the power supply is shown connected only once. No problem.
  • When there is disturbance in the air or vehicles passing nearby, the IR motion sensor circuit may get false triggered.
  • POT R5 can be used for sensitivity adjustment.

Read More

How To Make Make a Sound Card with PCM2704


This article relates to my previous article Make a sound card with PCM2702. In this time I used newer IC from Texas Instruments PCM2704. Thanks to this circuit with all necessary features inside 28pins SSOP package I was able to built quite small sound card. The result is sound card with size of gumstick.

Description: 
This device is fully functional sound card for PC. The main advantage of using PCM2704 against PCM2702 is much easier construction. As you can see on the block diagram it has built-in 5V and 3.3 voltage regulator, HID interface (MUTE, VOL+, VOL-), S/PDIF output. The circuit can be powered directly from USB port. Next advantage is that the outup DAC is able to drive directly 32ohms headphones, but the ouput power is only 12mW. For all details please refer to the PCM2704 datasheet.


Block diagram

The schematic is very simple. It is almost copy of the datasheet circuit diagram. You can see the core IC PCM2704 (U1), crystal with supporting parts (X1, C1, C2, R1), connection to the USB (USB connector, R2, R3,R4, L1), a lot of blocking capacitors for all voltages (C3, C4, C5, C6, C7, C8), S/PDIF output header (J1), HID header (J2), output filter (R5, C11, R6, C12, R7, R8), coupling capacitors (C9, C10) and output 3.5mm Jack connector (J3).





Schematic of sound card with PCM2704


Realization:
I designed my own PCB. The dimensions of the PCB are 55x18mm, including USB and Jack connector it is 73x18mm. To keep the size as small as possible 0805 size of capacitors and resistors were used. The L1 is ferrite bead which reduce high frequency hum. With good soldering iron and litle experience it is possible to assembly the PCB by hand.

Assembly diagram (top side)

Assembly diagram (bottom side)



PCB (top side)


PCB (bottom side)


Assembled PCB (top side)

Assembled PCB (bottom side)

Conclusion:
I built two pieces of this sound card. I have tested the sound card under Windows XP and Windows Vista and it works without any problem. I wanted to use this device for my Internet radio receiver, which I'm building according to the project published on mightyOhm.com. The receiver is based on Asus WiFi router WL-520GU with OpenWrt Linux distribution. The sound card works under the Linux as well, but it stop and start playing the sound periodically (the period varied from few minutes to one hour). I guess it is driver problem (if somebody has any idea how to fix it I will be very grateful).

You can ask me why to build this sound card when you can buy similar device for few bucks. I have also one sound card from China which cost around 5$ but the quality of the sound is very bad, so the main difference is sound quality.


Links:
PMC2704 (TI)
PCM2704 Evaluation Board (TI)








Read More

Control and Maintain Temperature via Internet using Arduino


Equipped with Ethernet interface, Arduino controls a boiler to maintain the set temperature and publish environmental data via Internet on Pachube, and the web interface allows  setting the temperature  remotely via Internet.


The project is designed to control an heating system in order to keep the temperature in a room above a certain value, which can be set from Internet or a Personal Computer by LAN, because ours is not a simple thermostat but a complex unit managed by Arduino, which can connect to a local network with ethernet interface.  The thermostat allows many functions, including the publication  temperature measured at regular intervals (set by firmware), as well as the state of the boiler (on or off). The datas are published on the website http://www.pachube.com, which provides a database which stores user data, also makes available a series of gadgets to be able to view this data directly into web pages.


The Circuit

We start our description of the hardware on this card from the temperature sensor: it is a DS18B20 equipped with a logic that can express in binary format, two bytes, the temperature measured by its sensor element and the data on the surveys are made available through a serial communication channel called one-wire.
The Ethernet module is a WIZNET network adapter that can be interfaced via the SPI bus (Serial Peripheral Interface) 4-wire.
The module is a WIZ811MJ ethernet (IEEE 802.3/802.3) and W5100-based chip with full magnetic filters ethernet connector and 2 LEDs for status signaling. The module communicates with the microcontroller by SPI. It works with 3.3 Vcc and the 3V3 are provided by Arduino.
The connector J3 is that counts the largest number of connections: it comes from the control signal of the transistor T1, the controller of the relay RL1 (in parallel with the coil there is the LED LD2, signaling,  the excitement of the relay). Through J3 the Arduino reads status of buttons P1 and P2 and the input IN, all with pull-up resistor. The yellow LED LD1 is used to give the state mode or assist the setting of operation modes made with the P1 button. This allows you to choose between modes of operation of the system: sensor, manual or thermostat. Pressing once set the system in the sensor mode (automatic) and that this operation is indicated by a flashing dell’LD1, two pressures set the sistem in manual mode (command from web page), which is indicated by two flashes Led. Finally, three pressures set the system in thermostat mode (slave input IN), and this is communicated by three consecutive flashes dell’LD1. Pressing the button P1 returns the sistem in the first mode.
As for P2, currently not used and is reserved for future developments.








R1: 4,7 kohm
R2: 10 kohm
R3: 470 ohm
R4: 4,7 kohm
R5: 4,7 kohm
R6: 4,7 kohm
R7: 4,7 kohm
R8: 4,7 kohm
U1: WIZNET
U2: DS18B20
P1: Microswitch
P2: Microswitch
LD1: led 3 mm yellow
LD2: led 3 mm red
T1: BC547
RL1: Relé 5V
D1: 1N4007
- Screw connector 2 via
- Screw connector 3 via
- Strip male 6 via(2 pz.)
- Strip male 8 via (2 pz.)
- Strip female 10 via (4 pz.)
- PCB



How to use

Opening in the browser the thermostat IP address  (defined by the Arduino firmware) you can access the page and set the temperature of the system, the functions or active manually the boiler.
In the web page in memory dell’Arduino is also inserted a reference to the graphs of the gadget sites,  in the graph bottom of the page where you can choose which display period (from 1 minute to 1 year).
The web page contains the top, some buttons and boxes for the settings. There is a refresh button and below there are an indication of the status of the boiler (OFF or ON):  the system can be used for both heating systems both cooling and air conditioning: it depends on how connected the relay. In fact, with the exchange between C and NO it controls the boiler, while that between C and NC controls the air conditioner, this is because until the temperature is less than the threshold, the relay is energized and closes NO to NC, so it can turn on a boiler or other heating system, while when the temperature exceeds the set threshold, the relay returns to rest and NC close to C, going to control the cooling system.
We continue with the analysis of web page talking about the radio buttons under the present condition of the boiler, which are three and let you set how our system should work: clicking on the relay sensor is controlled based on temperature detected by the Dallas sensor, while opting for manual you can make the relay turn on and off using the On-screen buttons Boiler (relay activated), and Off Boiler (relay deactivated). Finally, opting for thermostat, the relay will be controlled according to the condition of our input IN interface card, this mode allows you to enslave the functioning of our system to an existing thermostat is substantially repeated in the environment and to relay the condition of the thermostat itself.
Below the radio buttons that define how, is the section of the temperature setting: Click in the box, you can set at will (within limits) the temperature at which the system should take, the setting made applies here by clicking the Set temperature.

We conclude the description of the web page with the chart, which summarizes the time courses of temperature measured by the sensor and the display may relate to a period of time to choose between 1 minute and 1 year.
As mentioned, the public system at that site www.pachube.com the value of the measured temperature, in a personal page reserved for each registered user, this site provides a service for storage and display of data from various sources, ranging from information gathered from sensors in environmental data, various measures, then everything is shared, or made accessible to registered users of the community.
In order to publish data on www.pachube.com you must first register and create an account, then take your chosen username and validated by the site and write in the special section of the firmware on the feed, without informing the user name of firmware, our system will not be able to access the site and publish the data.
Delivery of data for the upgrade can be done with a frequency set by firmware, bearing in mind the limits allowed by the site (about 50 accesses per hour) for obvious reasons, because if any application tries to access in real time site for uploading the data, at some point the bandwidth of the connection used by it and would soon be saturated with its server would have some problem to run.
Well, having said that we can conclude by pointing out that clicking on the word pachube that is below the temperature graph, you enter the page on www.pachube.com mail account used by the system to publish data on the page shown address of the corresponding link, containing the account name.


The Sketch
The sketch contains 3 .PDE files. This is the main program.

Download ZIP File Download the Thermostat sketch





Source Code:
/* Thermostat with arduino

 created 2011
 by Boris Landoni

 This example code is in the public domain.

http://www.s2ptech.blogspot.com

http://www.futurashop.it

 */

#include <SPI.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#define SHARE_FEED_ID              5102     // this is your Pachube feed ID that you want to share to
#define REMOTE_FEED_ID             256      // this is the ID of the remote Pachube feed that you want to connect to
#define REMOTE_FEED_DATASTREAMS    4        // make sure that remoteSensor array is big enough to fit all the remote data streams
#define UPDATE_INTERVAL            20000    // if the connection is good wait 10 seconds before updating again - should not be less than 5
#define RESET_INTERVAL             10000    // if connection fails/resets wait 10 seconds before trying again - should not be less than 5
#define PACHUBE_API_KEY            "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // fill in your API key
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

int puls1 = 5;                 // pulsante per il cambio di modalità di funzionamento
int puls2 = 2;                 // pulsante per il cambio di modalità di funzionamento
int in    = 3;                 // ingresso del termostato

prog_char string_0[] PROGMEM  = "<html><head><title>Boris's Project</title><META HTTP-EQUIV=\"Refresh\" CONTENT=\"3600\"></head>";
prog_char string_1[] PROGMEM  = "<body><center><br><form> <input type=button value=\"Refresh \" onClick=\"window.location.reload()\"> </form><br><br><h2>Remote Control Thermostat   ";
prog_char string_2[] PROGMEM  = " C</h2><form method=GET><font size= 5>Boiler ";
prog_char string_3[] PROGMEM  = "</font><br><font size= 3>Input Thermostat ";
prog_char string_4[] PROGMEM  = "</font><br><table><td><input type=\"radio\" name=\"statourl\" value=\"1\" onClick=\"this.form.submit()\"  ";
prog_char string_5[] PROGMEM  = "></td><td>Sensor</td><td><input type=\"radio\" name=\"statourl\" value=\"2\" onClick=\"this.form.submit()\" ";
prog_char string_6[] PROGMEM  = "></td><td>Manual</td><td><input type=\"radio\" name=\"statourl\" value=\"3\" onClick=\"this.form.submit()\" ";
prog_char string_7[] PROGMEM  = "></td><td>Thermostat</td><br></table> </form><form method=GET>";
prog_char string_8[] PROGMEM  = "<table><tr><td><input type=submit name=b11 value=\"Boiler ON\"></td><td><input type=submit name=b10 value=\"Boiler OFF\"></td><td>";
prog_char string_9[] PROGMEM  = "</td></tr></table></form><form method=GET>Temperature: <input type=\"text\" size=\"2\" name=temp value=#* MAXLENGTH=2>";
prog_char string_10[] PROGMEM  = "<input type=\"submit\" value=\"Set temperature\"><br></form>";
prog_char string_11[] PROGMEM = "<br><OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
prog_char string_12[] PROGMEM = "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
prog_char string_13[] PROGMEM = "#version=6,0,0,0\" WIDTH=\"200\" HEIGHT=\"100\" id=\"gauge\"><PARAM NAME=\"movie\"";
prog_char string_14[] PROGMEM = "VALUE=\"http://apps.pachube.com/scaredycat/gauge.swf?xml_source=";
prog_char string_15[] PROGMEM = "http%3A//apps.pachube.com/scaredycat/getData.php";
prog_char string_16[] PROGMEM = "%3Fm%3D0%26f%3D5102%26s%3D0%26u%3D30%26l%3D0%26n%3D5%26t%3D";
prog_char string_17[] PROGMEM = "Temperatura%26w%3Dfalse%26c1%3D33FF33%26c2%3DEFE415%26c3%3DEF8B15%26c4%3DFF3333%26";
prog_char string_18[] PROGMEM = "in%3Dtrue\" /><PARAM NAME=\"quality\" VALUE=\"high\" /><param name=\"wmode\" value=\"transparent\">";
prog_char string_19[] PROGMEM = "<param name=\"allowScriptAccess\" value=\"sameDomain\" /><EMBED src=\"";
prog_char string_20[] PROGMEM = "http://apps.pachube.com/scaredycat/gauge.swf?xml_source=";
prog_char string_21[] PROGMEM = "http%3A//apps.pachube.com/scaredycat/getData.php";
prog_char string_22[] PROGMEM = "%3Fm%3D0%26f%3D5102%26s%3D0%26u%3D30%26l%3D0%26n%3D5%26t%3D";
prog_char string_23[] PROGMEM = "Temperatura%26w%3Dtrue%26c1%3D33FF33%26c2%3DEFE415%26c3%3DEF8B15%26c4%3DFF3333%26in%3Dtrue\"";
prog_char string_24[] PROGMEM = "quality=\"high\" wmode=\"transparent\" WIDTH=\"200\" HEIGHT=\"100\"";
prog_char string_25[] PROGMEM = "NAME=\"gauge\" allowScriptAccess=\"sameDomain\" swLiveConnect=\"true\"";
prog_char string_26[] PROGMEM = "TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"";
prog_char string_27[] PROGMEM = "http://www.macromedia.com/go/getflashplayer\"></EMBED></OBJECT>";
prog_char string_28[] PROGMEM = "<br><br><script type=\"text/javascript\" src=\"http://www.google.com/jsapi\">";
prog_char string_29[] PROGMEM = "</script><script language=\"JavaScript\" src=\"http://apps.pachube.com/google_viz/viz_multi.js\">";
prog_char string_30[] PROGMEM = "</script><script language=\"JavaScript\">createViz([5102,5102],[0,1],800,400,[\"ff0000\",\"0000ff\"],0,40);</script>";
prog_char string_31[] PROGMEM = "";
prog_char string_32[] PROGMEM = "";
prog_char string_33[] PROGMEM = "<font size= 2>Powered by Open-Electronics.org - Boris Landoni</font>"; //please don't remove <img src="http://www.open-electronics.org/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley">
prog_char string_34[] PROGMEM = "";
prog_char string_35[] PROGMEM = "";
prog_char string_36[] PROGMEM = "";
prog_char string_37[] PROGMEM = "";
prog_char string_38[] PROGMEM = "";
prog_char string_39[] PROGMEM = "";
prog_char string_40[] PROGMEM  = "<br></center></body></html>";
prog_char string_41[] PROGMEM  = "<font color=\"red\">ON</font>";
prog_char string_42[] PROGMEM  = "OFF";
prog_char string_43[] PROGMEM  = "checked";
prog_char string_44[] PROGMEM  = "on";
prog_char string_45[] PROGMEM  = "off";

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
string_14,
string_15,
string_16,
string_17,
string_18,
string_19,
string_20,
string_21,
string_22,
string_23,
string_24,
string_25,
string_26,
string_27,
string_28,
string_29,
string_30,
string_31,
string_32,
string_33,
string_34,
string_35,
string_36,
string_37,
string_38,
string_39,
string_40,
string_41,
string_42,
string_43,
string_44,
string_45
};

char buffer[150]; // make sure this is large enough for the largest string it must hold

byte mac[] = { 0xDE, 0xAD, 0xBA, 0xAF, 0xFA, 0xAD };
byte ip[] = { 192, 168, 0, 172 };
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
byte remoteServer[] = { 173,203,98,29 };            // pachube.com
float remoteSensor[REMOTE_FEED_DATASTREAMS];        // we know that feed 256 has floats - this might need changing for feeds without floats
String inString = String(35);
Server server(80);
const int led = 6;
const int rele = 7;
String temp="";
String statourl="";
int tam=0;
int st1=42,st2=42,st3=42,st4=42,st5=43,st6=44;
//float tempCold;
unsigned long pubblica;
unsigned long lampeggio;
int stato=1; // se 0 controllo con sensore temperatura integrato, se 1 controllo manuale, se 2 controllo con termostato esterno
float tempC=0;

void setup()
{
      pinMode(puls1, INPUT);
      pinMode(puls2, INPUT);
      pinMode(in, INPUT);
      pinMode(led, OUTPUT);
      pinMode(rele, OUTPUT);
      Serial.begin(9600);
      Ethernet.begin(mac, ip,gateway,subnet);
      server.begin();
      Serial.println("Serial READY");
      Serial.println("Ethernet READY");
      Serial.println("Server READY");
        sensors.begin();
        Serial.print("Found ");
        Serial.print(sensors.getDeviceCount(), DEC);
        Serial.println(" devices.");
        Serial.print("Parasite power is: ");
        if (sensors.isParasitePowerMode()) Serial.println("ON");
        else Serial.println("OFF");
        if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
        Serial.print("Device 0 Address: ");
        printAddress(insideThermometer);
        Serial.println();
        // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
        sensors.setResolution(insideThermometer, 9);
        Serial.print("Device 0 Resolution: ");
        Serial.print(sensors.getResolution(insideThermometer), DEC);
        Serial.println();

}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

void printWebPage(Client *client)
{
    int tmp=0;
    int temperatura=0;
      // send a standard http response header
      client->println("HTTP/1.1 200 OK");
      client->println("Content-Type: text/html");
      client->println();

      strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
      client->println( buffer );
      //Serial.println( buffer );
      for (int i = 1; i < 41; i++)
      {
          if (i==9)
          {
              strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));  //butto tutto nell'array buffer
              for (tmp=0 ; tmp < sizeof(buffer); tmp++)
              {
                if (buffer[tmp]=='#')
                {
                  //Serial.println( "trovato ##### " );
                  temperatura = EEPROM.read(0);
                  Serial.print("dato in mem : ");
                  Serial.println(temperatura);
                  buffer[tmp] =  char ((temperatura/10)+48);
                  tmp++;
                  buffer[tmp] =  char ((temperatura % 10)+48);
                }

              }
          }
          else
          {
            strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
          }
          client->println( buffer );

          switch(i){

              case 1:
                  itoa (tempC, buffer, 10); client->print( buffer ); Serial.print( buffer ); client->print( "," ); Serial.print( "," ); itoa ((int(tempC * 100) % 100), buffer, 10); client->print( buffer ); Serial.print( buffer ); break;
              case 2:
                  if(digitalRead(rele)) st4=41;
                  else st4=42;
                  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st4]))); client->println( buffer ); Serial.println( buffer ); break;
              case 3:
                  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st6]))); client->println( buffer ); Serial.println( buffer ); break;
              case 4:
                if (stato==1){
                  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st5]))); client->println( buffer ); Serial.println( buffer ); break;
                  }
              case 5:
                if (stato==2){
                  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st5]))); client->println( buffer ); Serial.println( buffer ); break;
                  }
              case 6:
                if (stato==3){
                  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st5]))); client->println( buffer ); Serial.println( buffer ); break;
                  }
          }
          delay(30);
      }

}

void verificaingressi()
{
  int temperatura = EEPROM.read(0);
  if (!digitalRead(puls1))
      {
        stato=stato+1;
        if (stato>3)
        {
          stato=1;
        }
       EEPROM.write(1, stato);
       digitalWrite(led,HIGH);
       delay(1000);
       digitalWrite(led,LOW);
       delay(1000);
       lampeggio=4000; //così lampeggia poi subito
      }

            if (stato==1)
      {
        if (tempC<temperatura )
        {
           digitalWrite(rele,HIGH);
           //st4=41;
        }
        else
        {
          if (tempC>(temperatura+1))
          {
            digitalWrite(rele,LOW);
            //st4=42;
          }
        }
      }

        if (!digitalRead(in))
        {
           if (stato==3) digitalWrite(rele,HIGH);
           st6=44;
        }
        else
        {
            if (stato==3) digitalWrite(rele,LOW);
            st6=45;
        }
}

void loop()
{

      stato = EEPROM.read(1);

      verificaingressi();
      sensors.requestTemperatures(); // Send the command to get temperatures

      tempC = sensors.getTempC(insideThermometer);
      if (millis() < pubblica) pubblica = millis();

      if ((millis() - pubblica) > UPDATE_INTERVAL){
          pubblica = millis();  

          Serial.println("Pubblico");
          Serial.print("Temp C    : ");
          Serial.println(tempC);
          if (tempC<50 && tempC>-20)
          {
            pachube_in_out(tempC);
          }
      }

      if (millis() < lampeggio)  lampeggio = millis();
      if ((millis() - lampeggio) > 5000){    //ogni 5 sec faccio lampeggiare il led giallo
          lampeggio = millis();
          for (int i = 0; i < stato; i++)
          {
                   //Serial.println("lamp");
                   digitalWrite(led,HIGH);
                   delay(250);
                   digitalWrite(led,LOW);
                   delay(250);
          }
      }

      Client client = server.available();

      int led=0;
      int tmp=0;
      if (client) {

      // an http request ends with a blank line
      boolean current_line_is_blank = true;
      while (client.connected()) {

      if (client.available()) {

      char c = client.read();
      if (inString.length() < 35) {
      inString.concat(c);

      }
      if (c == '\n' && current_line_is_blank) {

          if(inString.indexOf("b10")>=0){
            digitalWrite(led,LOW);
            stato=2;
          }
          if(inString.indexOf("b11")>=0){
            digitalWrite(led,HIGH);
            stato=2;
          }         

          if(inString.indexOf("b40")>=0){
            digitalWrite(led,LOW);
          }
          if(inString.indexOf("b41")>=0){
            digitalWrite(led,HIGH);
          }
          if(digitalRead(rele)) st4=41;
          else st4=42;  

          if (inString.indexOf("temp")>=0){
            char tempArr[20];
            temp=inString.substring(inString.indexOf('p')+2, inString.indexOf(" H"));
            temp.toCharArray(tempArr, 5);
            EEPROM.write(0, atoi(tempArr));
            tmp = EEPROM.read(0);
            stato=1;
          }

          if(inString.indexOf("statourl")>=0){
             char statoArr[20];
            statourl=inString.substring(inString.indexOf('l')+2, inString.indexOf(" H"));
            statourl.toCharArray(statoArr, 5);
            stato=(atoi(statoArr));
          }     

      EEPROM.write(1, stato);
      verificaingressi();
      printWebPage( &client);
      break;
      }
      if (c == '\n') {
      // we're starting a new line
      current_line_is_blank = true;
      } else if (c != '\r') {
      // we've gotten a character on the current line
      current_line_is_blank = false;
      }
      }
      }
      // give the web browser time to receive the data
      delay(1);
      inString = "";
      client.stop();
      }
}









Read More

How To Make Energy Meter Monitor using Arduino

This is a simple power meter to analize the current consuming in a house using the led indicator of a house energy meter.

Reading the red led of a home energy counters the system detects the corrent consumption in a house.

It is a noninvasive method, not cut wire, no current disconnects, so a very interesting method…
The system consists of two parts: the Arduino board that detects the led pulses and sends the data via the XBee module, and a PC that recive the data through a USB/Xbee module and processes the data with LabVIEW so you can prepare and study the consumption in a very instant.
Arduino sends two datas to the PC:
1 – Real time datas
2 – Average consumption measured in a time of 5 minutes.




 From the picture we see that the LED that indicates the current consumption is the red LED near to the display. In particular is the LED superior.

Arduino module
To detect the LED blinking you have to apply a simple photoresistor above the led and covered it with black tape. To read the analog voltage using the Arduino you have to use a resistive divider as shown in diagram:



The LED blinking causes the voltage drop down and this value is read by Arduino and compared with the voltage acquired by the potentiometer connected in the channel A0. This potentiometer has the task to adjust the sensitivity threshold.
The read data are processed from the sketch and then sends to the PC via Xbee module.

The Arduino code acquisition is as follows:
 delay(10); //10ms
   val_pot = analogRead(POT);
   delay(10); //10ms
   val_sensore = analogRead(SENSORE);
  if((val_sensore > val_pot)&(flag_acquire == 0)){
      flag_acquire = 1;
      digitalWrite(LED, LOW);
With this code Arduino acquires the two voltages, the photoresistor voltage compared with the voltage of the potentiometer, if the value is greater than the sketch actives the flag “flag_acquire = 1″, then read how much time has passed to another flash.
To do this use arduino to read a statement in an internal counter that returns the milliseconds since power on. The instruction is “millis ()” code here:
pre_tmS = cur_tmS;
      cur_tmS = millis();
      if( cur_tmS > pre_tmS ) {
        tm_diffS = cur_tmS – pre_tmS;
     }
There are 2 variables pre_tmS and cur_tmS, “cur_tmS” needs to read the current value of the internal counter: cur_tmS = millis (); Then if the condition (cur_tmS> pre_tmS) is true, I note the elapsed time between cycles, ie between the LED ON and the next cycle of the LED ON and write it on the variable “pre_tmS”. Now we have to send to the PC via the serial port using XBee with these instructions:
      Serial.print(“S”);
      Serial.println(tm_diffS);
      delay(10); //10ms
First Arduino sends a marker “S” used to labview to recognize that this value is part of the reading that real-time instant, then send the value in milliseconds elapsed. Now you have to reset the flag when the LED goes OFF using this statement:
  if((val_sensore < val_pot)&(flag_acquire == 1)){
      flag_acquire = 0;
     digitalWrite(LED, HIGH);
      impulsi++;      
      delay(10); //10ms
  }
You have to check the voltage acquired by the sensor, if it falls below the potentiometer value and the flag is active “flag_acquire == 1″ then you have to reset the flag. Note that the statement “impulsi++;” is simply a counter that counts the cycles of the LED power meter, this is to make an average energy consumed every 5 minutes. The third task is similar to the first task, wait 1 second, and increments the counter “time_flag++,” which is the fourth task of counting 300secondi (5 minutes). In addition, this task blinks the LED connected to pin 12 at a rate of 1 second.
The fourth task as mentioned above waiting 5 minutes and then sent via serial marker “L” is used to program labview to recognize that the data sent is the data on the average found in 5 minutes.

The sketch
#define POT 0
#define SENSORE 1
#define LED 13
#define LED1sec 12


// definire il tempo casuale che varia tra 40ms e 250ms
#define TimeAcquire  1000      //1sec
#define Time5Minuts  300      //5 minuti = 300sec


unsigned long cur_tm = millis();
unsigned long pre_tm = cur_tm;
unsigned int tm_diff = 0;


unsigned long cur_tmS = millis();
unsigned long pre_tmS = cur_tmS;
unsigned int tm_diffS = 0;


unsigned int time_flag=0;


unsigned int impulsi=0;
unsigned int val_pot=0;
unsigned int val_sensore=0;
char flag_acquire=0;
char flag_time=0;


void setup() {


  pinMode(LED, OUTPUT);
  pinMode(LED1sec, OUTPUT);
  Serial.begin(115200);          //  setup serial 115200
  Serial.println("ENEL KW/h reader!");


}


void loop() {


  //Acquisisco
   delay(10); //10ms
   val_pot = analogRead(POT);    // read the input pin
   delay(10); //10ms
   val_sensore = analogRead(SENSORE);    // read the input pin


  if((val_sensore > val_pot)&(flag_acquire == 0)){
      flag_acquire = 1;
      digitalWrite(LED, LOW);


      pre_tmS = cur_tmS;
      cur_tmS = millis();
      if( cur_tmS > pre_tmS ) {
        tm_diffS = cur_tmS - pre_tmS;
      }
      Serial.print("S");
      Serial.println(tm_diffS);


      delay(10); //10ms


  }
  if((val_sensore < val_pot)&(flag_acquire == 1)){
      flag_acquire = 0;
      digitalWrite(LED, HIGH);
      impulsi++;          //Incrementa impulsi
      delay(10); //10ms
  }


  //------Ogni 5 minuti invia "impulsi" ----------
  pre_tm = cur_tm;
  cur_tm = millis();
  if( cur_tm > pre_tm ) {
    tm_diff += cur_tm - pre_tm; //+=
  }
  if( tm_diff >= TimeAcquire ) { //Task ogni secondo
    tm_diff = 0;


    time_flag++;


    if(flag_time==0){
      digitalWrite(LED1sec, HIGH);
      flag_time = 1;
    }else{
      digitalWrite(LED1sec, LOW);
      flag_time = 0;
    }


  }


  if(time_flag>=Time5Minuts){


//Sono passati 5 minuti ? ..... Invia "impulsi" rilevati dal contatore
      Serial.print("L");
      Serial.println(impulsi);
      impulsi = 0;
      time_flag = 0;
  }


 //--------------------------------------------------


}

LABVIEW interface








To recive the data we use the XBee UartSbee V3.1 module from Futura Elettronica.


The interface created in LabVIEW is simple to use:


As can be seen from this figure, the top graph shows the average consumption every 5 minutes, while the bottom graph shows the real-time energy consumption. It ‘can save the data using the device as a data logger.
Read More