Skip to main content

Posts

Arduino Code to connect a flame sensor and gas sensor

The code below is uded to interface arduino with a flame sensor and a gas sensor together: int redLed = 12; int greenLed = 13; int smokeA0 = A0; int flamePin = 11; int Flame = HIGH; int sensorThres=100; void setup()  {   pinMode(redLed, OUTPUT);   pinMode(greenLed,OUTPUT);   pinMode(flamePin, INPUT);   pinMode(smokeA0,INPUT);   Serial.begin(9600); } void loop()  {   int analogSensor = analogRead(smokeA0);   Flame = digitalRead(flamePin);   if (Flame== LOW)   {     Serial.println("Fire!!!");     digitalWrite(redLed, HIGH);   }   else   {     Serial.println("No worries");     digitalWrite(redLed, LOW);   }   Serial.print("Pin A0: ");   Serial.println(analogSensor);   // Checks if it has reached the threshold value   if (analogSensor > sensorThres)   {     digitalWrite(greenLed, HIGH);   }   else   {     digitalWri...
Recent posts

Matlab Code to obtain DFT and plot its magnitude and phase response

Matlab Code:-   clc; clear all; close all; x=input('Enter the sequence: '); N=length(x); Wn=exp((-j*2*pi)/N);%Twiddle factor fprintf('Twiddle Factor=%f+j(%f)\n',real(Wn),imag(Wn)); disp('Magnitude and phase of Twiddle Factor:');     fprintf('|Wn|=%f    ',Wn);     fprintf('angle Wn=%f\n', angle(Wn));  fprintf('\n');  for k=1:N     X(k)=0; end %Calculation of DFT for k=1:N     for n=1:N         X(k)=X(k)+(x(n)*Wn^((k-1)*(n-1)));     end end %Printing the DFT fprintf('DFT of x(n) is:\n'); disp(X); fprintf('\n'); fprintf('X(k)\tMagnitude\tPhase\n\n'); for k=1:N     fprintf('X(%d)\t%f\t%f\n',k-1,X(k),angle(X(k))); end %To plot the magnitude and phase of the DFT subplot(1,2,1); stem(X,'linewidth',1.5); xlabel('k--->'); ylabel('magnitude--->'); title('Magnitude Response'); grid on; subplot(1,2,2); stem(angle(X),'linewidth',1.5); xlabel('k--->'); ylabel('...

Matlab Code for Circular Convolution using Matrix Method and also not using cconv method

Matlab Code:   clc; clear all; close all; %Circular Convolution by Matrix Method x=input('Enter the first sequence: '); h=input('Enter the second sequence: '); n=max(length(h),length(x)); A=0; %To obtain a circular matrix for i=1:n     if i==1         for j=1:n             A(i,j)=x(j); %first row stores all the elements of x(n)         end     else     for j=1:n         if(j==1)             A(i,j)=x(n-i+2); %first column of rows from i=2 to n are x(n),                                                                                x(n-i+2),...,x(3),x(2)         else             A(i,j)=A(i-1...

PN Sequence Generator Circuit Design in Multisim

 I tried doing a PN Sequence generator using a shift register in Multisim but it didn't work. However this one with d flip flops and xor gate did work somewhat. Here is the circuit.       Components Required:      1. 4D Flip Flops      2. XOR Gate      3. Function Generator for Clock Pulses      4. Oscilloscope       Circuit Design  :        Output:- Red Square waves- Clock Pulses Blue waves- PN sequence Hope this helps!

DFT Circular Convolution by Overlap Add Method in Matlab

  Matlab Code:       clc; close all ; x=input( 'Enter the input sequence: ' ); h=input( 'Enter the impulse sequence: ' ); n=length(x); m=length(h); z=1; for i=1:4     if i~=4         for j=1:m             X(i,j)=x(((i-1)*m)+1+(j-1));         end         for j=m+1:5             X(i,j)=0;         end     else         for j=1:5             if j==1                 X(i,j)=x(n);             else       ...

Narrate a story from your own life experience which reflects kindness to the self or kindness to others or kindness to the environment.

As Shakespeare quoted ‘ Beauty lives with kindness’, kindness is a noble act of gentleness to others, to environment or to one’s own self.   It gives inner happiness and makes one feel good about oneself. I did not know the gift of kindness until I experienced it myself. In my first year in college I went on a trip to Dehradun along with my family. We were heading towards Haridwar. On our way through the jungles of the Garhwal Himalayas amidst the lust green forest, we saw a young girl suddenly appear from behind the trees and jump in front of our car. Our driver stopped the car just on time. There I saw a girl of about ten years old whimpering. Her dress was torn, her hands and feet were bruised and she looked starved. We gave her some food and water and asked about her whereabouts. By now we could understand that she was blind. She told us that she lived in Chidderwala and that she was out with her brother to fetch some fire woods, when it started to rain and she slipped and fe...

Convolution of two signals using conv() in Matlab

We use the conv(x1,x2) function in Matlab to perform convolution of two discrete signals. For example, to perform the convolution of two discrete time sequences x1 (n) = {1, 0, 1,2}  and x2 (n) = {1, 2, 4, 6}. Code:  x1=[1,0,1,2]; %1st sequence N1=length(x1); %stores length of 1st sequence n1=0:1:N1-1; %range of x axis for 1st graph of 1st sequence subplot(1,3,1); % in a 1x3 grid, 1st sequence occupies the 1st grid stem(n1,x1,'linewidth',1.5); %to plot the sequence specifying time axis, signal and line width xlabel('n1----->'); %title of x axis ylabel('x1----->'); %title of y axis grid on; x2=[1,2,4,6]; %2nd sequence N2=length(x2);    %stores length of 2nd sequence n2=0:1:N2-1;  %range of x axis for 2nd graph of 2nd sequence subplot(1,3,2);  % in a 1x3 grid, 2nd sequence occupies the 2nd grid stem(n2,x2,'red','linewidth',1.5);  %to plot the sequence specifying time axis,signal,line width and colour xlabel('n2----->'); % title of...