FRC_7130_4th
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 消毒機 程式撰寫 ###### tags: `程式組教程` ## 電磁閥 ![](https://i.imgur.com/N0tCjtp.png) We are starting with the BareMinimum Sketch found in the IDE, it should look something like this: ```cpp= void setup() { // put your setup code here, to run once. } void loop() { // put your main code here, to run repeatedly. } ``` So first we will need a variable for the Arduino pin: ```cpp= int solenoidPin = 4; //This is the output pin on the Arduino we are using void setup() { // put your setup code here, to run once. } void loop() { // put your main code here, to run repeatedly. } ``` Next we need to set the Arduino pin to act as an output: ```cpp= int solenoidPin = 4; //This is the output pin on the Arduino we are using void setup() { // put your setup code here, to run once. pinMode(solenoidPin, OUTPUT); //Sets the pin as an output } void loop() { // put your main code here, to run repeatedly. } ``` Now that it is set as an output we can tell it what to do: ```cpp= int solenoidPin = 4; //This is the output pin on the Arduino we are using void setup() { // put your setup code here, to run once. pinMode(solenoidPin, OUTPUT); //Sets the pin as an output } void loop() { // put your main code here, to run repeatedly. digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON delay(1000); //Wait 1 Second digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF delay(1000); //Wait 1 Second } ``` So if we want the solenoid to allow water to flow, set the pin high. When you want the water to stop flowing, set the pin low. In this case it will turn the water on for 1 second and then off for 1 second, looping forever (or at least until it is unplugged!) This solenoid valve could easily be used with the flow meter featured in our last tutorial to create a system that only allows a certain volume of water to flow before shutting off. ## 幫浦 [Bump sensor](https://forum.arduino.cc/t/bump-sensor/493166) ```cpp= const byte switchPin = 10; byte oldSwitchState = HIGH; // initial condition void setup () { Serial.begin (9600); pinMode (switchPin, INPUT); } // end of setup void loop () { // see if switch is open or closed byte switchState = digitalRead (switchPin); // has it changed since last time? if (switchState != oldSwitchState) { oldSwitchState = switchState; // remember for next time if (switchState == LOW) { Serial.println ("Switch closed."); } // end if switchState is LOW else { Serial.println ("Switch opened."); } // end if switchState is HIGH } // end of state change } ``` 網路上查到的造霧機arduino程式(可以參考) ```cpp= /* Demo code for grove atomization. Touch to start atomizing. Last modified by he by xiaohe */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(A5, OUTPUT);// Set A5 as OUTPUT pinMode(5, INPUT); // Use digital pin 5 as output port } // the loop function runs over and over again forever void loop() { int D2Sig = digitalRead(5);// read pin 5 signal if (D2Sig == 1) { /* code */ digitalWrite(A5, HIGH); // atomize delay(10000); // wait for 10 seconds digitalWrite(A5, LOW); // atomization stopped } } ``` ```cpp= /* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-controls-pump */ // constants won't change const int RELAY_PIN = A5; // the Arduino pin, which connects to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin A5 as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on pump 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // turn off pump 5 seconds delay(5000); } ``` ## 繼電器 [[Arduino 範例] 繼電器(Relay)的使用](https://blog.jmaker.com.tw/arduino-relay/ ) 據我所知好像沒有程式?? (仁祥 ```cpp= void setup() { // put your setup code here, to run once: pinMode(11,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(11,HIGH); delay(500); digitalWrite(11,LOW); } ``` ## 微動開關 ```cpp= const int buttonPin = 10; // the number of the pushbutton pin const int ledPin = 12; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } ``` [Arduino 按壓開關與微動開關](/K2D_p--PRgW5B7SsmXAFRA) ## 馬達 (motor, encoder) [Talon Speed Controller](https://forum.arduino.cc/t/talon-speed-controller/146210) ```cpp= #include <Servo.h> void setup(){ } void loop() { servo.write(180); delay(1500); servo.write(0); delay(1500); } ``` [Control a Talon motor using PWM](https://mrmctavish.wordpress.com/2020/03/15/using-an-arduino-to-control-a-talon-or-spark-motor-controller-using-pwm/) ```cpp= #include <PWM.h> //use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz int motor = 9; // the pin that the LED is attached to int motorspeed = 1; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by int32_t frequency = 1000; //frequency (in Hz) bool success; void setup() { //initialize all timers except for 0, to save time keeping functions InitTimersSafe(); //sets the frequency for the specified pin success = SetPinFrequencySafe(motor, frequency); //if the pin frequency was set successfully, turn pin 13 on if(success) { pinMode(13, OUTPUT); digitalWrite(13, HIGH); } } void loop() { //use this functions instead of analogWrite on 'initialized' pins digitalWrite(13, HIGH); success = SetPinFrequencySafe(motor, 1000); pwmWrite(motor, motorspeed); delay(5000); digitalWrite(13, LOW); motorspeed=HIGH; pwmWrite(motor,motorspeed); delay(5000); success = SetPinFrequencySafe(motor, 1500); motorspeed = LOW; pwmWrite(motor, motorspeed); delay(5000); motorspeed=HIGH; pwmWrite(motor,motorspeed); delay(5000); success = SetPinFrequencySafe(motor, 2000); motorspeed = LOW; pwmWrite(motor, motorspeed); delay(5000); motorspeed=HIGH; pwmWrite(motor,motorspeed); delay(5000); } ``` [Knob](https://www.arduino.cc/en/Tutorial/Knob) ```cpp= #include <Servo.h> Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } ``` ## 燈條 ## 紅外線 [紅外線](https://hackmd.io/@yqvHTthmTYehjxz4k9Hqrw/HJDggCjyt) ```cpp= int IR_SENSOR = 0; // 類比讀取腳設為A0 int intSensorResult = 0; //偵測結果 float fltSensorCalc = 0; //計算距離 void setup(){ Serial.begin(9600); //設定和電腦的連接去將結果顯示在序列埠監控視窗(Serial Monitor) } void loop(){ //從IR sensor讀取傳感值 intSensorResult = analogRead(IR_SENSOR); //從類比讀腳(A0)獲取傳感值 fltSensorCalc = (6787.0 / (intSensorResult - 3.0)) - 4.0; //以公分為單位計算距離 Serial.print(fltSensorCalc); //傳送距離到電腦中 Serial.println("cm"); //將"cm"加到顯示結果中 delay(200); //延遲0.2秒 } ``` ## 超音波 ```cpp= // ---------------------------------------------------------------- // // Arduino Ultrasoninc Sensor HC-SR04 // Re-writed by Arbi Abdul Jabbaar // Using Arduino IDE 1.8.7 // Using HC-SR04 Module // Tested on 17 September 2019 // ---------------------------------------------------------------- // #define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 #define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04 // defines variables long duration; // variable for the duration of sound wave travel int distance; // variable for the distance measurement void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor Serial.println("with Arduino UNO R3"); } void loop() { // Clears the trigPin condition digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back) // Displays the distance on the Serial Monitor Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm"); } ``` ```cpp= int trigPin = 發射端腳位; int echoPin = 接收端腳位; void setup(){ Serial.begin (9600); //這東東不一定要加,要在電腦上看到數據要加 pinMode(trigPin,OUTPUT); //宣告發射端為輸出 pinMode(echoPin,INPUT); //宣告接收端為輸入 } void loop(){ digitalWrite(trigPin, LOW); //先將發射端斷電,訊號清空 delayMicroseconds(5); //讓訊號完整清空 digitalWrite(trigPin, HIGH); //將發射端通電,射出訊號 delayMicroseconds(10); //讓上面動作完整執行,為啥是10秒,這是網路上的數據 digitalWrite(trigPin, LOW); //將發射端斷電 duration = pulseIn(echoPin, HIGH); //讀取接收端的數據 cm = (duration/2) / 29.4; //從時間轉換成距離 // 1000000 microseconds / 340 * 100 = 29.4 microseconds(氣溫15度時) //上面這些就是測距的程式 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully