วันเสาร์ที่ 30 กันยายน พ.ศ. 2560

Infared remote control DIY


Wiring 








Library







Code


#include "IRremote.h"

 int RECV_PIN = 11;
 int Relay1 = 2;
 int Relay2 = 3;
 int Relay3 = 4;
 int Relay4 = 5;


 IRrecv irrecv(RECV_PIN);

 decode_results results;

 void setup()
 {
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the ir receiver
 pinMode(Relay1, OUTPUT); 
 pinMode(Relay2, OUTPUT); 
 pinMode(Relay3, OUTPUT); 
 pinMode(Relay4, OUTPUT);


  digitalWrite(Relay1,HIGH); // set the Relay on 
  digitalWrite(Relay2,HIGH); // set the Relay on 
  digitalWrite(Relay3,HIGH); // set the Relay on 
  digitalWrite(Relay4,HIGH); // set the Relay on 


 } 

 void loop() {


 if (irrecv.decode(&results)) {
 Serial.println(results.value, DEC);


 if(results.value == 16724175) //1 if you want to configure with your remote controll change the results.value
 digitalWrite(Relay1, LOW); // set the Relay on 
  if(results.value == 16738455)  //0
 digitalWrite(Relay1, HIGH ); // 0 set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16718055)
 digitalWrite(Relay2, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay2, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16743045)
 digitalWrite(Relay3, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay3, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 if(results.value == 16716015)
 digitalWrite(Relay4, LOW); // set the Relay on
 if(results.value == 16738455)
 digitalWrite(Relay4, HIGH); // set the Relay off

 irrecv.resume(); // Receive the next value

 }

 }



วันอาทิตย์ที่ 24 กันยายน พ.ศ. 2560

Sim900A+Arduino Factory alarm flame detector เตือนภัยด้วยระบบตรวจจับแสงไฟ ผ่านข้อความทางโทรศัพท์


Send alarm over temp VDO





Add more flame sensor



Wiring Flame sensor



Library  

https://www.dropbox.com/s/owwkbx4p3k8rsc0/GSM900.rar?dl=0

credit:  github

Code

#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];



//LCD 

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
//temp

int tempC;
int reading;
int tempPin = 0;


//flame

int flame = A3 ;// define the flame interface analog 0 interface
int Beep = 8 ; // buzzer interface defines the interface number 7
int val = 0 ; // define numeric variables val 

void setup()
{

  
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
//stup lcd
lcd.init(); 


//flame 

 pinMode(Beep, OUTPUT) ;// define LED as output interface
pinMode (flame, INPUT) ;// define the buzzer as the input interface

//setup temp
analogReference(INTERNAL);

  
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");



     

     if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("0843545655", "GSM Factory Alarm"))
          Serial.println("\nSMS sent OK");
     }

};


void loop()
{

  temp();
  lcd11();
  flame1();
  lcd11();
  flame1();

     if(started) {
      
          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer, 160, n, 20)) {

            
               Serial.println(n);  //Print out phone number
               Serial.println(smsbuffer); // Text 

              char* ptr = smsbuffer;

  while ( strlen(ptr) >= 2 ) {

    if ( ptr[0] == 'a' ) {
      if ( ptr[1] == '1' )
        digitalWrite(4, LOW);
      else
        digitalWrite(4, HIGH);
    }

    if ( ptr[0] == 'b' ) {
      if ( ptr[1] == '1' )
        digitalWrite(5, LOW);
      else
        digitalWrite(5, HIGH);
    }

     if ( ptr[0] == 'c' ) {
      if ( ptr[1] == '1' )
        digitalWrite(6, LOW);
      else
        digitalWrite(6, HIGH);
    }

    if ( ptr[0] == 'd' ) {
      if ( ptr[1] == '1' )
        digitalWrite(7, LOW );
      else
        digitalWrite(7, HIGH);
    }

     if ( ptr[0] == 'x') {
      if ( ptr[1] == '1'){
        digitalWrite(4,LOW);
        digitalWrite(5,LOW);
        digitalWrite(6,LOW);
        digitalWrite(7,LOW);}
         
     else
     {
        digitalWrite(4,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(7,HIGH);

      }
     }
    
  
    ptr += 2;
  }
          }
          delay(100);
     }
};

