brock

Wednesday, September 19, 2012

Water Level Controller And Motor Protector

Many a time we forget to switch off the motor pushing water into the overhead tank (OHT) in our households. As a result, water keeps overflowing until we notice the overflow and switch the pump off
As the OHT is usually kept on the topmost floor, it is cumbersome to go up frequently to check the 
water level in the OHT.


Here’s a microcontroller-based water level controller-cum-motor protector to solve this problem. It controls ‘on’ and ‘off ’ conditions of the motor depending upon the level of water in the tank. The status is displayed on an LCD module. The circuit also protects the motor from high voltages, low voltages, fluctuations of mains power and dry running.


Circuit description

Fig. 1 shows the circuit of the microcontroller-based water level controller-cum-motor protector. It comprises operational amplifier LM324, microcontroller AT89C51, optocoupler PC817, regulator 7805, LCD module and a few discrete components. 
  
The AT89C51 (IC2) is an 8-bit microcontroller with four ports (32 I/O lines), two 16-bit timers/ counters, on-chip oscillator and clock circuitry. Eight pins of port-1 and three pins of port-3 are interfaced with data and control lines of the LCD module. Pins P3.0, P3.1 and P3.6 are connected to RS (pin 4), R/W (pin 5) and E (pin 6) of the LCD, respectively. Pin EA (pin 31) is strapped to Vcc for internal program executions. Switch S2 is used for backlight of the LCD module.

  
Power-on-reset is achieved by connecting capacitor C8 and resistor R14 to pin 9 of the microcontroller. Switch S1 is used for manual reset.

  
The microcontroller is operated with a 12MHz crystal. Port pins P2.0 through P2.2 are used to sense the water level, while pins P2.3 and P2.4 are used to sense the under-voltage and over-voltage, respectively. Pin P3.4 is used to control relay RL1 with the help of optocoupler IC3 and transistor T5 in the case of under-voltage, over-voltage and different water level conditions. Relay RL1 operates off a 12V supply. Using switch S3, you can manually switch on the motor.

The LM324 (IC1) is a quad operational amplifier (op-amp). Two of its op-amps are used as comparators to detect under- and over-voltage. In normal condition, output pin 7 of IC1 is low, making pin P2.3 of IC2 high. When the voltage at pin 6 of N1 goes below the set reference voltage at pin 5 (say, 170 volts), output pin 7 of N1 goes high. This high output makes pin P2.3 of IC2 low, which is sensed by the microcontroller and the LCD module shows ‘low voltage.’

In normal condition, pin 1 of N2 is high. When the voltage at pin 2 of N2 goes above the set voltage at pin 3, output pin 1 of N2 goes low. This low signal is sensed by the microcontroller and the LCD module shows ‘high voltage.’

Presets VR1 and VR2 are used for calibrating the circuit for under-
and over-voltage, respectively.   
The AC mains is stepped down by transformer X1 to deliver a secondary output of 12V at 500 mA. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D5 through D8, filtered by capacitor C2, and used for the under- and over-voltage detection circuitry.

  
The transformer output is also rectified by a full-wave bridge rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulated by IC4 to deliver regulated 5V for the circuit.
 
When water in the tank rises to come in contact with the sensor, the base of transistor BC548 goes high. This high signal drives transistor BC548 into saturation and its collector goes low. The low signal is sensed by port pins of microcontroller IC2 to detect empty tank, dry sump and full tank, respectively.
     

Operation

When water in the tank is below sensor A, the motor will switch on to fill water in the tank. The LCD module will show ‘motor on.’ The controller is programmed for a 10-minute time interval to check the dry-run condition of the motor. If water reaches sensor B within 10 minutes, the microcontroller comes out of the dry-run condition and allows the motor to keep pushing water in the tank.

The motor will remain ‘on’ until water reaches sensor C. Then it will stop automatically and the microcontroller will go into the standby mode. The LCD module will show ‘tank full’ followed by ‘standby mode’ after a few seconds. The ‘standby mode’ message is displayed until water in the tank goes below sensor A. 

  
In case water does not reach sensor B within 10 minutes, the microcontroller will go into the dry-running mode and stop the motor for 5 minutes, allowing it to cool down. The LCD module will show ‘dry-sump1.’

  
After five minutes, the microcontroller will again switch on the motor for

10 minutes and check the status at sensor B. If water is still below sensor B, it will go into the dry-running mode and the LCD module will show ‘dry-sump2.’
  
