Advertisement
stspringer

Remote Car Starter Using Bluetooth

Mar 25th, 2023 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. /* Program: Remote Car Start AutoDesk Instructables
  2. * Remote Car Starter Using Bluetooth AutoDesk Instructables https://www.instructables.com/Remote-Car-Starter-using-Bluetooth/
  3. * uses delay will change to millis
  4. * Author: Chris Johnson
  5. * Revised: December 5th, 2011
  6. *
  7. * Inputs: BT Module "ON" signal
  8. * BT Module "OFF" signal
  9. * Vehicle RPM Sensor
  10. * Vehicle Neutral Position Sensor
  11. * Vehicle Speed Sensor
  12. * Serial port
  13. * Outputs: Ignition Control Relay
  14. * Accessory Control Relay
  15. * Starter Control Relay
  16. * Clutch Safety Switch Relay
  17. * Serial Port
  18. */
  19.  
  20.  
  21. //EQUATES
  22. //Inputs
  23. int BT_on = 2; //Bluetooth "ON" signal inputed to pin 2
  24. int RPM_sens = 3; //Vehicle RPM sensor inputted to pin 3
  25. int neutral_sens = 4; //Vehicle Neutral Position Sensor inputted to pin 4 (12 volts +/- 0.5 volts)
  26. int speed_sens = 5; //Vehicle Speed Sesor inputted to pin 5
  27. int BT_off = 7; //Bluetooth "OFF" signal inputed on pin 7
  28.  
  29. //Outputs
  30. int ign_ctrl = 8; //Ignition Control Relay controlled by pin 8
  31. int start_ctrl = 9; //Start Control Relay controlled by pin 9
  32. int clutch_sfty = 10; //Clutch Safety Swithc Relay controlled by pin 10
  33. int acc_ctrl = 11; //Accessory Control Relay controlled by pin 11
  34.  
  35. unsigned long start_time; //Variable used to store the time at which the starter is engaged
  36.  
  37. char data = 0; //Variable used to store data received via the serial port
  38.  
  39. //DEFINITIONS
  40. void setup()
  41. {
  42. pinMode(BT_on, INPUT); //Define pin inputs and outputs
  43. pinMode(RPM_sens, INPUT);
  44. pinMode(neutral_sens, INPUT);
  45. pinMode(speed_sens, INPUT);
  46. pinMode(BT_off, INPUT);
  47.  
  48. pinMode(ign_ctrl, OUTPUT);
  49. pinMode(start_ctrl, OUTPUT);
  50. pinMode(clutch_sfty, OUTPUT);
  51. pinMode(acc_ctrl, OUTPUT);
  52.  
  53. Serial.begin(9600); //Initialize the serial port with a baud rate of 9600
  54. }
  55.  
  56. //PROGRAM
  57.  
  58. //Loop function: Wait for a START command to be received (command via serial port or
  59. //voltage applied to BT_on pin)
  60. void loop()
  61. {
  62. if (Serial.available() > 0) //Check if any serial data is available
  63. {
  64. data = Serial.read(); //Set "data" variable to currently available serial data
  65. check(); //Go to "check" funtion if serial data is available
  66. }
  67. else if (digitalRead(BT_on) == HIGH) //Check if BT Module has set pin high
  68. {
  69. begin(); //Begin start sequence if pin is high
  70. }
  71. else
  72. {
  73. loop(); //Repeat this function until a START command is received
  74. }
  75. }
  76.  
  77. //Check function: Test for proper character set from BT
  78. void check()
  79. {
  80. if (data == 's') //Check if an "s" has been sent
  81. {
  82. begin(); //Begin start sequence if "s" has been sent
  83. }
  84. else
  85. {
  86. Serial.println("Invalid Command"); //If anything other than an "s" has been sent, send "Invalid Command" error message
  87. loop(); //Return to beginning of program
  88. }
  89. }
  90.  
  91. //Begin function: Turn on accessory and ignition
  92. void begin()
  93. {
  94. delay(500); // 0.5 second delay
  95. digitalWrite(acc_ctrl, HIGH); //Turn accessory ON
  96. digitalWrite(ign_ctrl, HIGH); //Turn ignition ON
  97. delay(500); // 0.5 second delay
  98. neutral(); //Go to "neutral" funciton
  99. }
  100.  
  101. //Neutral function: Check if the vehicle's transmission is in the neutral position.
  102. // Continue if vehicle is in neutral. Exit start sequence if vehicle is in gear.
  103. void neutral()
  104. {
  105. if (digitalRead(neutral_sens) == HIGH ) //Continue only if vehicle is in neutral
  106. {
  107. start(); //Start vehicle if in neutral
  108. }
  109. else
  110. {
  111. Serial.println("Vehicle Not in Neutral"); //If in gear, send "Vehicle Not in Neutral" error message
  112. vehicle_off(); //Exit start sequence if in gear
  113. }
  114. }
  115.  
  116. //Start function: Engage starter only if engine is not already running.
  117. void start()
  118. {
  119. int RPM = pulseIn(RPM_sens, HIGH, 1000000); //Get RPM value
  120. if(RPM == 0) //Continue start sequence only if vehicle is not running.
  121. {
  122. digitalWrite(clutch_sfty, HIGH); //"Depress" clutch
  123. digitalWrite(acc_ctrl, LOW); //Turn accessory OFF
  124. delay(500); //0.5 second delay
  125. digitalWrite(start_ctrl, HIGH); //Engage starter
  126. start_time = millis(); //Capture the time at which the starter was engaged
  127. starter_engaged(); //Go to Starter_engaged function
  128. }
  129. else
  130. {
  131. Serial.println("Vehicle Already Running"); //Send "Vehicle Already Running" message if engine was previously started
  132. vehicle_off(); //Exit start sequence if already running
  133. }
  134. }
  135.  
  136. //Starter_engaged function: Disengage starter after vehicle is starter or turn off starter if
  137. //vehicle has not started within 4 seconds.
  138. void starter_engaged()
  139. {
  140. int RPM = pulseIn(RPM_sens, HIGH); //Get RPM value
  141. if (RPM > 1000) //Continue if engine has started (reached low idle)
  142. {
  143. Serial.println("Engine Running"); //Send "Engine Running" message after engine has started
  144. disengage_starter(); //Go to disengage_starter after engine is running
  145. }
  146. else if ((start_time+4000) < millis()) //Test if 4 seconds has passed since the starter was engaged
  147. {
  148.  
  149. disengage_starter_timeout(); //Go to disengage_starter if engine has not started within 4 seconds of starter engagement
  150. }
  151. else
  152. {
  153. starter_engaged(); //Repeat this function if engine has not started or 4 seconds has not elapsed
  154. }
  155. }
  156.  
  157. //Disengage_starter function: Disengage the starter.
  158. void disengage_starter()
  159. {
  160. digitalWrite(start_ctrl, LOW); //Disengage the starter
  161. digitalWrite(clutch_sfty, LOW); //"Release" the clutch
  162. digitalWrite(acc_ctrl, HIGH); //Turn accessory ON
  163. vehicle_off_sense(); //Go to vehicle_off_sense function
  164. }
  165.  
  166. //Disengage_starter_timeout function: Disengage the starter (used after 4 seconds has elapsed without an engine start)
  167. void disengage_starter_timeout()
  168. {
  169. digitalWrite(start_ctrl, LOW); //Disengage the starter
  170. digitalWrite(clutch_sfty, LOW); //"Release" the clutch
  171. Serial.println("Vehicle Start Unsuccessful"); //Send "Vehicle Start Unsuccessful"
  172. vehicle_off(); //Exit start sequence
  173. }
  174.  
  175. //Vehicle_off_sense function: Waits for an "off" signal to be sent while the engine is running.
  176. //If no "off" signal is received, turns off the vehicle after 30 minutes has elapsed since the engine start.
  177. void vehicle_off_sense()
  178. {
  179. int moving = pulseIn(speed_sens, HIGH); //Get vehicle speed
  180. if (moving > 1000) //Check if vehicle is moving
  181. {
  182. Serial.println("Vehicle OFF -- Movement"); //Send "Vehicle OFF -- Movement" message ifvehcile is moving
  183. vehicle_off(); //Turn vehicle off if it is moving
  184. }
  185. else if (start_time+1800000 < millis()) //Check if 30 minutes has elapsed since engine start
  186. {
  187. Serial.println("Vehicle OFF -- Automatic Timeout"); //Send "Vehicle OFF -- Automatic Timeout" message if engine has been
  188. //running for 30 minutes
  189. vehicle_off(); //Turn vehicle off if engine is running for 30 minutes
  190. }
  191. else if (Serial.available() > 0) //Check if a signal has been sent via serial data
  192. {
  193. data = Serial.read(); //Store serial sent serial data
  194. if (data == 'o') //Check if signal sent is an OFF command ("o")
  195. {
  196. Serial.println("Vehicle OFF -- User Commanded"); //Send "Vehicle OFF -- User Commanded" message if serial data is the OFF
  197. //command ("o")
  198. vehicle_off(); //Turn vehicle off if OFF command is sent via serial data
  199. }
  200. }
  201. else if (digitalRead(BT_off) == HIGH) //Check if OFF command has been sent via BT module
  202. {
  203. Serial.println("Vehicle OFF -- User Commanded"); //Send "Vehicle OFF -- User Commanded" message if OFF
  204. //command was sent
  205. vehicle_off(); //Turn vehicle off if OFF command was sent via BT module
  206. }
  207. else
  208. {
  209. vehicle_off_sense(); //Repeat this function if none of the above conditions have been met
  210. }
  211. }
  212.  
  213. //Vehicle_off function: Turns the vechile off and starts the whole program over
  214. void vehicle_off()
  215. {
  216. digitalWrite(ign_ctrl, LOW); //Turn ignition OFF
  217. digitalWrite(acc_ctrl, LOW); //Turn accessory OFF
  218. loop(); //Repeat program (look for start command)
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement