Monday, January 8, 2018

Wireless voltmeter using Arduino and RF 433MHz receiver and transmitter

In this project i showed you how to make a wireless voltmeter using arduino and RF 433MHz receiver and transmitter.
You can use this code and concept for many other projects, any project which used sensor with analog voltage output to sense temperature, gas leakage or light , etc.
For example you can put a LM35 temperature sensor rather than potantiometer, you just have to putting its formula which convert LM35 output pin voltage to exact temperature.
You also can make a wireless AC or DC power meter by doing some change in code and hardware (using hall effect current sensor and single phase voltage sensor).
This type of RF module has distance range up to 200 meters according to datasheet but when i bought this RF module from Aliexpress its distance rang was very low, but i set its adjustable RF coil very carefully and i get very higher distance rang.(Don't play with RF coil if your module works good), You also have to use a 6 inch antenna to increase distance range to max as possible. 
This RF module is cheap and simple to use and suitable to works with 5v.

Parts list:
Arduino any version (2pcs)
RF 433MHz receiver and transmitter
Potentiometer 10K (2pcs)
LCD display 16x2

Download library of RCSwitch.h from this link:


Receiver Wiring:


Wireless voltmeter using Arduino and RF 433MHz receiver and transmitter
Receiver Code:

#include <RCSwitch.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 7);
RCSwitch mySwitch = RCSwitch();
float value;
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  mySwitch.enableReceive(0);
 // Receiver on inerrupt 0 => that is pin #2
}

void loop() {
lcd.clear();
     
  if (mySwitch.available()) {
   
    int value = mySwitch.getReceivedValue();
    lcd.setCursor(0,0);
      lcd.print("Voltage=");
    if (value == 0) {
      Serial.print("Unknown encoding");
     
    } else {
     
     
      lcd.setCursor(0,1);
      lcd.print((value * 5.0)/1024.0);
      lcd.print(" ");
      delay(500);
    }

    mySwitch.resetAvailable();
   
  }
}


Transmitter Wiring:


Wireless voltmeter using Arduino and RF 433MHz receiver and transmitter


Transmitter Code:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup()
{
  mySwitch.enableTransmit(7); //Connect data transmitter to Pin7 of Arduino
  }


void loop() {
 int sensorValue = analogRead(A0);
 delay(100);
 mySwitch.send(sensorValue , 12);
 delay(2000); 
}

Video:
In this video you can see how this project works


Monday, December 18, 2017

Power factor measurment using Arduino

In this project i used arduino and XOR gate to power factor measurement.

What is power factor?
Power factor is a number between 0 and 1 refers to phase shaft between voltage phase and current phase in AC appliance.

Power factor measurment using Arduino

How to measure PF with Microcontroller (Arduino)?

To measuring power factor with microcontrollers in first we used Op-Amp to zero cross detection to find the phase shift between current and voltage phase, the op-amp convert the sine wave signal comes from CT and PT with different amplitude to square wave with about 4v amplitude, then we connect these two square wave to XOR gate inputs. 
XOR gate output is 1 just when the input had different signal so when the load is resistive XOR gate output is 0 because the both voltage and current phase start and end in same time, but when the load is inductive or capacitive XOR output is 1 because there are phase shaft between voltage and current,

Power factor measurment using Arduino


Hence we can find the power factor by measuring the duty cycle of XOR output, but the inverse duty cycle because when the duty cycle is 0% that means PF is 1 (100%) and when duty cycle is 40% PF is 0.6 (60%) and so on,
So:
PF= (100-duty cycle)/100
OR 
PF=Low time / Period Time
 Circuit:
Here we have two circuits, the first one using Current transformer(CT) and Voltage or potential transformer(PT), the only difference between them is that second circuit with no transformer and no insulation between microcontroller and main voltage so its dangerous if you touch any point in the circuit, but its cheap, small size, light weight and similar to commercial socket power meter.    
Filtering capacitors in this circuit is very important to removing power supply noise( voltage ripple) to insure logic gate works well.

