#include<Servo.h>
Servo leftgate, rightgate;
int lamp1=22,lamp2=28, lamp3=24, lamp4=25, lamp5=26, lamp6=27,lamp7=23, lamp8=29, lamp9=30, fan1=32, fan2=33, fan3=34, fan4=35, fan5=36;
int door2=48, buzzer=28;
int state = 0, switch1_state = 0, times, firstconnect=1, alarm_slowrity, bithigh=0;
int flag = 1, pir=A5, lamp1on, x=0,flag1=0, displaydelay, lastdisplay=0, unfounddelay=0, flagfound=false;
long first_time, count=0, BPM=0, lastmillis, lastbpm=60, laston=0;
boolean readpulses=false, outdoor_on=false, outdoor_off=true;
int pulsePin = 0, standardbpm = 790, manualPin = 5; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0, bitpm, bitdelay=0, unbitdelay=0, lastunfound=0; // used to fade LED on with PWM on fadePin
// int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600, highcount=0; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
static boolean serialVisual = false; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
boolean flagunfound=false, firstunfound=0, displaybpm=false, autolamp1;
void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(pulsePin,INPUT);
pinMode(manualPin,INPUT);
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat! // we agree to talk fast!
//interruptSetup();
leftgate.attach(3);
rightgate.attach(2);
pinMode(pir, INPUT);
pinMode(lamp1, OUTPUT);
pinMode(lamp2, OUTPUT);
pinMode(lamp3, OUTPUT);
pinMode(lamp4, OUTPUT);
pinMode(lamp5, OUTPUT);
pinMode(lamp6, OUTPUT);
pinMode(lamp7, OUTPUT);
pinMode(lamp8, OUTPUT);
pinMode(lamp9, OUTPUT);
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(fan3, OUTPUT);
pinMode(fan4, OUTPUT);
pinMode(fan5, OUTPUT);
digitalWrite(lamp1, LOW);
digitalWrite(lamp2, LOW);
digitalWrite(lamp3, LOW);
digitalWrite(lamp4, LOW);
digitalWrite(lamp5, LOW);
digitalWrite(lamp6, LOW);
digitalWrite(lamp7, LOW);
digitalWrite(lamp8, LOW);
digitalWrite(lamp9, LOW);
digitalWrite(fan1, LOW);
digitalWrite(fan2, LOW);
digitalWrite(fan3, LOW);
digitalWrite(fan4, LOW);
digitalWrite(fan5, LOW);
rightgate.write(102);
leftgate.write(8);
Serial.begin(9600);
}
void loop()
{
//digitalWrite(5,HIGH);
//if(readpulses==true)
//readpulse();
//if(analogRead(pir)>250&&lamp1on==1&&autolamp1==true){
//digitalWrite(lamp1,LOW);
//delay(2000);
//}
//else
//digitalWrite(lamp1,HIGH);
while (Serial.available() > 0)
{
state = Serial.read();
Serial.println(state);
flag = 1;
flag1=0;
if (state == 236)//input="1"
{
readpulses=false;
}
if (state == 43 || state == 13)//input="1"
{
first_time=millis();
}
if((millis()-first_time)>350){
if (state == 101)//input="1"
{
digitalWrite(lamp1, HIGH);
lamp1on=0;
}
else if (state == 105)
{
digitalWrite(lamp1, LOW);
lamp1on=0;
.....
Please View the full Code on my Google Drive (Click Skip Ads After Clicking link below):
View on Google Drive
To get Arduino Microcontroller for the BEST PRICE! I recommend follow this > link
You can GET the CHEAPEST Arduino here:
1. Amazon link 1 (Arduino Nano)
2. Amazon link 2 (Arduino Nano)
3. Amazon link 3 (Arduino Nano)
Engineering Projects
Tuesday, January 5, 2016
Saturday, November 21, 2015
Monday, October 12, 2015
SMART HOME SYSTEM (ANDROID PROGRAM)
This is the program source code for my application which can control arduino's bluetooth module. It was the java code for this SYSTEM that I have build for myself. It still be okay for your source in making the application like that. This classes code just for communication within bluetooth modules.
The Code :
View on Google Drive
You can GET the CHEAPEST Arduino here:
1. Amazon link 1 (Arduino Nano)
2. Amazon link 2 (Arduino Nano)
3. Amazon link 3 (Arduino Nano)
The Code :
package com.led.led; import android.app.Application; import android.media.AudioManager; import android.media.ToneGenerator; import android.net.Uri; import android.os.Handler; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; import android.app.ProgressDialog; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.os.AsyncTask; import android.widget.ToggleButton; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.Viewport; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.Random; import java.util.UUID; import java.util.Timer; import java.util.TimerTask; public class ledControl extends ActionBarActivity { Button btnDis, eStatistic; ToggleButton lamp1, lamp2, lamp3, lamp4, fan1, fan2, fan3, fan4, leftgate, rightgate, bothgate, aircond1, aircond2, aircond3, door1, door2; ToggleButton hbtoggle; Switch Alarmswitch; CheckBox Autolamp; String address = null; SeekBar brightness; TextView lumn, showBPM, displaywakeup; private ProgressDialog progress; BluetoothAdapter myBluetooth = null; BluetoothSocket btSocket = null; private BufferedReader BufferedReader = null; private boolean isBtConnected = false; //SPP UUID. Look for it static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); public static String EXTRA_USAGE = "electric_usage"; String aString = null; InputStream aStream = null; InputStreamReader aReader = null; private BufferedReader mBufferedReader = null; private static final Random RANDOM = new Random(); private LineGraphSeries<DataPoint> series; private int lastX = 4, rhrcount=0; OutputStream mmOutputStream; InputStream mmInputStream; Thread workerThread; byte[] readBuffer; int readBufferPosition; boolean latch = false, graphing=true; int counter, intdata=0, bitpm=0; int[] intusage = {252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252}; int bpm = 0, xaxis=0, currentusage = 0, usage[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}; volatile boolean stopWorker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent newint = getIntent(); address = newint.getStringExtra(DeviceList.EXTRA_ADDRESS); //receive the address of the bluetooth device //view of the ledControl setContentView(R.layout.activity_led_control); //call the widgtes btnDis = (Button)findViewById(R.id.button2); eStatistic = (Button)findViewById(R.id.Statistic); brightness = (SeekBar)findViewById(R.id.seekBar); lumn = (TextView)findViewById(R.id.lumn); lamp1 = (ToggleButton)findViewById(R.id.LamptoggleButton); lamp2 = (ToggleButton)findViewById(R.id.FantoggleButton); lamp3 = (ToggleButton)findViewById(R.id.toggleButton); lamp4 = (ToggleButton)findViewById(R.id.WindowtoggleButton); Autolamp = (CheckBox)findViewById(R.id.checkBoxAuto); fan1 = (ToggleButton)findViewById(R.id.toggleButton2); fan2 = (ToggleButton)findViewById(R.id.toggleButton3); fan3 = (ToggleButton)findViewById(R.id.toggleButton4); fan4 = (ToggleButton)findViewById(R.id.toggleButton5); hbtoggle = (ToggleButton)findViewById(R.id.HBtoggle); aircond1 = (ToggleButton)findViewById(R.id.toggleButton10); aircond2 = (ToggleButton)findViewById(R.id.toggleButton14); aircond3 = (ToggleButton)findViewById(R.id.toggleButton6); leftgate = (ToggleButton)findViewById(R.id.leftgate); rightgate = (ToggleButton)findViewById(R.id.rightgate); bothgate = (ToggleButton)findViewById(R.id.bothgate); Alarmswitch = (Switch)findViewById(R.id.Alarmswitch); showBPM = (TextView)findViewById(R.id.BPMShow); displaywakeup = (TextView)findViewById(R.id.displaywakeup); GraphView graph = (GraphView) findViewById(R.id.graph); series = new LineGraphSeries<DataPoint>(); new ConnectBT().execute(); //Call the class to connect //commands to be sent to bluetooth graph.addSeries(series); Viewport viewport = graph.getViewport(); viewport.setYAxisBoundsManual(true); viewport.setMinY(0); viewport.setMaxY(10); viewport.setScrollable(true); Alarmswitch.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (Alarmswitch.isChecked()) onAlarm(); else offAlarm(); } }); lamp1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (lamp1.getText().toString().equals("ON")) { onlamp1(); setauto(); displaywakeup.setText("Wakeup"); usage[1]=1; } else{ offlamp1(); usage[1]=0;} } }); lamp2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (lamp2.getText().toString().equals("ON")) onlamp2(); else offlamp2(); } }); lamp3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(lamp3.getText().toString().equals("ON")) onlamp3(); else offlamp3(); } }); ......
void beginListenForData() { final Handler handler = new Handler(); final byte delimiter = 45; //This is the ASCII code for a newline character stopWorker = false; readBufferPosition = 0; readBuffer = new byte[1024]; workerThread = new Thread(new Runnable() { public void run() { while(!Thread.currentThread().isInterrupted() && !stopWorker) { try { int bytesAvailable = mmInputStream.available(); if(bytesAvailable > 0) { byte[] packetBytes = new byte[bytesAvailable]; mmInputStream.read(packetBytes); for(int i=0;i<bytesAvailable;i++) { byte b = packetBytes[i]; if(b == delimiter) { byte[] encodedBytes = new byte[readBufferPosition]; System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length); final String data = new String(encodedBytes, "US-ASCII"); readBufferPosition = 0; int intdata = Integer.parseInt(data); if(intdata<=10) bpm=intdata; else { bitpm = intdata; rhrcount++; } handler.post(new Runnable() { public void run() { int intdata = Integer.parseInt(data); if(rhrcount>100) displaywakeup.setText("Wake UP"); if(intdata>10) showBPM.setText(data); } }); latch = false; } else if(latch==true) { readBuffer[readBufferPosition++] = b; } else if(b == 35) { latch = true; } else { } } } } catch (IOException ex) { stopWorker = true; } } } }); workerThread.start(); } }
......
Please View the full Code on my Google Drive (Click Skip Ads After Clicking link below):
View on Google Drive
You can GET the CHEAPEST Arduino here:
1. Amazon link 1 (Arduino Nano)
2. Amazon link 2 (Arduino Nano)
3. Amazon link 3 (Arduino Nano)
Monday, April 20, 2015
Tuesday, February 24, 2015
Micro-Controller
Software for Intel 8051 Micro-C programming (MIDE)
Link - http://mide-51.software.informer.com/download/
Please COMMENT if you want any help!!!
Subscribe to:
Comments (Atom)




