Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Saturday, 27 August 2011

Remote outlets, AVIDSEN and CHACON


Remote Control AVIDSEN (103107)

ON OFF
A 265353 265349
B 266325 266321
C 266649 266645
D 266757 266753
E 266793 266789

period 150
















Remote Control CHACON (EMW200RC)

ON OFF
1 164023 164022
2 172771 172770
3 175687 175686
4 176659 176658

period 360

(Note: you may have to try different period intervals, only this worked for me, and it is different from what i get in show_received_code program from RemoteSwitch Library)













How control remote outlets with Arduino ?

1 - Get an RF 433Mhz transmitter module
2 - Install RemoteSwitch library
3 - Connect module to PIN 4
4 - Upload program with the right codes













#include <RemoteSwitch.h>


#define OUTLET_A_ON 265353
#define OUTLET_A_OFF 265349
#define PERIOD 150;

#define RF_TX_PIN 4

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println("Sending off");
transmit(OUTLET_A_OFF);
delay(5000);

Serial.println("Sending on");
transmit(OUTLET_A_ON);
delay(5000);
}

void transmit(unsigned long rcode){
unsigned long code = rcode;
unsigned long period = PERIOD;
code |= (unsigned long)period << 23;
code |= 3L << 20;
RemoteSwitch::sendTelegram(code, RF_TX_PIN); // RF transmitter pin
}


Tuesday, 4 January 2011

Arduino Remote Control Outlet

Today i bought an remote control outlet kit from avidsen (2 adapters + remote control)
Using the library and info from here and here, was possible to decode the on/off codes.

After finding these codes, i added and actuator to the platform with two functions on() and off()



Electric water heater


Outlet adapter


Outlet adapter and remote control



Actuator in system


Mobile version





New update: i was forgetting one important thing, set a policy to turn on water heater between 7 am and 8 am and turn off after 8 am.


My policies in system


turn_heater_on policy info



Thursday, 9 December 2010

Preparing Arduino Bug Zapper


Objectives:

Detect when a bug is killed
Send data to server



Testing ATmega 328 with Arduino bootloader



No PCB :(



Bug Zapper racket


Next steps:

Attach Electret Microphone [link]
Attach 315MHz Transmitter module [link]
Calibration
Add everything to racket inside





Tuesday, 19 October 2010

DHT11 Arduino with VirtualWire

By some reason when using VirtualWire library and using vw_setup(2000) caused the readings from humidity sensor to fail (dht11 start condition 1 not met). I looked at datasheet and changed a the times how the MCU starts to talk with the sensor.

The code is based from this post

Here is the the fixed code:

void InitDHT() {
 pinMode(TEMP_RH_PIN, OUTPUT);
 delay(1000);
 digitalWrite(TEMP_RH_PIN,HIGH);
}

void ReadDHT() {

 bGlobalErr=0;
 byte dht_in;
 byte i;
        
        // see datasheet to understand this
        pinMode(TEMP_RH_PIN, OUTPUT);
        digitalWrite(TEMP_RH_PIN,HIGH);
        
 digitalWrite(TEMP_RH_PIN,LOW);
 delay(18);

 digitalWrite(TEMP_RH_PIN,HIGH);
 delayMicroseconds(22);

 pinMode(TEMP_RH_PIN,INPUT);
 delayMicroseconds(5);

 dht_in=digitalRead(TEMP_RH_PIN);

 if(dht_in) {
  bGlobalErr=1;
  Serial.println("<dht11 start condition 1 not met");
  return;
 }
 
 delayMicroseconds(80);
 dht_in=digitalRead(TEMP_RH_PIN);

 if(!dht_in) {
  bGlobalErr=2;
  Serial.println("<dht11 start condition 2 not met");
  return;
 }
 delayMicroseconds(80);
 
        //now ready for data reception... pick up the 5 bytes coming from the sensor
 for (i=0; i<5; i++)
    dht_dat[i] = read_dht_dat();

 //Next: restore pin to output duties
 pinMode(TEMP_RH_PIN,OUTPUT);
 digitalWrite(TEMP_RH_PIN,HIGH);

 byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];

 /*Condition in following "if" says "if fifth byte from sensor
       not the same as the sum of the first four..."*/
 if(dht_dat[4]!= dht_check_sum) {
   bGlobalErr=3;
          Serial.println("DHT11 checksum error");   
 }

}


byte read_dht_dat() {
 //Collect 8 bits from datastream, return them interpreted
 //as a byte. I.e. if 0000.0101 is sent, return decimal 5.
 //Code expects the system to have recently entered the
 //dataline low condition at the start of every data bit's
 //transmission BEFORE this function is called.
 byte i = 0;
 byte result=0;
 for (i=0; i< 8; i++) {
  //We enter this during the first start bit (low for 50uS) of the byte
  //Next: wait until pin goes high
  while(digitalRead(TEMP_RH_PIN)==LOW);
  delayMicroseconds(30);
  if (digitalRead(TEMP_RH_PIN)==HIGH)//Was: if(PINC & _BV(dht_PIN))
  result |=(1<<(7-i));
  while (digitalRead(TEMP_RH_PIN)==HIGH);
  //Was: while((PINC & _BV(dht_PIN)));
 }
 //end of "for.."
 return result;
}

Thursday, 14 October 2010

Arduino code to read lines from serial input

Here is short and useful example to read lines from serial port in Arduino.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void setup (){
  Serial.begin(9600);
  Serial.flush();
  digitalWrite (13, HIGH);      //turn on debugging LED
}

void loop (){

  int i=0;
  char commandbuffer[100];

  if(Serial.available()){
     delay(100);
     while( Serial.available() && i< 99) {
        commandbuffer[i++] = Serial.read();
     }
     commandbuffer[i++]='\0';
  }

  if(i>0)
     Serial.println((char*)commandbuffer);

}