Power factor measurment using Arduino
Power factor measurment using Arduino
Arduino LCD wiring:
Power factor measurment using Arduino

 
Results:

This picture shown voltage and current phases when PF=1


XOR output signal when PF=1


Voltage and current phases when PF=0.84 

 Power factor measurment using Arduino 


XOR output signal when PF=0.84

Power factor measurment using Arduino

Voltage and current phases when PF=0.66

Power factor measurment using Arduino

XOR output signal when PF=0.66

Power factor measurment using Arduino


NOTES:
1- This project deal with main voltage so its dangerous.
2-This project need to only two op-amp but should be use them in separate IC package as i used LM324 and that's quad op-amp but i used two separate ICs otherwise we received false results. that's because there are not insulation between A1 and A2 or A2 and A3 and so on.
3-If you remove C2 in non-linear loads(harmonic loads) i see PF reading by microcontroller will be false, so used it whether your load is linear or non-linear to give true reading.
4-However transformers haven't polarity but here transformer winding point(dot) is very important, because if CT and PT dot don't match, the arduino will read the PF lower than 1 even with pure resistive load.

Power factor measurment using Arduino

5-In first connect a resistive load to test if your project works well or no.

In this video you can see how this project works:



 
You can improve this project to power factor correction by adding some relay and capacitor and improving the code.


Parts list:
Arduino board
IC 4030 or IC 4070 (XOR gate)
Voltage Transformer 15V or less
Current transformer
Resistor 100K
Resistor 220 ohm
Potentiometer 10K or 100K
Capacitor 47pF (2pcs)
Capacitor 100nF
Capacitor470uF
LCD display 16x2
Diode 1N4148 (4pcs)
LM324 or 741(2pcs)


CODE:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int input=13;

int high_time;
int low_time;
float time_period;
float freq;
float powerfactor;
void setup()
{
pinMode(input,INPUT);
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("POWER FACTOR=");

high_time=pulseIn(input,HIGH);
low_time=pulseIn(input,LOW);


time_period=high_time+low_time;
powerfactor=low_time/time_period;
lcd.setCursor(0,1);
lcd.print(powerfactor);
lcd.print(" ");
delay(500);
}

Wednesday, August 30, 2017

Arduino 220v AC dimmer with remote control with code

This Arduino project help you to control brightness of a 220V dimmable lamp or speed of ceiling fan (or any other electric motor) with an IR remote control using Arduino.
Max. power which can controlled with this dimmer depend on triac model.(BT136 can bear 4A according to Datasheet).

This project consist of 4 basic parts:

1-Microcontroller(Arduino)
2-Zero-cross detector(Bridge and Optocoupler)
3-Display(7Segment)
4-Phase angel controller(Tiac and Triac driver)

The load can controlled by Up and Down bush button or with IR remote controller. 

Circuit diagram:

Arduino 220v AC dimmer with remote control with code
 

Parts list:
Arduino UNO(or other version)
Optocoupler pc817
Triac driver MOC3021(Or any other Random-phase triac driver)
1 Digit 7 Segment common cathode
Triac BT136
Diode bridge(4pcs 1N4007)
Push bottom(4pcs)
Resistor 100K(2pcs)
Resistor470 ohm (2pcs)
Resistor 330 ohm
Resistor 100 ohm 1W
Resistor 10K
Capacitor 100nF 400v
IR receiver 1830B
Important NOTES:
1- You have to using only RANDOM-phase triac driver such as MOC 3021 or MOC 3023 , etc, and don't use MOC3041 or other triac driver with Zero-cross detector.
2-This project directly connected to 110/220v AC so can be very dangerous for beginners.
3-Red components(100 ohm resistor and 100nF capacitor) shown in above diagram should only used when the load is inductive.
4-Don't use this Dimmer for non-dimmable load such as CFL lamps, dimming can burn your lamp.
5-The number after "Case" in the code need to change with number that shown to you in "Serial Monitor" when you press a button on your remote control toward the IR receiver .

Arduino 220v AC dimmer with remote control with code


You can watch in following video how this project works:


Code:

