Mon objet est vivant!!!

Arduino est une plateforme open-source de prototypage d’électronique.

Arduino introduction

 

Comment connecter un capteur qui a deux pattes.


On va utiliser une resistance de 10k ohm pour créer un pont diviseur de tension.

Different types of sensors

Simple switch ON/OFF
bouton

Ces capteurs fonctionne grâce à une resistance variable.
Potentiomètre

FSR (Force sensing resistance)

FSR (Force sensing resistance)

Capteur de torsion/flexion

LDR (Light dependant resistance)

Capteur de pluie

Capteur d’humidité

Capteur de niveau

 

Capteur piezoÉlectrique 
Ce capteur utilise l’effet piezo électrique pour mesurer des changements de pression, de force, de vibration…

 

Faire du son

On peut utiliser la librairie TONE

Syntax

tone(pin, frequency)
tone(pin, frequency, duration)

Parameters

pin: the pin on which to generate the tone
frequency: the frequency of the tone in hertz – unsigned int
duration: the duration of the tone in milliseconds (optional) – unsigned long

Board Min frequency (Hz) Max frequency (Hz)
Uno, Mega, Leonardo and other AVR boards 31 65535

 

Un exemple de code pour faire un simple « theremin » avec l’arduino utilisant une LDR, un speaker et la librairie Tone

// These constants won't change:
const int LDR = A0; // pin that the sensor is attached to
const int Speaker = 9; // pin that the LED is attached to

// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
// turn on LED to signal the start of the calibration period:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

// calibrate during the first five seconds
while (millis() < 5000) { sensorValue = analogRead(LDR); // record the maximum sensor value if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}

// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}

// signal the end of the calibration period
digitalWrite(13, LOW);
}

void loop() {
// read the sensor:
sensorValue = analogRead(LDR);

// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, 
sensorMax, 50, 4000);

// play the tone
tone(Speaker, sensorValue);

//Take a break
delay(10);
}

Comment faire un capteur capacitif

Pour cela, il vous faut la librairie capacitiveSensor. Vous pouvez l’installer via le menu : Sketch/Include library/manage library/…

 

Brancher le capteur à Arduino

Quelle resistance utiliser
Use a 1 megohm resistor (or less maybe) for absolute touch to activate.
With a 10 megohm resistor the sensor will start to respond 10-15 centimeters away.
With a 40 megohm resistor the sensor will start to respond 30-60 centimeters away (dependent on the foil size). Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.
One tradeoff with larger resistors is that the sensor’s increased sensitivity means that it is slower. Also if the sensor is exposed metal, it is possible that the send pin will never be able to force a change in the receive (sensor) pin, and the sensor will timeout.
Also experiment with small capacitors (100 pF – .01 uF) to ground, on the sense pin. They improve stability of the sensor.

Code pour le capteur capacitif :

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing
    Serial.println(total1);                  // print sensor output 1

    delay(10);                             // arbitrary delay to limit data to serial port 
}