DIY Electric Car Forums banner

Arduino Software

7463 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 - 4 of 14 Posts
This is just the PWM code I am not using the LEM Sensor at all here
If so, you need to calibrate it at first, by reading the input while there is no current and then use that value where you have ( -28 ) now.
From what I can tell on the print line the LEM is linear. The -28 is for the calibration of the pot.
Are you trying to actually create PWM square wave with variable on/off times?
Why wouldn't I need to create PWM on off times is it because somewhere in there library they have this code or something like it written because if they do I have looked all through it and didn't see anything like this to control a motor which is odd because every other micro controller that uses basic already has a library with a code for pwm for a motor :confused:

My thoughts are that I am going to have to hook up the lem sensor and just run the car up to about 100 amps on jack stands see what measurements I get when I reach 100 amps. Let's say its a digital value of 150 on the print line that means if I were consuming 500 amps then the digital value would be 750. So if I wanted to limit to 500 then I would decrease the PWM High every time the sensor read that value just a little enough to keep me under 500 amps. I wonder how to know just how much to decrease the throttle so that it limits it just the right amount? and if I do so will there be any herky jerkiness of the throttle. Under normal driving the car barely ever reached 250 amps but the initial amperage is much higher maybe I just need some soft start code for when I just take off. I have a few of ideas I just don't know how to put them into the code.
See less See more
Or maybe if it says that 500 amps is the max that this lem sensor will read then I won't have to put it up on jack stands because 500=1023.:eek:
By all means post up the code and 500 hertz must be what I am running at during my short trips down the street:( and if you could post a link to their motor control library I couldn't find it anywhere.:confused:
1 - 4 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