void flame1()

 {val = analogRead (flame) ;// read the analog value flame sensor

//delay(2000);
Serial.println (val) ;// output analog values, and print them out
 if (val >= 600) // When the analog value is greater than 600 when the buzzer sounds
{ digitalWrite (Beep, HIGH);} 
else {digitalWrite (Beep, LOW);
}
 if(val>=600)
 {
sms.SendSMS("0843545655", "flame over 600");

  }
  
}

void temp()

{

  reading = analogRead(tempPin);
tempC = reading / 7;

  

  if(tempC > 60 )
  {
sms.SendSMS("0843545655", "Temp over 60 C");

  }

  

  
}
void lcd11()


{ lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Temp");

  
  lcd.setCursor(2,1);
  lcd.print(tempC);

  lcd.setCursor(5,1);
  lcd.print("C");

  lcd.setCursor(8,0);
  lcd.print("Flame");

  lcd.setCursor(8,1);
  lcd.print(val);
 }







วันพุธที่ 20 กันยายน พ.ศ. 2560

SIM900A + Arduino Factory alarm














Wiring all same previous blog just add relay module


VDO





Free-shipping-1PCS-LOT-New-SIM900A-SIM900- (2)













                       


              

Connect 4 Relays module to Arduino Board

Wiring 

4 Relays module     to       Board Arduino

Vcc                                     5 Volt
IN1                                     Pin 4
IN2                                     Pin 5
IN3                                     Pin 6
IN4                                     Pin 7
GND                                   GND












I2C LCD

Connect

LCD >>> Arduino

GND  >>> GND
VCC  >>> 5Vcc
SDA  >>> A4
SCL   >>> A5


Temperature




aeProduct.getSubject()



Sig >>> A0 (Arduino)


Concept

Idea for control relay if you want to control something immedaitly

example pump lighting .

Send sms

a1  relay  IN1 on
a?  relay  IN1 off

b1  relay  IN2 on
b?  relay  IN2 off

c1  relay  IN3 on
c?  relay  IN3 off

d1  relay  IN4 on
d?  relay  IN4 off

x1  All relay  on
x?  All relay  off


Library




Code

#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];



//LCD 

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
//temp

float tempC;
int reading;
int tempPin = 0;

void setup()
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
//stup lcd
lcd.init(); 

//setup temp
analogReference(INTERNAL);

  
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");



     

     if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("08*******", "GSM SmartHome"))
          Serial.println("\nSMS sent OK");
     }

};


void loop()
{
  temp();
     if(started) {
      
          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer, 160, n, 20)) {

            
               Serial.println(n);  //Print out phone number
               Serial.println(smsbuffer); // Text 

              char* ptr = smsbuffer;

  while ( strlen(ptr) >= 2 ) {

    if ( ptr[0] == 'a' ) {
      if ( ptr[1] == '1' )
        digitalWrite(4, LOW);
      else
        digitalWrite(4, HIGH);
    }

    if ( ptr[0] == 'b' ) {
      if ( ptr[1] == '1' )
        digitalWrite(5, LOW);
      else
        digitalWrite(5, HIGH);
    }

     if ( ptr[0] == 'c' ) {
      if ( ptr[1] == '1' )
        digitalWrite(6, LOW);
      else
        digitalWrite(6, HIGH);
    }

    if ( ptr[0] == 'd' ) {
      if ( ptr[1] == '1' )
        digitalWrite(7, LOW );
      else
        digitalWrite(7, HIGH);
    }

     if ( ptr[0] == 'x') {
      if ( ptr[1] == '1'){
        digitalWrite(4,LOW);
        digitalWrite(5,LOW);
        digitalWrite(6,LOW);
        digitalWrite(7,LOW);}
         
     else
     {
        digitalWrite(4,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(7,HIGH);

      }
     }
    
  
    ptr += 2;
  }
          }
          delay(1000);
     }
};

