E46 BMW Social Directory E46 FAQ 3-Series Discussion Forums BMW Photo Gallery BMW 3-Series Technical Information E46 Fanatics - The Ultimate BMW Resource BMW Vendors General E46 Forum The Tire Rack's Tire Wheel Forum Forced Induction Forum The Off-Topic The E46 BMW Showroom For Sale, For Trade or Wanting to Buy

Welcome to the E46Fanatics forums. E46Fanatics is the premiere website for BMW 3 series owners around the world with interactive forums, a geographical enthusiast directory, photo galleries, and technical information for BMW enthusiasts.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   E46Fanatics > Tuning & Tech > DIY: Do It Yourself

DIY: Do It Yourself
Post here to share or improve your wrench turning skills! All BMW E46 DIY tips, tales, and projects discussed inside. Learn to work on your car and know the right BMW parts you will need!

Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 06-19-2014, 01:13 AM   #1
SuperSleeper
Registered User
 
Join Date: Jul 2006
Location: California
Posts: 416
My Ride: 2003 330CIC
Arduino based automatic convertible top control

Hi Folks,

My Key died, and rather than spend countless amounts of money and time, I decided to take matters into my own hands and use third-party means to resolve the issue by installing this fairly decent (and cheap) keyless entry system:


http://www.amazon.com/gp/product/B00...?ie=UTF8&psc=1

I found this system to be well constructed and reliable, although it's range could be better.

Second, I used an Arduino Leonardo, and paired it with this relay module:


http://www.amazon.com/gp/product/B00...?ie=UTF8&psc=1

All in all, I get excellent and consistent results each time. I've done extensive testing with my car and successfully open and close the top each third key press. Below is the modified code taken from open source community. Feel free to use it and do with it what you may. I won't be responsible for any adverse effects and or damages to car or bodily injury. So you will take matters into your own hands:

Quote:
/*
Base code by: Tom Igoe
Modified by: Eric Geer
Version: 1.2
Date: 6/12/2014
Function: Read state of door lock mechanism and hold state open after third press
Purpose: Automatic open and close of BMW E46 Convertible top mechanism.
Code is designed to work with input detected from third party keyless entry system:
http://www.amazon.com/gp/product/B00...?ie=UTF8&psc=1
Arduino reads the lock/unlock mechanism and passes state through to vehicle on pins 11 and 12 via relay board:
http://www.amazon.com/gp/product/B00...?ie=UTF8&psc=1
After third press of the lock or unlock buttons within 5 seconds time, a hold timer engages with sufficient time to fully close
or open the convertible top. Code can easily be modified for purposes of controlling coupe or 4-door to close all windows and
sunroof.
This
Based off "State change detection (edge detection)" by Tom Igoe
http://arduino*****en/Tutorial/ButtonStateChange

*/

// this constant won't change:
const int lockbuttonPin = 2;
const int unlockbuttonPin = 3;
const int lockledPin = 12;
const int unlockledPin = 11;
const int TimeoutPeriod = 50;
// Variables will change:
int lockCounter = 0;
int lockButtonState = 0;
int lastLockButtonState = 0;
int unlockCounter = 0;
int unlockButtonState = 0;
int lastunLockButtonState = 0;
int timeout = 0;
void setup() {
pinMode(lockbuttonPin, INPUT);
pinMode(lockledPin, OUTPUT);
pinMode(unlockbuttonPin, INPUT);
pinMode(unlockledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
lockButtonState = digitalRead(lockbuttonPin);
unlockButtonState = digitalRead(unlockbuttonPin);
delay(100);
timeout++;
if (timeout > TimeoutPeriod) {
timeout=0;
if (lockButtonState == lastLockButtonState) {
lockCounter=0;
Serial.print("Timeout reset lock counter: ");
Serial.println(lockCounter);
}
if (unlockButtonState == lastunLockButtonState) {
unlockCounter=0;
Serial.print("Timeout reset unlock counter: ");
Serial.println(unlockCounter);
}
}

if (lockButtonState != lastLockButtonState) {
timeout=0;
if (lockButtonState == HIGH) {
digitalWrite(lockledPin, HIGH);
delay(100);
digitalWrite(lockledPin, LOW);
lockCounter++;
Serial.println("Lock Relay ON");
Serial.print("Lock pushes: ");
Serial.println(lockCounter);
timeout=0;
}
else {
Serial.println("Lock Relay OFF");
}
}
if (unlockButtonState != lastunLockButtonState) {
if (unlockButtonState == HIGH) {
digitalWrite(unlockledPin, HIGH);
delay(100);
digitalWrite(unlockledPin, LOW);
unlockCounter++;
Serial.println("Unlock Relay ON");
Serial.print("Unlock pushes: ");
Serial.println(unlockCounter);
timeout=0;
}
else {
Serial.println("Unlock Relay OFF");
}
}
lastLockButtonState = lockButtonState;
lastunLockButtonState = unlockButtonState;

if (lockCounter % 4 == 3) {
lockCounter=0;
digitalWrite(lockledPin, HIGH);
delay(34000);
}
digitalWrite(lockledPin, LOW);

if (unlockCounter % 4 == 3) {
unlockCounter=0;
digitalWrite(unlockledPin, HIGH);
delay(25000);
}
digitalWrite(unlockledPin, LOW);
}
__________________
SuperSleeper
SuperSleeper is offline   Reply With Quote
Ads by Google

Guests, get your FREE E46Fanatics.com membership to remove this ad.
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Censor is ON





All times are GMT -5. The time now is 08:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
(c) 1999 - 2011 performanceIX Inc - privacy policy - terms of use