Vincec's Dimension

Arduino Notes

Word count: 536 / Reading time: 3 min
2019/06/25 Share

pinMode(pin, mode)

Mode type:

  • INPUT
  • INPUT_PULLUP
  • OUTPUT

Interface

  • Digital
  • Analog
  • Power pin

Digital

Wire Example

source: Lynda)

PushButton

Active Low Pushbutton -> send low signal to microprocessor / pull-up circuit, pull-up resistor
Active Down Pushbutton -> send up signal to microprocessor / pull-down circuit, pull-down resistor

Build-in pull-up resist(input_pullup) & led light indicator(PIN #13)

Functions

  • digitalWrite()
  • digitalRead(pin)

Code example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int counter = 0;
int LED = 2;

void setup() {
// initialize digital pin LED_BUILTIN as an output.
// pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED, HIGH);
delay(1100);
Serial.println("Open");
digitalWrite(LED, LOW);
delay(1100);
Serial.println("Close");
counter++;
Serial.println(counter);
// digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(1100); // wait for a second
// digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
// delay(1100); // wait for a second
}

Analog Input

Sensors

Voltage, Analog Output, Ground

  • Temperature sensor
  • LDR sensor (voltage divider circuit)

E.g. TMP37, Scale Factor: 20 mV/C = Output voltage - (0ffset voltage) mV / Temperature C

ADC

10-Bit Analog to Digial Converter, Voltage value: 0 mV -> 5000 mV, ADC value: 0 -> 1023

Functions

  • analogReference(), 5V -> analogReference(DEFAULT)
  • analogRead(A0), type int

Analog Output

Pulse with Modulation(PWM), duty cycle, chnage pulse width(on status)

Functions

  • analogReference(), 5V -> analogReference(DEFAULT)
  • analogWrite(pin, value), value: amount of time digital pulse is set to high, 0 ~ 255 (0 ~ 5 V)
  • map(fromValue, fromLow, fromHigh, toLow, toHigh), cast the range, fromXXX - the value of original, toXXX, the value of target.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//arduino example - fading
int ledPin = 9; // LED connected to digital pin 9

void setup() {
// nothing happens in setup
}

void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

Stepper Motor

Need Stepper Motor Drive Board and exteral AC supply

  • Unipolar(eight-wire)
  • Bipolar ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
digitalWrite(motorpin1, HIGH);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, LOW);
delay(delayTime);

digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, HIGH);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, LOW);
delay(delayTime);

digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, HIGH);
digitalWrite(motorpin4, LOW);
delay(delayTime);

digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, HIGH);
delay(delayTime);

Stepper Motor Library

Stepper(steps, pin1, pin2, pin3, pin4)

Steps per resolution (degrees/step), full = 360

Reference

Author: VINCEC

Permalink: https://vince-amazing/blog/2019/06/25/arduino-notes/

Date: June 25th 2019, 3:10:28

Copyright license: The article usingCC licensing 4.0

CATALOG
  1. 1. pinMode(pin, mode)
  2. 2. Interface
  3. 3. Digital
    1. 3.1. Wire Example
    2. 3.2. PushButton
      1. 3.2.1. Build-in pull-up resist(input_pullup) & led light indicator(PIN #13)
    3. 3.3. Functions
    4. 3.4. Code example
  4. 4. Analog Input
    1. 4.1. Sensors
    2. 4.2. ADC
    3. 4.3. Functions
  5. 5. Analog Output
    1. 5.1. Functions
    2. 5.2. Example
  6. 6. Stepper Motor
    1. 6.1. Stepper Motor Library
  • Reference