Commit b0c09a13 authored by Raul Singh's avatar Raul Singh
Browse files

Fixed slides order, added stuff

parent ef6dd86d
Pipeline #1110 passed with stage
in 58 seconds
......@@ -116,29 +116,27 @@
<section data-external="./slides/05-signals.html"></section>
<section data-external="./slides/06-breadboard.html"></section>
<section data-external="./slides/07-digital_output.html"></section>
<section data-charset="utf-8"
data-markdown="./slides/08-photoresistors.md"
data-markdown="./slides/07-photoresistors.md"
data-separator="^\r?\n---\r?\n$"
data-separator-notes="^Notes:"
data-separator-vertical="^\r?\n----\r?\n$">
</section>
<section data-external="./slides/09-analog_input.html"></section>
<section data-charset="utf-8"
data-markdown="./slides/09-wifi.md"
data-markdown="./slides/08-wifi.md"
data-separator="^\r?\n---\r?\n$"
data-separator-notes="^Notes:"
data-separator-vertical="^\r?\n----\r?\n$">
</section>
<section data-charset="utf-8"
data-markdown="./slides/10-bot_telegram.md"
data-markdown="./slides/09-bot_telegram.md"
data-separator="^\r?\n---\r?\n$"
data-separator-notes="^Notes:"
data-separator-vertical="^\r?\n----\r?\n$">
</section>
<section data-charset="utf-8"
data-markdown="./slides/11-project.md"
data-markdown="./slides/10-project.md"
data-separator="^\r?\n---\r?\n$"
data-separator-notes="^Notes:"
data-separator-vertical="^\r?\n----\r?\n$">
......
# Let's try to do something more interesting!
----
We will do a small circuit and read an analog value from a sensor
What sensor will we use?
----
## Photoresistors
Photoresistors, also known as **LDR** (light dependent resistors), are light-sensitive devices. In the dark their impedence is really high,generally 10MΩ.
......@@ -13,6 +23,34 @@ Its settling time latency is about 10ms, therefore it’s not ideal for controll
----
So, in few words, a photoresistor is something we can use as a **light sensor**
<img src="./images/ftres3.gif" alt="Manoh" style="width:30%;"/>
----
We will do a small sketch that reads the light value and prints it on the computer
But first, we need to build the circuit!
----
A photoresistor, as said before, is a **variable** resitor that changes depending on how much light hits it.
A resitor causes a **voltage drop** across its ends.
----
If we put 2 resistor in series, we get a **voltage divider**
This circuits divides the voltage depending on the resitor's value. If they are both equal, the voltage is divided in two halfs, 1/2 and 1/2. If one resistor has a value of (1/3)R and (2/3)R, the whole voltage gets divided in 1/3 and 2/3.
----
So, if we put a photoresistor in place of the first resitor, its **varying** resitance will lead to a **varying** voltage.
We just need to read the voltage value after the photoresistor.
----
<img src="./images/ESP32_photoresistor.png" alt="Sensor"/>
\ No newline at end of file
<section>
<h2>Analog input</h2>
</section>
<section>
<h3>The goal</h3>
<h4 class="fragment">We'll have to get the value of an analog signal</h4>
</section>
<section>
<h3>This time we won't init the pin</h3>
<small class="fragment" style="color: red;">N.B. only specific pins can be used,<br/>
these are the pins<br/>
marked with an "A" (A0, A1, ...)</small>
</section>
<section>
<h3>Read the analog value</h3>
<p class="fragment">With the function <b>analogRead</b></p>
</section>
<section>
<h3><a href="https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/">analogRead(pin)</a></h3>
<blockquote cite="https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/">
Reads the value from the specified<br/>
analog pin.[...]<br/>
it will map input voltages between 0<br/>
and the operating voltage(5V or 3.3V) into<br/>
integer values between 0 and 1023.
</blockquote>
<ul>
<li><b>pin:</b> the id of the pin which we want to use</li>
</ul>
<pre class="fragment"><code class="lang-cpp">int v = analogRead(A1)</code></pre>
</section>
<section>
<p>Let's introduce an useful math function</p>
<h5><a href="https://www.arduino.cc/reference/en/language/functions/math/map/">map(value, fromLow, fromHigh, toLow,
toHigh)</a></h5>
<blockquote cite="https://www.arduino.cc/reference/en/language/functions/math/map/">
Re-maps a number from one range to<br/>
another. That is, a value of <b>fromLow</b><br/>
would get mapped to <b>toLow</b>,<br/>
a value of <b>fromHigh</b> to <b>toHigh</b>,<br/>
values in-between to values in-between
</blockquote>
<pre class="fragment"><code class="lang-cpp">int x = map(512, 0, 1023, 0, 255); //128</code></pre>
</section>
<section>
<h3>The task</h3>
<h4 class="fragment">We want to control the LED<br/>
brightness with a potentiometer</h4>
</section>
<section>
<h4>What's a <a href="https://en.wikipedia.org/wiki/Potentiometer">potentiometer</a>?</h4>
<p class="fragment" style="text-align: left; width: 80%;">
<img align="left" data-src="./images/potentiometer.png"
style="height:170px; margin-left: 0px; margin-right: 30px;"/>
It's essentially a resistor(<b>R</b>)<br/>
divided in two parts (<b>R1</b> & <b>R2</b>)<br/>
of which we can change<br/>
the size with a knob</p>
<p class="fragment" style="text-align: right; width: 80%;">
<img align="right" data-src="./images/potentiometer_symbol.svg"
style="height:170px; margin-left: 30px; margin-right: 0;"/>
If we apply a voltage to the two external<br/>
pins (<b>1</b> & <b>2</b>) of a potentiometer we'll find<br/>
on the middle pin(<b>3</b>) a voltage that<br/>
varies with the position of the knob</p>
</section>
<section>
<h4>The circuit</h4>
<img data-src="./images/circuit_led_pwm_potentiometer.svg" style="width:35%;"/>
</section>
<section>
<h4>The sketch</h4>
<pre><code class="lang-cpp">int v, x;
void setup() {
pinMode(9, OUTPUT); // initializes LED pin as output
}
void loop() {
v = analogRead(A1); // reads the analog value
x = map(v, 0, 1023, 0, 255); // rescales value to PWM range
analogWrite(9, x); // writes the output as PWM
delay(100); // waits a moment
}</code></pre>
</section>
<section>
<h4>What (is supposed to) happen?</h4>
<p class="fragment">Turning the potentiometer<br/>
changes the LED brightness</p>
</section>
</section>
<h4>Photoresistors</h4>
</section>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment