DIY Electric Car Forums banner

Arduino Software

7467 Views 13 Replies 8 Participants Last post by  Dave Koller
Anyone familiar with the C like language of arduino? I am currently using it for my microcontroller and could really use some help with the over current protection part of it
Code:
 int potPin = 2;    // select the input pin for the potentiometer
    int ledPin = 11;   // note onlly 5,6, 9,10,11 are PWM
    int wait = 0;     // variable to store the value coming from the sensor


    void setup() {
   //   Serial.begin(9600);
    pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
    }

    void loop() {
    wait = analogRead(potPin) - 28; // read the value from the sensor
    if(wait > 950){
      digitalWrite(ledPin, LOW);
    }else{
       digitalWrite(ledPin, HIGH); // turn the ledPin on
       delayMicroseconds(1023 - wait); // stop the program for some time
       digitalWrite(ledPin, LOW); // turn the ledPin off
       delayMicroseconds( wait); // stop the program for some time
    }
   //   Serial.println( wait );
    }
What I have so far is very rudimentary and I currently have this lem current sensor LEM LF306S LF 306-S 300A. When I put a magnet near it and print out values on a serial print line it read 1023 the maximum for arduino. Anyone on the forum ever work with arduino or know anyone who has written programs for motor controllers with it before?
1 - 1 of 14 Posts
Arduino has pwm libraries. For example the command:

analogWrite(pin, 124);

Would set the pwm value on "pin" to approx 50%. 0 being off and 255 being 100%. Arduino pwm defaults to 500hz which is usless for motor control but can be set to any frequency. I have some code to effect this on my laptop so let me know and i'll post it up.
1 - 1 of 14 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top