You are on page 1of 16

Kathmandu University

Dhulikhel, Kavre

ASSIGNMENT NO:3

Submitted By: Submitted To:


Name: Anjali Shah Dr. Samundra Gurung, PhD

Group: EE-Communication

Roll No:31052

Course code: EPEG 317

Date: January 9th,2024


1.Develop a 5 bit DAC of your choice in proteus and explain its working. (Add a snapshot
picture of the proteus circuit model)

Digital to Analog converter is an electronic circuit in which the binary form of signal (0’s and
1’s) to analog signal. In this circuit design, R-2R ladder method is used to design a 5 bit DAC.

FIGURE: 5 BIT DAC BY R-2R LADDER METHOD


The output signal as a result of all these input voltage points is taken from the end of
the ladder which is used to drive the inverting input of an operational amplifier.

The working of 5 bit DAC is explained below:

1.Construction:
R- 2R ladder circuit is made by adding combination R & 2R resistor in cascaded form.
Each stage contains R-2R for each bit. The switch is connected between Vref and
Ground. This is controlled by binary input.
2.Digital Input and Switches:
Each tap is connected to a switch and rest of the other digital input bit. When bit is high
(1), the switch connects to a reference voltage (positive supply). When bit is low (0), the
switch connects to the ground.
3.Current Division and Summation:
The reference current (Iref) flows through the ladder, dividing equally at each tap
where a switch is closed (MSB side tap receives half the current compared to the LSB
side tap, and so on). Current from activated taps (based on the input bits) is then
summed using operational amplifiers (op-amps) to generate the final analog output
voltage.
4.Output voltage calculation:

We can generalize this formula for a 5- bit DAC as;

/Vout= – Vref {S1(1/21) + S2(1/22) + S3(1/23) + S4(1/24) + S5(1/25)} …[]\


‘. (1)
Where,
S1=MSB
S5=LSB.
Here, in this proteus design R=1k and Vref =5 Volts.
By using equation (1), taking the bits 0 and 1 of switches the output voltage is calculated.

For example, for the given switch position in the proteus i.e., 11111.

The output voltage calculated will be,

