Go Down

Topic: Motorbike 12V feeds to iPhone app (Read 661 times) previous topic - next topic

PeterH


Hi. I took an old car mobile phone charger apart. And used this to supply a clean 5 volts to the arduino and the blutooth module.


Is this actually supplying a smooth constant 5V to the Arduino? Batteries don't mind whether the supply is exactly the right voltage or completely smooth, but Arduinos do.
I only provide help via the forum - please do not contact me for private consultancy.

spriggsy

Thinking about it maybe the 5v supply isnt 100%, this is the sort of device that im currently using.



and here is my code

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(2, 3); // RX, TX

String incomingString;
int relay1 = 4;
//relay2 = 5;

int ledState = LOW;

int alarmLed =  8;      // the number of the LED pin
int lowBeam = 9;
int highBeam = 10;
int right = 11;
int left = 12;
int neutral = 13;

int running = 0;

long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

int buttonState = 0;          // current state of the button being checked

int lastLState = 0;             // previous state of the button
int lastRState = 0;             // previous state of the button
int lastlowBeamState = 0;       // previous state of the button
int lasthighBeamState = 0;       // previous state of the button
int lastneutralState  = 0;
boolean alarm = true;


void setup() {
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, HIGH); 
  pinMode(alarmLed, OUTPUT);     
  pinMode(right, INPUT);
  pinMode(left, INPUT);
  pinMode(lowBeam, INPUT);
  pinMode(highBeam, INPUT);
  pinMode(neutral, INPUT);
  Serial.begin(9600);
  Bluetooth.begin(9600);
}


void loop() {
  // Check if there's incoming serial data.
  buttonState = digitalRead(right);
  if (buttonState != lastRState) {
    if (buttonState == HIGH) {
      Bluetooth.println("R ON");
    }
    else {
      Bluetooth.println("R OFF");
    }
  }
  lastRState = buttonState;

  buttonState = digitalRead(left);
  if (buttonState != lastLState) {
    if (buttonState == HIGH) {
      Bluetooth.println("L ON");
    }
    else {
      Bluetooth.println("L OFF");
    }
  }
  lastLState = buttonState;


  buttonState = digitalRead(lowBeam);
  if (buttonState != lastlowBeamState) {
    if (buttonState == HIGH) {
      Bluetooth.println("LOW ON");
    }
    else {
      Bluetooth.println("LOW OFF");
    }
  }
  lastlowBeamState = buttonState;

  buttonState = digitalRead(highBeam);
  if (buttonState != lasthighBeamState) {
    if (buttonState == HIGH) {
      Bluetooth.println("HIGH ON");
    }
    else {
      Bluetooth.println("HIGH OFF");
    }
  }
  lasthighBeamState = buttonState;

  buttonState = digitalRead(neutral);
  if (buttonState != lastneutralState) {
    if (buttonState == HIGH) {
      Bluetooth.println("N ON");
    }
    else {
      Bluetooth.println("N OFF");
    }
  }
  lastneutralState = buttonState;

  if (Bluetooth.available() > 0) {
    delay(10);
    char  inchar;   
    String text = "";
    while (Bluetooth.available()){
      inchar = Bluetooth.read();
      text = text + inchar;
    }
    text.toUpperCase();
    text.trim();
    Serial.println(text);
    if (text == "IGN ON") {
      digitalWrite(relay1, LOW);
      alarm = false;
    }
    if (text == "IGN OFF") {
      digitalWrite(relay1, HIGH); 
      alarm = true;
    }
  }


  unsigned long currentMillis = millis();
  // the following code gets called after every delay.
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   
    if (alarm)
    {
      // if the LED is off turn it on and vice-versa:
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
      // set the LED with the ledState of the variable:
      digitalWrite(alarmLed, ledState);
    }
    else
    {
      digitalWrite(alarmLed,LOW);
    }
  }
}





this is all working fine if im not reading any of the 12volt feeds from the bike. i was riding the bike earlier on today ith no probs and no resetting.

spriggsy

I think i may have narrowed it down to the Bluetooth.print command.

if i don't send many messages at a time it runs fine. when constantly sending it crashes the chip.  although it runs fine if powered from USB,

anyone else ever run into anything like this or have any suggestions?

Go Up