#include "IRremote.h"
//-----( Declare Constants )-----
int receiver = 13;
//-----( Declare objects )-----
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'
//-----( Declare Variables )-----


#include <TimerOne.h>           // Avaiable from http://www.arduino.cc/playground/Code/Timer1

volatile int i=0;               // Variable to use as a counter
volatile boolean zero_cross=0;  // Boolean to store a "switch" to tell us if we have crossed zero
int AC_pin = 3;                 // Output to Opto Triac
int buton1 = 4;                 // first button at pin 4
int buton2 = 5;                 // second button at pin 5
int dim2 = 0;                   // led control
int dim = 128;                  // Dimming level (0-128)  0 = on, 128 = 0ff
int pas = 10;                   // step for count;
int A = 9;                  // step for count;
int B = 6;
int C = 7;
int D = 8;
int E = 12;
int F = 10;
int G = 11;
// version: 4m7 (15.04.2013 - Craiova, Romania) - 16 steps, 4 button & LED blue to red (off to MAX)
// version: 7m6.1 (23.01.2014 - Craiova, Romania) - 16 steps, 2 button & LCD1602

int freqStep = 75;    // This is the delay-per-brightness step in microseconds.

char incomingByte;  // incoming data from serial 9bluetooth)

void setup() {  // Begin setup

  Serial.begin(9600); // initialization
 
  irrecv.enableIRIn(); // Start the IR receiver (classic remote)

  pinMode(buton1, INPUT);  // set buton1 pin as input
  pinMode(buton2, INPUT);  // set buton1 pin as input
  pinMode(AC_pin, OUTPUT);                          // Set the Triac pin as output
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);                       
  attachInterrupt(0, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
  Timer1.initialize(freqStep);                      // Initialize TimerOne library for the freq we need
  Timer1.attachInterrupt(dim_check, freqStep);     
  // Use the TimerOne Library to attach an interrupt

}

void zero_cross_detect() {   
  zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured
  i=0;
  digitalWrite(AC_pin, LOW);
}                                

// Turn on the TRIAC at the appropriate time
void dim_check() {                  
  if(zero_cross == true) {             
    if(i>=dim) {                    
      digitalWrite(AC_pin, HIGH);  // turn on light      
      i=0;  // reset time step counter                        
      zero_cross=false;    // reset zero cross detection
    }
    else {
      i++;  // increment time step counter                    
    }                               
  }   
}                                     


//-----( Declare User-written Functions )-----
void translateIR() // takes action based on IR code received

{
  switch(results.value)
  {
 
   
case 16724175:
 
    dim=128;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, LOW);
    }
    break;
   
case 16744575: 
    dim=120;
    {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    }
    break;

case 16728255: 
    dim=105;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, LOW);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, LOW);
    digitalWrite(G, HIGH);
    }
    break;

case 16760895: 
    dim=90;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, HIGH);
    }
    break;
   
case 16720095: 
    dim=75;
    {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
    break;

case 16752735: 
    dim=60;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
    break;

case 16736415: 
    dim=45;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
    break;

case 16769055: 
    dim=30;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    }
    break;

case 16716015: 
    dim=15;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
    break; 
   
case 16748655: 
    dim=00;
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
    break;  


  case 16758855: 
    {
    if (dim<127) 
   {
    dim = dim + pas;
    if (dim>127)
    {
     dim=128;
    }
    }
    }
    break;

  case 16730295: 
    {
      {
  if (dim>5) 
  {
     dim = dim - pas;
  if (dim<0)
    {
      dim=0;  // in vechiul sketch era 1
    }
   }
   }
   }
    break;
  
   if(dim>100)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, LOW);
    }
  
    default:
    Serial.println(results.value);
  }

}


