Announcement

Collapse
No announcement yet.

Arduino Mini MDee

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Arduino Mini MDee

    arduino_mdee.zip

    Code:
    #include <LiquidCrystal.h>
    
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    int Coil =  13;      // the number of the Coil pin
    int led = 10;        // detection led can add a buzzer here
    int analogPin = 0;   // pin to read the samples
    int cSamples = 30;  // how much samples are taken
    int SampleDelay = 0;  // delay before gathering the samples ajustable via the buttons
    int SampleCounter = 0;
    int tempc = 0;
    int Sensor = 5;  // default sensor offset ajustable via buttons
    int testresults = 0;
    int cal = 0;  // store the calibration setting
    float val = 0.0f;
    float readSamples = 0.0f;
    float results = 0.0f;
    bool calibrate = false;
    
    int button_up_Sensor = 7;
    int button_down_Sensor = 6;
    int button_up_SampleDelay = 9;
    int button_down_SampleDelay = 8;
    
    void setup ()
    {
      lcd.begin(16, 2);
      pinMode(Coil, OUTPUT);
      pinMode(led, OUTPUT);
      pinMode (A0, INPUT);
      Serial.begin (115200);
    }
    
    void loop ()
    {
      
      digitalWrite(Coil, HIGH);
      delayMicroseconds(50); // how long the gate is open to charge the coil
      digitalWrite(Coil, LOW);
      delayMicroseconds(SampleDelay);
      for(int i = 0; i < cSamples; i++)
      {
        val = analogRead(analogPin);
        readSamples+=val;
        val = 0.0f;
      }
      
      results = (readSamples/cSamples);
      
      if(results < 0.0f)
      {
        results = fabsf(results); // if the results are - flip them to +
      }
    
      if(SampleCounter <= cSamples)
      {
        tempc += (int)results; // recast to a int easy to deal with the display
        SampleCounter++;
      }else
      {
        if(calibrate == false)
        {
          cal = tempc/cSamples;
          calibrate = true;
          lcd.setCursor(0, 1);
          lcd.print("       ");
          lcd.setCursor(0, 1);
          lcd.print("Cal ");
          lcd.print(cal);
        }
        testresults = tempc/cSamples;
        lcd.setCursor(0, 0);
        lcd.print("       ");
        lcd.setCursor(0, 0);
        lcd.print("DP ");
        lcd.print(testresults);
        digitalWrite(led, LOW);
        if(cal > (testresults + Sensor) || cal < (testresults - Sensor)) digitalWrite(led, HIGH);
        tempc = 0;
        SampleCounter = 0;
      }
      
      
      readSamples = 0.0f;
    
      if(digitalRead(button_up_Sensor) == HIGH)
      {
        Sensor++;
        lcd.setCursor(8, 0);
        lcd.print("         ");
        lcd.setCursor(8, 0);
        lcd.print("SN ");
        lcd.print(Sensor);
        digitalWrite(Coil, LOW);
        delay(200);
      }
    
      if(digitalRead(button_down_Sensor) == HIGH)
      {
        Sensor--;
        lcd.setCursor(8, 0);
        lcd.print("         ");
        lcd.setCursor(8, 0);
        lcd.print("SN ");
        lcd.print(Sensor);
        digitalWrite(Coil, LOW);
        delay(200);
      }
    
      if(digitalRead(button_up_SampleDelay) == HIGH)
      {
        SampleDelay++;
        lcd.setCursor(8, 1);
        lcd.print("         ");
        lcd.setCursor(8, 1);
        lcd.print("SamD ");
        lcd.print(SampleDelay);
        digitalWrite(Coil, LOW);
        calibrate = false;
        delay(100);
      }
    
      if(digitalRead(button_down_SampleDelay) == HIGH)
      {
        SampleDelay--;
        if(SampleDelay < 0)SampleDelay = 0;
        lcd.setCursor(8, 1);
        lcd.print("         ");
        lcd.setCursor(8, 1);
        lcd.print("SamD ");
        lcd.print(SampleDelay);
        digitalWrite(Coil, LOW);
        calibrate = false;
        delay(100);
      }
    }
    this is what i have been working on so far it works quite well, im looking for some help in improving it i have had no luck in trying to add a pizo buzzer the EM off it just disrupts the sensitivity
    the buttons are just 5v supply with 10k resistor to ground
    when calibrating just use the delay, if its not calibrated right the numbers up and down wont match just switch it up and down again
    then adjust the sensitivity the lower the more sensitive it will get (SN)
    adjusting the delay is like what it says it will wait a few microseconds before sampling well as long as what you set it for basicly find the sweet spot lol
    i tryed a few things on the site but none seemed to work so i had to try my self, its easy to build and uses minimal components and should be easy to use other OP amps

  • #2
    Most Cool. What did you use as a coil ? What LCD did you use? I have a few. I'll play with this for sure. Thank You !

    HF

    Click image for larger version