The same procedure will repeat, and if the dry-run condition still persists, the display will show ‘dry-sump3’ and the microcontroller will not start the motor automatically. Now you have to check the line for water and manually reset the microcontroller to start operation.

  
In the whole procedure, the microcontroller checks for high and low voltages. For example, when the voltage is high, it will scan for about two seconds to check whether it is a fluctuation. If the voltage remains high after two seconds, the microcontroller will halt running of the motor. Now it will wait for the voltage to settle down. After the voltage becomes normal, it will still check for 90 seconds whether the voltage is normal or not. After normal condition, it will go in the standby mode and start the aforementioned procedure.


Code:

Microcontroller Based Solar Charger


As the sources of conventional energy deplete day by day, resorting to alternative sources of energy like solar and wind energy has become need of the hour.

Solar-powered lighting systems are already available in rural as well as urban areas. These include solar lanterns,
 solar home lighting systems, solar streetlights, solar garden lights and solar power packs. All of them consist of four components: solar photovoltaic module, rechargeable battery, solar charge controller and load.

In the solar-powered lighting system, the solar charge controller plays an important role as the 
system’s overall success depends mainly on it. It is considered as an indispensable link between the solar panel, battery and load.

The microcontroller-based solar charge controller described here has the following features:

1. Automatic dusk-to-dawn operation of the load
2. Built-in digital voltmeter (0V-20V range)
3. Parallel- or shunt-type regulation
4. Overcharge protection
5. System status display on LCD
6. Deep-discharge protection
7. Low battery lock
8. Charging current changes to ‘pulsed’ at full charge
9. Low current consumption
10. Highly efficient design based on microcontroller
11. Suitable for 10-40W solar panels for 10A load

The circuit of the solar charge controller is shown in Fig. 1. It comprises microcontroller AT89C2051, serial analogue-to-digital converter ADC0831, optocoupler MCT2E, regulator 7805, MOSFETs BS170 and IRF540N, transistor BC547, LCD and a few discrete components. Component description is given below.

Microcontroller. Microcontroller AT89C2051 is the heart of the circuit. It is a low-voltage, high-performance, 8-bit microcontroller that 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. A 12MHz crystal is used for providing the basic clock frequency. All I/O pins are reset to ‘1’ as soon as RST pin goes high. Holding RST pin high for two machine cycles, while the oscillator is running, resets the device. Power-on reset is derived from resistor R1 and capacitor C4. Switch S2 is used for manual reset.
   
Serial ADC.
  The microcontroller monitors the battery voltage with the help of an analogue-to-digital
 converter. The ADC0831 is an 8-bit successive approximation analogue-to-digital converter with a serial I/O and very low conversion time of typically 32 μs. The differential analogue voltage input allows increase of thecommon-mode rejection and offsetting of the analogue zero input voltage. Inaddition, the voltage reference input can be adjusted to allow encoding of anysmaller analogue voltage span to the full eight bits of resolution. It is available in an 8-pin PDIP package and can be interfaced to the microcontroller with only three wires.
   
LCD module.
 The system
 status and battery voltage are displayed on an LCD based on HD44780 controller. The backlight feature of the LCD makes it readable even in low light conditions. The LCD is used here in 4-bit mode to save the microcontroller’s port pins. Usually the 8-bit mode of interfacing with a microcontroller requires eleven pins, but in 4-bit mode the LCD can be interfaced to the microcontroller using only seven pins.
   
Solar panel.
 The solar
 panel used here is meant to charge a 12V battery and the wattage can range from 10 to 40 watts. The peak unloaded voltage output of the solar panel will be around 19 volts. Higher-wattage panels can be used with some modifications to the controller unit.
   
Rechargeable battery.
 The solar energy is converted into electrical energy and stored in a 12V lead-acid battery.
 The ampere-hour capacity ranges from 5 Ah to 100 Ah.
   
Dusk-to-dawn sensor.
 
Normally, in a solar-photovoltaic-based installation—for example, solar home lighting
 system, solar lantern or solar streetlight—the load (the light) is switched on at dusk (evening) and switched off at dawn (morning). During daytime, the load is disconnected from the battery and the battery is recharged with current from the solar panel. The microcontroller needs to know the presence of the solar panel voltage to decide whether the load is to be connected to or disconnected from the battery, or whether the battery should be in charging mode or discharging mode. A simple sensor circuit is built using a potential divider formed around resistors R8 and R9, zener diode ZD1 and transistor T1 for the presence of panel voltage.
   
Charge control.
 