void loop() { 
  digitalWrite(buton1, HIGH);
  digitalWrite(buton2, HIGH);


 if (digitalRead(buton1) == LOW)  
   {
  if (dim<127) 
  {
    dim = dim + pas;
    if (dim>127)
    {
      dim=128; // in vechiul sketch era 127
    }
  }
   }
  if (digitalRead(buton2) == LOW)  
   {
  if (dim>5) 
  {
     dim = dim - pas;
  if (dim<0)
    {
      dim=0;  // in vechiul sketch era 1
    }
   }
   }
    while (digitalRead(buton1) == LOW) {  }             
    delay(10); // waiting little bit... 
    while (digitalRead(buton2) == LOW) {  }             
    delay(10); // waiting little bit...   

 if(dim>127)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, LOW);
    }
   
      
 if(127>dim && dim>115)
    {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    }

 if(115>dim && dim>105)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, LOW);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, LOW);
    digitalWrite(G, HIGH);
    }

 if(105>dim && dim>90)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, HIGH);
    }
   
 if(90>dim && dim>75)
   {
    digitalWrite(A, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }

 if(75>dim && dim>60)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }

 if(60>dim && dim>45)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }

 if(45>dim && dim>30)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    }

 if(30>dim && dim>15)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }
     
 if(15>dim && dim>00)
    {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, LOW);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    }

// remote
   if (irrecv.decode(&results)) // have we received an IR signal?
  {
    translateIR();
    irrecv.resume(); // receive the next value
  } 

 delay (100);
}

Sunday, December 18, 2016

Auto light switch for bathroom using laser and IC4017

Many people forgets the bathroom and toilet lamps in ON state, absolutely this causes increasing electric bill and even decrease lamps lifespan. This circuit is a simple way to turning ON and OFF the bathroom or toilet lamp automatically without using microcontroller.
The circuit based on the counter IC4017 and laser. when a person go to bathroom his body cut the laser ray that is focused on the LDR in another side of the door frame, connecting and disconnecting the laser ray changed the LDR electric resistance and giving a positive signal to pin14 of the IC4017 through transistor 2N2222, since pin4 jumped to reset pin (pin15) so the output selector will be changed between pin3 and pin2. Pin3 run the transistor to running the relay.
Two LEDs showing ON state and OFF state. 330 ohm resistor used to LEDs protection by giving 15mA current to them.
You can use any other NPN transistor rather than 2N2222 such as BC547, C9013, 2N5551, etc. 
This circuit is suitable for light switching for any place that used by one person such as toilet and bathroom, you can't use it for the room because when second person coming  inside the room the lamp will be turns OFF.

Part list:
IC4017
Transistor 2N2222
Laser 5mW
Relay 5v 
LEDs
LDR
Resistor 1K
Resistor 200K
Resistor 2.2K
Resistor 330R
Capacitor 10nF
Diode 1N4007


Auto light switch for bathroom using laser and IC4017

Auto light switch for bathroom using laser and IC4017

In following video you can watch how the circuit works:


Saturday, November 26, 2016

220V Auto room light switch using Arduino and Lazer (Visitor counter)

Many peoples forgets the Room lamps in running state when nobody in the room, this causes increasing electric bill or battery energy losing in solar home.
This Arduino project is a visitor counter that turns OFF the lamp when nobody in the room automatically, it also can used for lamps of bathroom, toilet, kitchen, etc.
Visitor counter can makes by using different types of sensors, such as IR ray, Ultrasonic, Avoidance sensor, Laser ray, etc.
Here i used Laser because the laser has long distance range, Avoidance sensor is very easy to use but its distance rang is lower than 30cm.
You can make this project with LCD display for showing the numbers of people in the room but as you can see in the video i don't used display because its not important for me, any way the code is same with or without display.
This project help to power consumption optimizing. 

Parts list:
Arduino board 
1 Channel Relay module
Laser diode(2 pcs)
Light sensor modules(2 pcs)
Adapter 5v 200mA
If you want to using display, need :
16X2 LCD Display
Resistor 10K
Resistor 220 ohm

220V Auto room light switch using Arduino and Lazer (Visitor counter)


220V Auto room light switch using Arduino and Lazer (Visitor counter)

220V Auto room light switch using Arduino and Lazer (Visitor counter)

Manual OFF switch used when you are in the room but want to turning OFF the lamp for sleep.

