Placeholder Image

Subtitles section Play video

  • Hi my name is Massimo Banzi.

  • and I am one of the cofounders

  • of the Arduino project.

  • And we are here for another video

  • about our Arduino starter kit.

  • Today we are going to look at

  • a new project

  • called "The Touch Sensor Lamp".

  • This is a simple circuit

  • where we are going to build

  • a sensor that is able to detect

  • when a human being is

  • touching the circuit.

  • You can see that if I touch this

  • wire, the LED turns on.

  • For this tutorial we are going to

  • introduce a new concept

  • from the Arduino platform:

  • external libraries.

  • This is a very powerful concept because

  • there are some things

  • in Arduino programming

  • that are very complex for beginners.

  • Like for example, in this

  • case, we are building a touch sensor.

  • The touch sensor uses a

  • fairly complex process

  • for the beginner.

  • And it would be quite complex for

  • beginners to write the code

  • completely by themselves.

  • so someone with a lot of

  • skills in Arduino programming

  • developed a library that

  • is able to perform

  • this sensing function.

  • On the arduino website

  • you are going to find all the

  • instructions you need

  • in order to install

  • a new library

  • into the Arduino development enviroment.

  • But let's have a look at this circuit.

  • Here we have an LED

  • connected to pin number 12

  • of the Arduino.

  • And then we have this strange circuit,

  • where we have a resistor

  • connected between pin number 2

  • and 4 of our Arduino.

  • And then there is a wire

  • connected to pin number 2.

  • If i touch the wire with my finger,

  • the led turns on.

  • So, this is due to the passive sensor

  • implemented by the library

  • that we are going to see

  • in a few seconds.

  • The capacitive sensor is able to

  • detect when a human being

  • is touching a metallic surface.

  • It's the same principle used by

  • the touch sensor

  • on the screen of every iPhone

  • or Android mobile phones

  • that you may have used.

  • We can also increase the sensitivity

  • of the sensor

  • by using an external metallic surface.

  • I am going to use

  • a piece of printed circuit board

  • that hasn't been etched yet.

  • So as you can see

  • it is a piece of fiberglass

  • with some copper on top.

  • so we are going connect this

  • to my circuit and see

  • what happens if I place

  • a bigger surface.

  • So we are going to help ourself

  • using this alligator clip.

  • I am going to

  • connect the alligator clip to the wire

  • and then to the copper surface.

  • so now when

  • my hand touches the surface

  • it turns on and off.

  • Actually what happens is that

  • only if you actually have to

  • touch

  • the surface, it starts to

  • sense my hand even

  • when the hand is just close.

  • Actually if we flip

  • the board around here we have

  • an insulating surface made of

  • fiberglass and still

  • if I place my full hand on it,

  • it can still detect my hand.

  • so the capacitive sensor

  • is very useful because I

  • can actually detect the touch

  • of a person even through

  • certain insulating materials.

  • Now let's have a look at the code.

  • here you can see

  • something new already at the

  • beginning of the code.

  • We are going to use this statement

  • called "include".

  • You have this # sign followed by

  • include and CapSense.h

  • So, this statement tells Arduino

  • to look for a library called

  • CapSense and include that

  • into our program.

  • As I said before

  • this is quite useful because

  • it is going to introduce

  • a piece of code,

  • which is quite complex

  • and is going to make

  • your life very simple.

  • and you can find online literally

  • hundreds of libraries

  • that encapsulate the functionality

  • of very complex sensors.

  • And provide you a very simple

  • way to use them.

  • So they are an incredibly powerful

  • part of the Arduino platform.

  • So

  • a little further down in the code

  • you can see that we are creating

  • an object of type CapSense

  • and this object is called capSensor.

  • And we are specifying that pin

  • 4 and 2

  • are the two pins connected to

  • the resistor and pin number 2 is

  • actually the one that goes to

  • the sensor.

  • So, later on we create

  • another variable called threshold

  • that is set to the value 1000.

  • this value will need to be

  • determined experimentally while you

  • work on your code.

  • And finally we create a

  • constant called ledPin

  • that specifies that the LED

  • is connected to pin number 12.

  • In the setup()

  • you see there is nothing complex.

  • There is a Serial.begin()

  • that opens a communication channel

  • with the computer at 9600 bits per second,

  • followed by a pinMode(ledPin, OUTPUT)

  • that makes sure that the pin

  • connected to the led is set

  • as an output

  • so that we can turn in on and off.

  • If we look at the setup(),

  • we can see that there is an

  • interesting command here.

  • We are using the CapSense library

  • to read from the sensor

  • and the number 30

  • witin brackets - here -

  • is indicating that we want

  • to read 30 samples

  • from the sensor.

  • This makes sure that we filter

  • out any unwanted noise or

  • false reading.

  • The value read by the sensor

  • goes into this variable

  • called sensorValue.

  • Later on we print sensorValue

  • towards the computer

  • so we can visualise it

  • with a serial monitor.

  • After that

  • comes the moment when we have actually

  • to decide if the led has to

  • be on or off.

  • If sensorValue is more

  • than the threshold then we turn

  • on the LED. If sensorValue

  • is less, then the LED turns off.

  • Then we introduce a small

  • 10ms delay

  • to make sure that we are not

  • reading too fast

  • And afterwards we just

  • go back to the beginning of the loop,

  • we'll read the sensor again

  • and we continue like this.

  • If we switch on the serial monitor,

  • we can actually see

  • a series of numbers

  • coming from the sensor.

  • You can see that when I

  • approach with my hand the PCB

  • that I connected to the sensor,

  • the numbers increase.

  • And when the number

  • is bigger than a certain value

  • that we set which is 1000

  • in this case.

  • When the value is more than 1000

  • the LED turns on.

  • So this sensor

  • can also be used as a

  • proximity sensor

  • if properly configured.

  • Ok so

  • we are at the end of the tutorial

  • I hope you enjoyed this project

  • and see you later alligator.

Hi my name is Massimo Banzi.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it

B1

Arduino視頻教程08:觸手可及的燈泡 (Arduino Video Tutorial 08: Touchy-Feely Lamp)

  • 78 0
    Chuan Zhe Lin posted on 2021/01/14
Video vocabulary