Relay RL1 connects the solar panel to the battery through diode D1. Under normal conditions,
 it allows the charging current from the panel to flow into the battery. When the battery is at full charge (14.0V), the charging current becomes ‘pulsed.’ To keep the overall current consumption of the solar controller low, normally-closed (N/C) contacts of the relay are used and the relay is normally in de-energised state.
   
Load control.
 
One terminal of the load is connected to the battery through fuse F1 and another terminal of the load to an n-channel power MOSFET T3. MOFETs are voltage-driven devices that require virtually no drive
 current. The load current should be limited to 10A. One additional MOSFET is connected in parallel for more than 10A load current.

Circuit description

Basically, there are two methods of controlling the charging current: series regulation and parallel (shunt) regulation. A series regulator is inserted between the solar panel and the battery. The series type of regulation ‘wastes’ a lot of energy while charging the battery as the control circuitry is always active and series regulator requires the input voltage to be 3-4 volts higher than the output voltage. The current and voltage output of a solar panel is governed by the angle of incidence of light, which keeps varying.
   
Parallel regulation is preferred in solar field. In parallel regulation, the control circuitry allows the charging
 current (even in mA) to flow into the battery and stop charging once the battery is fully charged. At this stage, the charging current is wasted by converting into heat (current is passed through low-value, high-wattage resistor); this part of the regulation dissipates a lot of heat.
   
In this project, we have used parallel regulation technique but instead of wasting the charging current as heat,
 we have made it pulsed and applied to the battery to keep the battery topped-up.
   
After power-on, the microcontroller reads the battery voltage with the help of the ADC and displays the
 values on the LCD. It monitors the input signal from the dusk-to-dawn sensor and activates the load or charging relay RL1 accordingly. The digital voltmeter works up to 20V. As Vref of the ADC is connected to VCC (5V), the input voltage to the ADC cannot exceed +5V. A potential divider is used at pin 2 of the ADC (IC2) using resistors R5, R6 and R7 to scale down the voltage from 0V-20V to 0V-05V. The ADC output is multiplied four times and displayed on the LCD as battery voltage.
   
When the solar panel voltage is present, the dusk-to-dawn sensor provides a signal to the microcontroller,
 which then displays ‘charging’ message on the LCD. During charging, the battery voltage is continuously monitored. When the voltage reaches 14.0V, the microcontroller interrupts the charging current by energising the relay, which is connected to MOSFET BS170 (T2), and starts a 5-minute timer. During this stage, the LCD shows “battery full.”
   
After five minutes, the relay reconnects the panel to the battery. This way, the charging current is pulsed at the
 intervals of five minutes and the cycle repeats until the panel voltage is present.
   
When the panel voltage falls below the zener diode (ZD1) voltage of the dusk-to-dawn sensor, the microcontroller
 senses this and activates the load by switching on MOSFET T3 via optocoupler IC3 and “load on” message is displayed.
   
In this mode, the microcontroller monitors for low battery. When the battery voltage drops below 10 volts, the
 microcontroller turns off the load by switching off MOSFET T3 and “battery low—load off” message is displayed.

Normally, when the load is switched off, the battery voltage tends to rise back and the load oscillates between
 ‘on’ and ‘off ’ states. To avoid this, the microcontroller employs a hysteresis control by entering into a ‘lock’ mode during low-battery state and comes out of the lock mode when the dusk-to-dawn sensor receives the panel voltage (the next morning). During lock mode, the microcontroller keeps converting the ADC value and displays the battery voltage on the LCD.

Code:

Crystal Tester With BC547

Here is a simple circuit that can be used to test a crystal before using it in a circuit. The circuit is built around two BC547 transistors (T1 and T2) and a few discrete components. 

 The oscillator circuit formed by transistor T1, resistors R1 and R2, and capacitors C1 and C2 oscillates if a good crystal is connected to the test points marked as CUT (crystal under test). The output from the oscillator is rectified by diode D1 and filtered by capacitor C3. The positive voltage appearing across the capacitor is fed to the base of transistor T2, causing it to conduct.



Testing of a crystal is simple: Insert the crystal at CUT points shown in the circuit diagram and press test switch S1. If LED1 glows, your crystal is good and you can use it in a circuit.

The circuit is powered by a standard 9V battery. Push-to-on switch S1 is included to prolong the battery life but it’s not needed if you use a socket for the crystal under test.

Assemble the circuit on a general-purpose PCB and enclose in a suitable small cabinet. Fix the two-pin connector, LED1 and test switch on top of the cabinet. Fix the 9V battery inside the cabinet.

Note. You can use 2N3563 transistors instead of BC547.