220V Auto room light switch using Arduino and Lazer (Visitor counter)


I used 1000uF 16v capacitor for power line to protect the arduino board from sudden voltage raising but its not necessary.

220V Auto room light switch using Arduino and Lazer (Visitor counter)

220V Auto room light switch using Arduino and Lazer (Visitor counter)



There are some important notes for making this project: 

1-Put the laser diode in the door frame before LDRs to determine the LDRs suitable position and to making sure the laser beam and LDRs are in same straight line. 

2-The laser diodes must set in suitable height to become suitable for all peoples with different long. also you have pay attention to door handle position, when the door is closed, handle maybe cuts the laser beam so put the laser beam above the handle.

3-The laser is harmful for eyes when its directly toward your eyes. 

4-One problem will happen for ONLY FIRST TIME USING this project. That problem is:
When you are in the room and turns this project ON for first time the light will be OFF because the Arduino count zero people come in the room(nobody) when you try to getting out the room the arduino turns ON the light because it count -1 people in the room. So in first time please try to get out the room without cutting the laser beam.
I'm trying solve this problem in the code.  



Code:

#include<LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 3, 4, 5, 6);
#define in 11
#define out 12
#define relay 13
int count=0;
void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}
void loop()

 
  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();
 
  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }
 
  else
    digitalWrite(relay, HIGH);
 
}

Wednesday, November 23, 2016

AC 220V Frequency counter using arduino

In this project i used Arduino and some other electronic components for AC mains frequency measurement.
Since Frequency is equal to: 1 divided by time period, so in first we should measure the time period. Time Period is the time of one full wave in AC voltage, means positive half wave+negative half wave.
Here i used optocoupler for detecting the frequency of AC voltage. 47K resistor decrease the current to about 5mA for running the optocoupler and one diode for half wave rectification  So the arduino here calculate the ON time and OFF time of optocoupler that connected to Pin 13 in arduino board, then divided 1 by (ON+OFF) Time for give the frequency. 
Since in arduino code the time always must insert as millisecond so we devide 1000 by ON+OFF Time for give the frequency.
The circuit 100% insulated from mains voltage and can not be harmful for your arduino board.
You can use any other available optocoupler rather than 817B. 

AC 220V Frequency counter using arduino

Parts list: 
Arduino board
LCD display 16x2
Resistor 10K
Resistor 220 ohm
Resistor 47K / 1W
Diode 1N4007
Potentiometer 10K
Optocoupler 817B or any optocoupler  

NOTE: Don't touch the circuit when it connected to mains voltage.
 
AC 220V Frequency counter using arduino

AC 220V Frequency counter using arduino



Code:

 #include <LiquidCrystal.h>
int input=13;

int high_time;
int low_time;
float time_period;
float freq;
float frequency;
LiquidCrystal lcd(0, 1, 3, 4, 5, 6);
void setup()
{
pinMode(input,INPUT);
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Frequency Meter");

high_time=pulseIn(input,HIGH);
low_time=pulseIn(input,LOW);


time_period=high_time+low_time;
time_period=time_period/1000;
frequency=1000/time_period;
lcd.setCursor(0,1);
lcd.print(frequency);
lcd.print(" Hz");
delay(500);
}

Monday, July 25, 2016

Fridge door alarm circuit with delay time

New fridge models contain an alarm to notice door leaves open, it prevent energy losing.
This circuit is a simple fridge door alarm that active when the fridges door leaves open for 15 seconds, this delay time depend on 10uF capacitor so you can increase this delay time by increasing the capacitor value.
Alarm sound frequency depend on second capacitor value.
The circuit run with 9v battery and draw 40mA when the alarm is active and lower than 10mA when it is in standby state. Its better to use a rechargeable 9v battery.

Parts list:
IC555 (2pcs)
Buzzer
LDR
Resistor 1M
Resistor 1.5M
Resistor 100K
Capacitor 10uF
Capacitor 220nF
Battery 9v

Fridge door alarm circuit with delay time

Fridge door alarm circuit with delay time