Home Automation System

Wednesday, February 10, 2016

Phase shift of the AC current signal with Arduino

time taken to collect two samples

116 us

shiftvalue = V2 -V1/116us

for (int i ;i=172;i++){
TimeA =micros();
data[i]=anlogReading(A0);
TimeB[i]=micros()-TimeA;
}


for (int i ;i=172;i++){

Phase[i] = data[i]-data[i-1]/TimeB[i];

# Need to find phase shift of each values 
# to keep constant value to phase we need to add some corrective value to the main  value 
# How to get phase value  
# Normally to cover 360 deg it take 20 ms 
if  add each value of Phase  to complete 360 deg , time taken , are equivalent to 20 ms then same in the correct track . to adjust need to add some corrective values to each phase to get close to main value . 

}

Simple way of getting sample value 
# This can be in Setup() 
for (int i ;i=10;i++){
TimeA =micros();
data=anlogReading(A0);
TimeB[i]=micros()-TimeA;
}

for (int i ;i=0.02*1000/(Average Of TimeB[]);i++){
TimeA =micros();
data[i]=anlogReading(A0);
TimeB[i]=micros()-TimeA;
}


50Hz AC Current Arduino calibration

Sampling the 50 Hz wave in arduino Uno board analog reading;


50 Hz means , 50 cycles in a second,
to complete one circle it takes 20 ms

if you sample the wave in normal arduino Anlogreading
then it take 116us to take a sample ,
time that take to reading between two value is 116us ;
so 20 ms it takes only 172 samples ..(approx)

That is  20/116 ;

so ,,,, we need to identify the phase before process the sampling ,,,

for(i = 0; i<172;i++){
data[i]=analogRead(A0);
} 
and get the average of the sample,

or you can but may be zero for AC signal , because AC wave have negative value too,

so to avoid that, takes max value of the average signal and multiply with root square , to get RMS value.


Wednesday, August 26, 2015

ESP8266 Running Mode and Program Mode

Displaying IMG_20150827_085705.jpg

Note: A key programming , ESP8266 V0.9.2.2 version of firmware is changed .
Please add QQ group 120,693,138 in order to obtain more detailed information .
1. Please MTDO and GPIO0 to a low level , GPIO2 placed high.
   If your module does not MTDO, please at least GPIO0 placed low.
   GPIO0 at low level programming model is the high level run mode.
   Attention must use the pull-down resistor to set the level , not directly connected to VCC / GND.
2. Please resetting ( RST refers to low-level pulse ) or re- enter the programming mode on power .
3. Please do not use USB to TTL power leads , use a separate power supply .
   Power quality related to the module is stable , there is a problem please check the power priority .
4. After successful programming , please re-power . Module change the baud rate value 9600 or your last set .
5. Writing aborted , re- power programming.










Further ALL GPIO should connect to VCC/GND with 3.3K resistors to avoid excessive current. 



Monday, August 24, 2015

Arduino RAM Problems

int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

Arduino BIT operation time ;


 void setup() {
  // put your setup code here, to run once:
  DDRB = _BV(PB5);
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  long a = micros();
PORTB |= _BV(PB5);
long b = micros()-a;
Serial.print("Bit Operation TME:");
Serial.println(b);
delay(1000);
PORTB= B00000000;
delay(1000);
long k = micros();
digitalWrite( 13,HIGH);
long m = micros()-k;
Serial.print("Normal Op TME:");
Serial.println(m);
delay(1000);
PORTB= B00000000;
delay(1000);

}

OUTPUT :

Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:0
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8
Bit Operation TME:4
Normal Op TME:8

Arduino Port operation


Type of ports in Atmega328p;
Digital and Analog

DIGITAL PORTS 

PORTD : ( PD0 to PD7) 

Pin No : PD0-:( Pin 0 to Pin 7)

example :  PD2 = Pin 2 ;



DDRD = DDRD | B11111100;  // this is safer as it sets pins 2 to 7 as outputs
                   // without changing the value of pins 0 & 1, which are RX & TX 

PORTB : ( PB0 to PB5)

Pin No : PB0-5 : Pin 8 to Pin 13

BV=Bit Value.

PORTB |= _BV(PB5);

/* set bit 0 using _BV() */
PORTB |= _BV(PB5);

/* set bit 0 using shift */
a |= (1<<0);

Thursday, August 20, 2015

Another example for Analog Reading

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

 

Copy From ;
http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/