Vout = – Vref {S1(1/21) + S2(1/22) + S3(1/23) + S4(1/24) + S5(1/25)

Vout = – 5 {1*(1/21) + 1*(1/22) + 1*(1/23) + 1*(1/24) + 1*(1/25)

= 4.88 V

This output voltage is given to non-inverting terminal of another amplifier to convert the
output voltage from negative to positive value.
2. Develop a fuzzy logic controller for a particular application of your choice and
implement it with the help of Arduino or other microcontroller.

FUZZY LOGIC CONTROL FOR AUTOMATIC HARMFUL GAS EXHAUST


FAN CONTROL SYSTEM

This project is automatic detection of harmful gas in atmosphere in smart kitchen system
using fuzzy logic controller. The system embedded system consists of Control unit i.e.,
Arduino which acts as a brain to control all the activities of the circuit, Sensing element i.e.,
gas sensor(MQ-135) which detects the presence of gas in the atmosphere, Power unit to
power the electrical equipment for the optical performance and Control element i.e., fan to
vary the output based on gas concentration.
The overall components of the circuit are shown below:

BATTERY

DC FAN(FAN)
GAS
SENSOR ARDUINO
WITH FUZZY
RULES

FIGURE 2: OVERALL REPRESENTATION OF THE CIRCUIT

The system uses a Fuzzy Logic Controller (FLC) to ensure safety in a smart kitchen. The
fuzzy logic works with a combination of rules (conditions) that determine whether the
current environmental condition is disastrous or not. The sensor readings from the gas and
send values to the ARDUINO. Using these readings, the FLC on the Arduino determines
whether the conditions are safe or not and hence, sends an appropriate signal to turn on
the fan. The speed of the fan is decided based on the concentration of gas in the
surroundings using fuzzy logic controller. The fan’s speed will be neutral below the
threshold value and above this value the speed of the fan changes.

Fuzzy Logic Design System:


The proposed fuzzy logic system is shown in the figure 3 below. The fuzzy logic refers to
fuzzy sets in the fuzzy logic controller. Here, the variable represents the harmful gas(LPG).
The fuzzy logic system consists of four basic components:
 Fuzzification
 Inference
 Rules
 De-Fuzzification
Each component helps in decision making process.

RULES

CRISP INPUT FUZZIFIER DEFUZZIFIER CRISP OUTPUT

INFERENCE

FIGURE: BLOCK DIAGRAM OF FUZZY CONTROL SYSTEM


Fuzzification of the input and output variables:
1.Input variables:
PPM (Concentration of the gas: 0 to 2000 ppm):

 Low: 100 to 600 ppm


 Moderate: 500 to 1000 ppm
 High: 900 to 2000 ppm
2.Output Variables:
Speed of the fan (0 to 150 rpm):
 Slow: 20 to 50 rpm
 Medium: 40 to 100 rpm
 Fast: 80 to 150 rpm
Inputs for Fuzzy Rule:

Gas variable Fan Speed

Low Slow

Moderate Medium

High Fast

MATLAB TOOLBOX IMPLEMENTATION:

FIGURE: MATLAB TOOLBOX IMPLEMENTATION OF FUZZY LOGIC INFERNCE SYSTEM


FIGURE: MEMBERSHIP FUNCTION FOR INPUT VARIABLE GAS(LPG)
FIGURE: MEMBERSHIP FUNCTION FOR OUTPUT VARIABLE GAS(SPEED)

FIGURE: FUZZY INFERENCE RULES


FIGURE: FUZZY RULE VIEWER OF THE SYSTEM

FIGURE: SURFACE VIEWER


Fuzzy Logic Evaluation Table:
The fuzzy outputs, given in table, are the same when compared to the actual outputs expected from
the output. To calculate the accuracy of a software simulation of the fuzzy logic, the fuzzy output
and actual output all yield the same result, which confirms the accuracy of the fuzzy logic inference
system.

Gas(ppm) Fuzzy output Actual output


1500 115 115
500 70 70
115 35 35

Software Simulation:
The circuit was implemented using DC fan,transistor as relay and diode as well as external
supply. Relay acts as a electronic switch which can which take really small amount of power to
drive high power equipments. For this relay switch circuit npn transistor was used as a relay.
Transistor works faster than relays for on/off swithching circuit.

Since,the Arduino can only provide 40mA to its digital pin at 5V,which is enough to light on the
LED but not the fan.So, external power supply is provides through the circuit. The transistor is
PMW’ed. Higher the value of PMW,higher will be the speed of fan and vice-versa. Since,the
speed of fan is predictd by the Fuzzy Logic based on the concentration of the gas in the
surroundings. This value is provided to the PMW pin i.e., Pin 9 of Arduino. If the concentration
of gas is higher,the the fan will spin at higher speed, if moderate fan will spin at moderate
speed and high concentration the fan will spin at high speed.
Electric fans function through a process known as induction, where the flow of electric charge
in a wire creates a magnetic field. Coiling the wire enhances the magnetic field, and in DC fans,
this field interacts with magnets to drive movement. When a fan stops, a diode can be used to
prevent potential damage from the small current generated as the shaft continues to spin. Fans
draw the most current during startup or when carrying a load, with stall current representing
the amount of current when forcibly stopped.
The voltage rating signifies the optimal operating voltage for a fan, and deviating from this
rating, whether higher or lower, can impact the fan's lifespan. Providing less than the rated
voltage may result in slower fan speed, and insufficient voltage during startup may prevent
movement. Understanding these principles is essential for effective fan design and operation.
Figure: Simulation of the circuit

Simulink output:
Hardware Implementation:
MQ-135 sensor was used to take the analog input from sensor and provide it to the
Arduino. The fan speed was varied by using the PWM pin of Arduino i.e., Pin 9. In this pin,
the 0 value gives 0% duty cycle whereas 255 value fives 100% duty cycle.

Arduino code:
#include <Fuzzy.h>
// Fuzzy
Fuzzy *fuzzy = new Fuzzy ();

// FuzzyInput
FuzzySet *low = new FuzzySet(100, 350, 350, 600);
FuzzySet *moderate = new FuzzySet(500, 750, 750, 1000);
FuzzySet *high = new FuzzySet(900, 1500, 1500, 2000);

// FuzzyOutput
FuzzySet *slow = new FuzzySet(20, 35, 35, 50);
FuzzySet *medium = new FuzzySet(40, 70, 70 ,100);
FuzzySet *fast = new FuzzySet(80, 120, 120, 150);

void setup()
{
// Set the Serial output
Serial.begin(9600);

// FuzzyInput
FuzzyInput *ppm = new FuzzyInput(1);

ppm->addFuzzySet(low);
ppm->addFuzzySet(moderate);
ppm->addFuzzySet(high);
fuzzy->addFuzzyInput(ppm);

// FuzzyOutput
FuzzyOutput *speed = new FuzzyOutput(1);

speed->addFuzzySet(slow);
speed->addFuzzySet(medium);
speed->addFuzzySet(fast);
fuzzy->addFuzzyOutput(speed);
// Building FuzzyRule
FuzzyRuleAntecedent *ifppmlow = new FuzzyRuleAntecedent();
ifppmlow->joinSingle(low);

FuzzyRuleConsequent *thenspeedslow = new FuzzyRuleConsequent();


thenspeedslow->addOutput(slow);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifppmlow, thenspeedslow);


fuzzy->addFuzzyRule(fuzzyRule1);

// Building FuzzyRule
FuzzyRuleAntecedent *ifppmmoderate = new FuzzyRuleAntecedent();
ifppmmoderate->joinSingle(moderate);

FuzzyRuleConsequent *thenspeedmedium = new FuzzyRuleConsequent();


thenspeedmedium->addOutput(medium);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifppmmoderate, thenspeedmedium);


fuzzy->addFuzzyRule(fuzzyRule2);

// Building FuzzyRule
FuzzyRuleAntecedent *ifppmhigh = new FuzzyRuleAntecedent();
ifppmhigh->joinSingle(high);

FuzzyRuleConsequent *thenspeedfast = new FuzzyRuleConsequent();


thenspeedfast->addOutput(fast);

FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifppmhigh, thenspeedfast);


fuzzy->addFuzzyRule(fuzzyRule3);
}
void Setup()
{
pinMode(7,OUTPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}

void loop()
{
// Read the analog value from the gas sensor
int sensorValue = analogRead(A0);

// Convert analog value to voltage to ppm


float sensorVoltage = sensorValue * (5.0 / 1023.0);
float ppm=((2000/4)*sensorVoltage);
Serial.println(" \t\nppm: ");
Serial.print(ppm);

fuzzy->setInput(1, ppm);
fuzzy->fuzzify();

float speed = fuzzy->defuzzify(1);

Serial.print("\t\t speed: ");


Serial.print(speed);

analogWrite(9,speed);
delay(1000);

// wait 1 second
delay(1000);
}

The circuit was successfully implemented on the breadboard where motor was used as a
fan. The fan was off below 100ppm and then it changes its speed according to the
increasing/decreasing gas concentration in the atmosphere.
The YouTube link for the video is Automatic Gas sensor Exhaust Fan using Fuzzy Logic
(youtube.com)
FIGURE: HARDWARE IMPLEMENTATION OF THE CIRCUIT
FIGURE: HARDWARE IMPLEMENTATION OF THE CIRCUIT

You might also like