Announcement

Collapse
No announcement yet.

Rotaty Angle Sensor - How to Use Rotaty Angle Sensor

Collapse
X
Collapse
  •  

  • Rotary Angle Sensor - How to Use Rotary Angle Sensor


    Tutorial Video



    Hardware

    About Rotaty Angle Sensor

    Rotaty angle sensor (also called potentiometer) is used to linearly adjust/change something in value. The rotaty angle sensor used in this example includes three pins:
    • VCC pin.
    • GND pin.
    • Signal pin ( produces analog output between 0 and VCC).
    How the rotaty angle sensor works:
    • The sensor outputs analog signal to signal pin. The signal value is in direct proportion to the rotated angle.
    How to use rotaty angle sensor:
    • By reading value of sensor's signal pin, we can infer the rotated angle or how many percent something should be addjusted/changed. To read value of sensor's signal pin, we just need to connect the sensor's signal pin to PHPoC device's ADC (Analog to Digital Converter) pin and use PHPoC code to read the value.
    We can use another kind of rotaty angle sensor instead, even if it has different pinout, for example:We can use the source code of this example if its working principle is the same as the rotaty angle sensor used in this example.

    Wiring Diagram



    Quick Steps

    Source code of this example is a part of PHPoC Support Packet (PSP). You need to:
    • Download PHPoC Support Package.
    • Upload example\p4s\01.php_task\02.adc_rotary_angle to PHPoC Blue/Black.
    • Click "Run" button on PHPoC Debugger.
    If you use PHPoC for the first time, see How To Use PSP.


    Source Code

    Source files includes:
    • init.php: this file is run when PHPoC system is powered or reset. It is used to specify which file is run is system loop.
    • task0.php: this file is run in system loop of PHPoC devices.

    init.php

    This file is run when PHPoC system is powered or reset. It is used to specify that task0.php is run is system loop.
    PHP Code:
    <?php

    system
    ("php task0.php");

    ?>



    task0.php

    [Full Code]
    PHP Code:
    <?php

    if(_SERVER("REQUEST_METHOD"))
     exit; 
    // avoid php execution via http request

    include "/lib/sd_340.php";

    echo 
    "PHPoC example : P4S-34X / ADC / Catalex Rotary Angle Sensor\r\n";

    adc_setup(00); // adc0, channel 0

    $last_adc_in 0;

    while(
    1)
    {
     
    $adc_in adc_in(030);

     if(
    abs($adc_in $last_adc_in) > 5)
     {
      
    printf("Voltage : %.2fV\r\n"$adc_in 4095.0 3.3);

      
    $last_adc_in $adc_in;

      
    usleep(100000);
     }
    }

    ?>



    [Explanation]

    Source code of this file does:
    • Setup ADC pin.
    In infinite loop:
    • Read value from rotaty angle sensor.
    • Calculate Voltage based on the read value.
    • Print Voltage to PHPoC Debugger's console.



    See Also

    Other Resources
    Last edited by support; 12-14-2022, 07:34 AM.
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 02:45 PM
    • Arduino - RS-422 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 02:44 PM
    • Arduino - RS-232 Expansion Board
      by support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 02:43 PM
    • Arduino - Stepper Motor Controller
      by support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 02:41 PM
    • Arduino - DC Motor Controller
      by support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 02:40 PM
    • Arduino - Digital Input Board
      by support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 02:39 PM
    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