Arduino source code for Autoconnection app controller (ford falcon ver)
// Coded by joe jo
//copyright on joe jo.
//copy and paste below codes to arduino
#include <TimerOne.h>
#include <avr/interrupt.h>
String data = "0"; //Variable for storing received data
int analogInput = A0;
float Vout = 0.00;
float Vin = 0.00;
float R1 = 100000.00; // resistance of R1 (100K)
float R2 = 10000.00; // resistance of R2 (10K)
int val = 0;
int doorstatus_pin = 2;
String password = "0000";
int ig_acc = 3;
int ig_on = 4;
int ig_start = 5;
int extra = 6;
int door = 7;
int trunk = 8;
int light = 9;
int igset = 0;
void Wait()
{
uint8_t i=0;
for(;i<23;i++)
_delay_loop_2(0);
}
void callback()
{
val = analogRead(analogInput);//reads the analog input
Vout = (val * 5.00) / 1024.00; // formula for calculating voltage out i.e. V+, here 5.00
Vin = (Vout / (R2/(R1+R2)))+0.27; // formula for calculating voltage in i.e. GND
if (Vin<0.09)//condition
{
Vin=0.00;//statement to quash undesired reading !
}
Serial.print(" ");
Serial.print(Vin);
Serial.println("V");//voltage
Serial.println("\n");
Serial.println("\n");
door_status();
ig_status();
}
void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
//pinMode(2, INPUT); //Sets digital pin 2 as Input pin
pinMode(doorstatus_pin, INPUT_PULLUP); //normally input is pull down status
//attachInterrupt(digitalPinToInterrupt(doorstatus_pin), door_status, CHANGE);
pinMode(analogInput, INPUT); //assigning the input port
pinMode(door, OUTPUT);
pinMode(ig_acc, OUTPUT);
pinMode(ig_on, OUTPUT);
pinMode(ig_start, OUTPUT);
pinMode(trunk, OUTPUT);
pinMode(light, OUTPUT);
pinMode(extra, OUTPUT);
digitalWrite(door, HIGH);
digitalWrite(ig_acc, HIGH);
digitalWrite(ig_on, HIGH);
digitalWrite(ig_start, HIGH);
digitalWrite(trunk, HIGH);
digitalWrite(light, HIGH);
digitalWrite(extra, HIGH);
Timer1.initialize(1000000*3); // initialize timer1, and set a 1/2 second period
//Timer1.pwm(9, 512); // setup pwm on pin 9, 50% duty cycle
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
}
void ig_status()
{
switch (igset){
case (0) : Serial.println(" i0"); break;
case (1) : Serial.println(" i1"); break;
case (2) : Serial.println(" i2"); break;
case (3) : Serial.println(" i3"); break;
}
}
void igup()
{
igset = igset + 1;
if (igset >= 3)
{
igset = 3;
}
igsetup();
}
//we call IG up
void igdown()
{
igset = igset - 1;
if (igset <= 0)
{
igset = 0;
}
igsetup();
}
void igsetup()
{
switch (igset){
case (0) : igoff_f(); break;
case (1) : igacc_f(); break;
case (2) : igon_f(); break;
case (3) : igstart_f(); break;
}
}
void igoff_f()
{igset = 0;
digitalWrite(ig_acc, HIGH);
digitalWrite(ig_on, HIGH);
digitalWrite(ig_start, HIGH);
digitalWrite(13, LOW);
ig_status();
}
void igacc_f()
{
igset = 1;
digitalWrite(ig_acc, LOW);
digitalWrite(ig_on, HIGH);
digitalWrite(ig_start, HIGH);
ig_status();
}
void igon_f()
{
igset = 2;
digitalWrite(ig_acc, LOW);
digitalWrite(ig_on, LOW);
digitalWrite(ig_start, HIGH);
ig_status();
}
void igstart_f()
{
igset = 3;
//noInterrupts();
digitalWrite(ig_acc, LOW);
digitalWrite(ig_on, LOW);
digitalWrite(ig_start, LOW);
ig_status();
delay(1000*3); igon_f();
// interrupts();
}
void door_status()
{
noInterrupts();
// critical, time-sensitive code here
if (digitalRead(doorstatus_pin) == HIGH)
{Serial.println(" dl");}
else
{Serial.println(" du");}//only when grounded
interrupts();
delay(100); //for switching effect
// other code here
}
void autounlock()
{
if (digitalRead(doorstatus_pin) == HIGH)
{Serial.println(" dl");
digitalWrite(door, LOW);
delay(100);
digitalWrite(door, HIGH);
digitalWrite(13, LOW);
}
else
{Serial.println(" du");}//only when grounded
delay(100); //for switching effect
}
void door_f()
{
digitalWrite(door, LOW);
delay(100);
digitalWrite(door, HIGH);
digitalWrite(13, LOW);
}
void light_f()
{
digitalWrite(light, LOW);
delay(100);
digitalWrite(light, HIGH);
digitalWrite(13, LOW);
}
void extra_f()
{
digitalWrite(extra, LOW);
delay(100);
digitalWrite(extra, HIGH);
digitalWrite(13, LOW);
}
void trunk_f()
{
digitalWrite(trunk, LOW);
delay(100);
digitalWrite(trunk, HIGH);
digitalWrite(13, LOW);
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.readString(); //Read the incoming data & store into data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n");
if(data.startsWith(password) && (data.charAt(4) == '%'))// chartAT(start from'0')
{
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
// Serial.println("matched password");
if (data.endsWith("x") && (data.charAt(5) == '1'))
{
if (igset == 0){ autounlock(); Serial.println("autounlock");}
}
if (data.endsWith("x") && (data.charAt(6) == '1'))
{
if (igset == 0){
igset = 3;
igsetup(); Serial.println("autostart");}
}
if (data.endsWith("x") && (data.charAt(7) == '1'))
{
if (igset == 0){ light_f(); Serial.println("autolight"); }
}
if (data.endsWith("door"))
{
door_f();
door_status();
ig_status();
}
else if (data.endsWith("light"))
{
light_f();
}
else if (data.endsWith("extra"))
{
extra_f();
}
else if (data.endsWith("trunk"))
{
trunk_f();
}
else if (data.endsWith("status"))
{
door_status();
ig_status();
}
else if (data.endsWith("igup"))
{
igup();
}
else if (data.endsWith("igdown"))
{
igdown();
}
}
else if(data.startsWith(password) && (data.charAt(4) == '$'))
{
Serial.println(" sa");
password[0] = data.charAt(5);
password[1] = data.charAt(6);
password[2] = data.charAt(7);
password[3] = data.charAt(8);
}
else
{
Serial.println(" wr");//wrong password
digitalWrite(13, LOW);
}
}
}
Subscribe to:
Posts (Atom)
constraint layout learning
constraint layout learning is fun but sadly I couldn't find the way to fitting layouts to any size of mobile screen. it is easy to org...
-
Arduino source code for Autoconnection app controller (ford falcon ver) // Coded by joe jo //copyright on joe jo. //copy and paste below...
-
please test relay module before installation. Immobilizer need key to start engine. not ...
-
Sometimes, I am still confusing to wire up such as LED light with dimmer functions with using PWM module. MAYBE ONLY ME. ANYWAY PWM MODULE h...