Friday, October 06, 2023, 04:30:01 + 4
parent
fdf5ba2673
commit
fb3a36da8a
|
@ -1,5 +1,13 @@
|
|||
{
|
||||
"recentFiles": [
|
||||
{
|
||||
"basename": "Analog SerialReader",
|
||||
"path": "Analog SerialReader.md"
|
||||
},
|
||||
{
|
||||
"basename": "Arduino",
|
||||
"path": "Machine Tips (Quantum)/Physics/Hardware/MicroControllers/Arduino.md"
|
||||
},
|
||||
{
|
||||
"basename": "Related Projects",
|
||||
"path": "Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md"
|
||||
|
@ -191,14 +199,6 @@
|
|||
{
|
||||
"basename": "GPU",
|
||||
"path": "GPU.md"
|
||||
},
|
||||
{
|
||||
"basename": "Fortran",
|
||||
"path": "Coding Tips (Classical)/Terminal Tips/Languages/Fortran.md"
|
||||
},
|
||||
{
|
||||
"basename": "fzf",
|
||||
"path": "fzf.md"
|
||||
}
|
||||
],
|
||||
"omittedPaths": [],
|
||||
|
|
|
@ -13,13 +13,26 @@
|
|||
"state": {
|
||||
"type": "markdown",
|
||||
"state": {
|
||||
"file": "Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md",
|
||||
"file": "Machine Tips (Quantum)/Physics/Hardware/MicroControllers/Arduino.md",
|
||||
"mode": "source",
|
||||
"source": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "888f3d7d90adcfb4",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "markdown",
|
||||
"state": {
|
||||
"file": "Analog SerialReader.md",
|
||||
"mode": "source",
|
||||
"source": false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"currentTab": 1,
|
||||
"stacked": true
|
||||
}
|
||||
],
|
||||
|
@ -94,7 +107,7 @@
|
|||
"state": {
|
||||
"type": "backlink",
|
||||
"state": {
|
||||
"file": "Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md",
|
||||
"file": "Analog SerialReader.md",
|
||||
"collapseAll": false,
|
||||
"extraContext": false,
|
||||
"sortOrder": "alphabetical",
|
||||
|
@ -111,7 +124,7 @@
|
|||
"state": {
|
||||
"type": "outgoing-link",
|
||||
"state": {
|
||||
"file": "Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md",
|
||||
"file": "Analog SerialReader.md",
|
||||
"linksCollapsed": false,
|
||||
"unlinkedCollapsed": true
|
||||
}
|
||||
|
@ -134,7 +147,7 @@
|
|||
"state": {
|
||||
"type": "outline",
|
||||
"state": {
|
||||
"file": "Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md"
|
||||
"file": "Analog SerialReader.md"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,10 +172,12 @@
|
|||
"command-palette:Open command palette": false
|
||||
}
|
||||
},
|
||||
"active": "012e39cfd1f0b5b6",
|
||||
"active": "888f3d7d90adcfb4",
|
||||
"lastOpenFiles": [
|
||||
"Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/typewriter Keys.md",
|
||||
"Machine Tips (Quantum)/Physics/Hardware/MicroControllers/Arduino.md",
|
||||
"Analog SerialReader.md",
|
||||
"Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/Related Projects.md",
|
||||
"Coding Tips (Classical)/Project Vault/Communication Projects/Typewriter/typewriter Keys.md",
|
||||
"Machine Tips (Quantum)/NYU Haqathon.md",
|
||||
"Coding Tips (Classical)/Project Vault/Communication Projects/WRITTEN TEXT/E-Mail Templates.md",
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Shwetha Jayaraj Notes.md",
|
||||
|
@ -198,8 +213,6 @@
|
|||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/Resume-ish - my occupations.md",
|
||||
"2023-10-02.md",
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/Quantum Stuff.md",
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/pdf.md",
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/Main Page.md",
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/Coding Projects.md"
|
||||
"Coding Tips (Classical)/Project Vault/Current Occupations/Website Projects/hi.shwethajayaraj/pdf.md"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
via [Arduino Example ](https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial)
|
||||
|
||||
Read a potentiometer, print its state out to the Arduino Serial Monitor.
|
||||
|
||||
LAST REVISION:09/19/2023, 10:55 AM
|
||||
|
||||
This example shows you how to read analog input from the physical world using a potentiometer. A **potentiometer** is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer (or _pot_ for short) as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer running the Arduino Software (IDE).
|
||||
|
||||
### Hardware Required
|
||||
|
||||
- Arduino Board
|
||||
|
||||
- 10k ohm Potentiometer
|
||||
|
||||
|
||||
### Circuit
|
||||
|
||||
Connect the three wires from the potentiometer to your board. The first goes from one of the outer pins of the potentiometer to ground. The second goes from the other outer pin of the potentiometer to 5 volts. The third goes from the middle pin of the potentiometer to the analog pin A0.
|
||||
|
||||
[![circuit](https://docs.arduino.cc/static/10842b0499a5e4e370aedcd222b52e2c/a6d36/circuit.png "circuit")](https://docs.arduino.cc/static/10842b0499a5e4e370aedcd222b52e2c/5a190/circuit.png)
|
||||
|
||||
By turning the shaft of the potentiometer, you change the amount of resistance on either side of the wiper, which is connected to the center pin of the potentiometer. This changes the voltage at the center pin. When the resistance between the center and the side connected to 5 volts is close to zero (and the resistance on the other side is close to 10k ohm), the voltage at the center pin nears 5 volts. When the resistances are reversed, the voltage at the center pin nears 0 volts, or ground. This voltage is the _analog voltage_ that you're reading as an input.
|
||||
|
||||
The Arduino boards have a circuit inside called an _analog-to-digital converter or ADC_ that reads this changing voltage and converts it to a number between 0 and 1023. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In between, [analogRead](https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/)() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
|
||||
|
||||
### Schematic
|
||||
|
||||
[![schematic](https://docs.arduino.cc/static/3bb842ec08b8a83f88c1a7c32800fe41/a6d36/schematic.png "schematic")](https://docs.arduino.cc/static/3bb842ec08b8a83f88c1a7c32800fe41/5a190/schematic.png)
|
||||
|
||||
### Code
|
||||
|
||||
In the sketch below, the only thing that you do in the setup function is to begin serial communications, at 9600 bits of data per second, between your board and your computer with the command:
|
||||
|
||||
```
|
||||
Serial.begin(9600);
|
||||
```
|
||||
|
||||
Next, in the main loop of your code, you need to establish a variable to store the resistance value (which will be between 0 and 1023, perfect for an [](https://www.arduino.cc/reference/en/language/variables/data-types/int/)
|
||||
|
||||
[`int`](https://www.arduino.cc/reference/en/language/variables/data-types/int/)
|
||||
|
||||
[datatype](https://www.arduino.cc/reference/en/language/variables/data-types/int/)) coming in from your potentiometer:
|
||||
|
||||
```
|
||||
int sensorValue = analogRead(A0);
|
||||
```
|
||||
|
||||
Finally, you need to print this information to your serial monitor window. You can do this with the command [Serial.println](https://www.arduino.cc/en/Serial/Println)() in your last line of code:
|
||||
|
||||
```
|
||||
Serial.println(sensorValue);
|
||||
```
|
||||
|
||||
Now, when you open your Serial Monitor in the Arduino Software (IDE) (by clicking the icon that looks like a lens, on the right, in the green top bar or using the keyboard shortcut Ctrl+Shift+M), you should see a steady stream of numbers ranging from 0-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will respond almost instantly.
|
||||
|
||||
### Learn more
|
||||
|
||||
You can find more basic tutorials in the [built-in examples](https://docs.arduino.cc/built-in-examples) section.
|
Loading…
Reference in New Issue