zoukankan      html  css  js  c++  java
  • Arduino 各种模块篇 震动模块 vibrator module

    The vibrator I got works at the voltage ranging from 3.3V ~ 5.5V

    Gvib.jpg

    I want to make it vibrate variably.

    So I planned to test in 2 different ways.

    1) analog valtage supply

    2) PWM full valtage supply

    Here's the test situations and codes

    1) analog valtage supply

    int vibratorPin=A1; // vibrator on A1
    int i=0;
    void setup()
    {
      Serial.begin(9600);
      //pinMode(vibratorPin,OUTPUT);
      pinMode(10,OUTPUT); // Full valtage Pin
      digitalWrite(10,HIGH);
    }
    void loop()
    {
      for(i=0; i < 256; i=i+1)
      //Acutally the vibrator works from on i = 130
      //analog doesn't work so ideally
      {
        analogWrite(vibratorPin,i); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
        Serial.print("vibration value");
        Serial.print("	");
        Serial.println(i);
        delay(50);
      }
      i=0;
    }

    --analysis : only when "i" goes up more than 130 , the vibrator begins to work.

    Also not very different from if just give it full voltage supply. ( digital Pin 10 as a control experiment here )

    2) PWM full voltage supply

    int vibratorPin=9; // vibrator on Pin 9
    int i=0;
    void setup()
    {
      Serial.begin(9600);
      pinMode(vibratorPin,OUTPUT);
      pinMode(10,OUTPUT); // Full valtage Pin
      digitalWrite(10,HIGH);
    }
    void loop()
    {
      for(i=0; i < 256; i++)
      //Acutally the vibrator works from on i = 130
      //analog doesn't work so ideally
      {
        digitalWrite(vibratorPin,i); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
        Serial.print("vibration value");
        Serial.print("	");
        Serial.println(i);
        delay(50);
      }
      i=0;
    }

    --effect analysis:

    Initially when variable "i" ranges from 0 to 100, I can feel the module vibrates dynamically clearly. But after "i" goes up to more than 100, I feel it all the same, which means "100" is no different from "200" for this instance.

    So I re-code it.

    int vibratorPin=9; // vibrator on Pin 9
    int i=0;
    void setup()
    {
      Serial.begin(9600);
      pinMode(vibratorPin,OUTPUT);
      pinMode(10,OUTPUT); // Full valtage Pin
      digitalWrite(10,HIGH);
    }
    void loop()
    {
      for(i=0; i < 5; i=i+1) // Here is the part i changed , but still not different from previous one
      //Acutally the vibrator works from on i = 130
      //analog doesn't work so ideally
      {
        digitalWrite(vibratorPin,i); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
        Serial.print("vibration value");
        Serial.print("	");
        Serial.println(i);
        delay(500);
      }
      i=0;
    }

    #############

    Summery:

    Above all, so for  this vibrator module, please don't think to use it like a vibrator variably.

    Buy a digital one! Haha! Gonna get one!

  • 相关阅读:
    Codeforces 1316B String Modification
    Codeforces 1305C Kuroni and Impossible Calculation
    Codeforces 1305B Kuroni and Simple Strings
    Codeforces 1321D Navigation System
    Codeforces 1321C Remove Adjacent
    Codeforces 1321B Journey Planning
    Operating systems Chapter 6
    Operating systems Chapter 5
    Abandoned country HDU
    Computer HDU
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3425670.html
Copyright © 2011-2022 走看看