Skip to content
Snippets Groups Projects
Commit 1e3d5946 authored by Jiawen Gong's avatar Jiawen Gong
Browse files

Update file week05.md

parent 23968c0d
No related branches found
No related tags found
No related merge requests found
Pipeline #414524 passed
......@@ -98,6 +98,71 @@ Different from digital circuit, analog signals have continuous electrical signal
## **ARDUINO**
<iframe width="560" height="315" src="https://www.youtube.com/embed/7Q5kZ0tz3AI?si=pf0Da_Kc1y_U9K4w" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
Easiest Code for Analog Read:
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(100); // delay in between reads for stability
}
Modified Resistance Measurement Circuit (with a 9.5k ohm resistor and with custom lower and upper resistance range)
/*
Resistance Measurement - www.circuits4you.com
Reads an analog input on pin 0, converts it to resistance, and prints the result to the serial monitor.
Using a 9,5k ohm resistor as known resistor
*/
int ledPin = 5; // LED connected to digital pin 9
int lowerBoundResistance = 500;
int upperBoundResistance = 1500;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1024.0);
int resistorvalue = 9500;
float I = voltage / resistorvalue;
float VRx = 5 - voltage;
float Rx = VRx / I;
Rx = (5 - voltage) / I;
int mappedValue = map(Rx, lowerBoundResistance, upperBoundResistance, 0, 255);
mappedValue = constrain(mappedValue, 0, 255);
// print out the value you read:
Serial.print("Resistance:");
Serial.print(Rx);
Serial.print(" Ohms");
Serial.print(" and mapped value is ");
Serial.println(mappedValue);
analogWrite(ledPin, mappedValue);
delay(100);
}
<div style="padding:75% 0 0 0;position:relative;"><iframe src="https://player.vimeo.com/video/877385332?badge=0&amp;autopause=0&amp;quality_selector=1&amp;progress_bar=1&amp;player_id=0&amp;app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" style="position:absolute;top:0;left:0;width:100%;height:100%;" title="E-Textiles by Michelle Vosson"></iframe></div><script src="https://player.vimeo.com/api/player.js"></script>
## **TOOLS**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment