Wind tunnel Stabilization Ball System (ii)-----PID Distance PWM control based on Arduino implementation

Source: Internet
Author: User

The Arduino is really good,

Already addicted.

This is a wind tunnel stabilized pellet system.

First, the component module

Arduino Front

Arduino PIN Wiring

The drive board, it's Freescale's little broken car.

Power.

Wind tunnel

Fan model

Second, the Arduino code

It's a code of words.

#include <PID_v1.h>intinputpin=4;//define ultrasonic signal receiver pin ECHO to D4      intoutputpin=5;//define ultrasonic signal transmitter pin TRIG to D5      intPWM =6;//PWM output D6      intdis=0; Doublesetpoint, Input, Output; PID Mypid (&input, &output, &setpoint,0.7,5.3,0.8, DIRECT); voidSetup () {Serial.begin (9600);        Pinmode (Inputpin, INPUT);        Pinmode (Outputpin, OUTPUT);        Pinmode (PWM, OUTPUT); SetPoint= the; Input= Max;       Mypid.setmode (AUTOMATIC); }            voidloop () {Dis=Distancem (); Input=255-map (DIS,0, $, -, $);        Mypid.compute ();        Analogwrite (PWM, Output); Serial.print ("  ");        Serial.print (Input); Serial.print ("  ");      Serial.println (Output); }     intDistancem () {Digitalwrite (Outputpin, low); Delaymicroseconds (2); Digitalwrite (Outputpin, high); //Pulse for 10μs to trigger ultrasonic detectionDelaymicroseconds (Ten);          Digitalwrite (Outputpin, low); intDistance = Pulsein (Inputpin, high);//Read receiver Pulse timeDistance= distance/ -;//Transform Pulse time to distanceSerial.print (distance);//Ourput DistanceDelay -); returndistance; }

I've said it before.

I'll send it again.

Sensor SRF05 Ultrasonic

VCC------------5V

GND------------GND

PIN ECHO-----D4
PIN TRIG-----D5

A self-brought library is used in the code Pid_v1.h

Mypid (&input, &output, &setpoint,0.7,5.3,0.8, DIRECT);

Input, output, stable convergent position point, KP,KI,KD, direct way.

Input=255-map (dis,0,45,20,200);

Here is a mapping because my sensors are on the upper end of the wind tunnel.

The closer the top is to the lower the value, so you need to change the symbol.

Make it proportional to the value and height.

The PWM is exactly 0-255, so change the value.

The output pin of the PWM is D6,

The frequency is 1kHz, although the frequency is low but enough.

Three, parameter debugging

Next use the serial data to see

Distance, Input,output, respectively.

I took the data down to plot with Matlab.

Red stands for height, or is relatively stable.

Yellow is the value of PWM.

Because the previous test sensor is very stable,

So the data input I did not use the Kalman filter to deal with.

A knife was cut by the fan,

All in all, no rotten tail, hooray!

Wind tunnel Stabilization Ball System (ii)-----PID Distance PWM control based on Arduino implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.