void temp()

{

  reading = analogRead(tempPin);
tempC = reading / 10;
//Serial.println(tempC);


   // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Temperature");
  lcd.setCursor(2,1);
  lcd.print(tempC);

  if(tempC > 23 )
  {
sms.SendSMS("084*******", "Temp over 23 C");

  }
   
delay(1000);

}






วันศุกร์ที่ 8 กันยายน พ.ศ. 2560

Robot car Part 3/3 avoid obstacle . Finish







HC-SR04 Ultrasonic module








Drive unit using L298 2 motor driver 



Connection  
L298 to Arduino Nano
ENA=2;
IN1=3;
IN2=4;
ENB=7;
IN3=5;
IN4=6;
Add bluetooth for mobile App control


Bluetooth >> Arduino Nano

Rx >> 11
Tx >> 10
Vcc >> 5 Vcc
GND >> GND


Code 


#include <Servo.h> 

#include<SoftwareSerial.h>

Servo myservo;
const int pingPin = 13;
int inPin = 12;
SoftwareSerial mySerial(10, 11); // RX, TX
String state;
int ENA=2;
int IN1=3;
int IN2=4;
int ENB=7;
int IN3=5;
int IN4=6;
void setup() {

  // ultrasonic

  myservo.attach(9);
 // Serial.begin(9600);
  // put your setup code here, to run once:
       mySerial.begin(9600);
       Serial.begin(9600); //start serial communication
       pinMode(ENA, OUTPUT);//Pin2
       pinMode(IN1, OUTPUT);//Pin3
       pinMode(IN2, OUTPUT);//Pin4
       pinMode(IN3, OUTPUT);//Pin5
       pinMode(IN4, OUTPUT);//Pin6
       pinMode(ENB, OUTPUT);//Pin7

//digitalWrite(ENA,LOW);
//digitalWrite(IN1,LOW);
//digitalWrite(IN2,LOW);
//digitalWrite(IN3,LOW);
//digitalWrite(IN4,LOW);
//digitalWrite(ENB,LOW);
   
}
void loop() {
  // put your main code here, to run repeatedly:
 Ultrasonic();

  while (mySerial.available()){ //Check if there is an available byte to read
     delay(10); //Delay added to make thing stable 
    char c = mySerial.read(); //Conduct a serial read
   
    state += c; //Shorthand for voice = voice + c
}

if (state.length() > 0){
  //Serial.println(state);
  if(state == "forward")
  {


   Forward();
  }
 else if(state == "back")
 {
    Backward();
 }
 if(state == "left")
  {
    Turn_left();
  }
 else if(state == "right")
 {
    Turn_right();
 }
  else if(state == "stop")
 {
    Stop();
 }
  state =""; //Reset the variable after initiating
  }
}
void Forward()
{
 {digitalWrite(ENA,HIGH);
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);
 digitalWrite(ENB,HIGH);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH);}
}
void Backward()
{
 digitalWrite(ENA,HIGH);
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW);
 digitalWrite(ENB,HIGH);
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
}

void Turn_left()
{
 digitalWrite(ENA,HIGH);
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW);
 digitalWrite(ENB,HIGH);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH);
}
 void Turn_right()
{
 digitalWrite(ENA,HIGH);
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);
 digitalWrite(ENB,HIGH);
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
}
void Stop()
{
 digitalWrite(ENA,HIGH);
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,LOW);
 digitalWrite(ENB,HIGH);
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,LOW);
}
void Ultrasonic()
{
long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(inPin, INPUT);
duration = pulseIn(inPin, HIGH);
cm = microsecondsToCentimeters(duration);
 if (cm < 15) {  
    //  servo
Stop();
delay(1000);
Turn_right();
delay(250);
Stop();
delay(1000);
        myservo.write(0); 
        delay(1000);      
        myservo.write(90); 
        delay(1000);      
        myservo.write(270); 
        delay(1000);    
  // end servo
delay(2000);
  Forward();
}
  else {
    myservo.write(90);
  }
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}