Name:	ArduinoMDee.PNG
Views:	1
Size:	93.0 KB
ID:	348181

    Comment


    • #3
      it was just a 1602 16x2 but any will do, as for the coil im undecided i used a 350mh but i think any coil will work, damping i don't think it critical lol i removed it and it still works if not better
      it needs some research into it what would be the best setup that's why im posting it
      i use a nano and a mega both work fine
      you can probably build it without a display i don't see why not just add a pin to flash a led on button pushes
      as for a buzzer hmmm its that sensitive the EM off it disrupts the field when you test it you will see what i mean
      but i have done as much as i can i need new input on it but it makes a good detector

      Comment


      • #4
        Being New at this Arduino thing I don't understand how your getting the inputs from the two buttons ? What pins ?

        HF

        Comment


        • #5
          I assume i am overlooking something, but how do you get a stable pulse rate ?
          The pulse width is 50 microseconds, but is the loop time dependent on which button is pushed : delay(200) / delay(100) milliseconds I assume ?
          So, if you push all buttons at the same time, the loop delay will be larger than when you push only one button ?
          If pushing multiple buttons at once is not a use case, I would put the button sampling in a do - while loop and break when a single button is pushed and handled.
          What is the time between 2 pulses now, when no buttons are pushed ?

          Nice work, btw

          Comment


          • #6
            its using 4 buttons on 6 7 8 9 inputs all high on the 5v line when the button is pushed its sent to ground via a 10k resistor
            https://www.arduino.cc/en/tutorial/button
            the delay basicly waits before sampling setting it to 0 will sample just as the fet drops and take 30 samples, if set the delay to 100 micro seconds that's how long before taking 30 samples
            the time between pulse and sampling is 4ms but can be extended with changing cSamples say to 50 but i find 30 is perfect its just at the point it has reached 0

            Comment


            • #7
              This is Declaring the Analog Pins Inputs ?


              int button_up_Sensor = 7;
              int button_down_Sensor = 6;
              int button_up_SampleDelay = 9;
              int button_down_SampleDelay = 8;


              ???

              Comment


              • #8
                no digital sorry for the confusion they are low via a 10k resistor when you push the button it puts the pin to 5v i seen what i typed lol just use the setup i posted
                https://www.arduino.cc/en/Tutorial/HelloWorld

                Comment


                • #9
                  Got it . Thank You.

                  Comment


                  • #10
                    You can use timer and PWM pin to generate pulse without messing with loop.
                    This is just an example:


                    Code:
                    #include "TimerOne.h"
                    void setup()
                    {
                      Timer1.initialize(1666); // 600Hz
                      Timer1.pwm( 9, 256); // pin 9, 25% duty cycle
                      Timer1.pwm(10, 512); // pin 9, 50% duty cycle
                    }
                    void loop()
                    {
                    
                    }

                    Comment


                    • #11
                      the timer needs to be part of the loop for the readings to be accurate they must sync but i must try that to see the results

                      Comment


                      • #12
                        Do you have the PCB with just the Tracks I can burn a board with ?

                        Comment


                        • #13
                          i used a bread board then strip board i was thinking of building a cnc since i have a few arduinos lol, think that might be my next project

                          Comment


                          • #14
                            for all who dont have full Version of Sprint Layout, please upload pdf with black pcb tracks as pdf

                            Comment


                            • #15
                              arduino_mdee_final.zip
                              ok got the hardware stable time to work on the software all seems to work stable i will update the software soon

                              Comment

                              Working...