Sensore per arduino meglio acquistare on-line su Gearbest.com che offre la migliore Sensore per arduino con spedizione gratuita. Sensore per arduino - Acquista Sensore per arduino online al miglior prezzo con spedizione gratuita Gearbest.com.
Connect Arduino to computer and run the Arduino code.
This code uses CapSense Library by Paul Badger, and the SerialCallResponse sketches by Tom Igoe and Scott Fitzgearld.
In order to calibrate a sensor, use Serial.print and map the values of the corresponding pin:
///////////////////////////////////////
void loop() {
long total1 = cs_4_2.capacitiveSensor(30);
long total1 = cs_4_2.capacitiveSensor(30);
Serial.println(total1);
/////////////////////////////////////////
Code for Communicating with Processing over Serial
*/
int val1 = 0;
int val2 = 0;
int val3 = 0;
int inByte = 0;
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 1M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 1M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
void setup() {
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
cs_4_6.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(6, INPUT);
// pinMode(8, INPUT);
establishContact(); // send a byte to establish contact until receiver responds
void loop() {
// if we get a valid byte, read inputs:
if (Serial.available() > 0){
// get incoming byte:
inByte = Serial.read();
//long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long total2 = cs_4_6.capacitiveSensor(30);
//long total3 = cs_4_8.capacitiveSensor(30);
//delay(10);
val1 = map(total1, 700, 2300, 0, 255); // sensor values from calibration are mapped to here - begins to detect human proximity at 700 (4' away) , hand nearly touching sensor at 2300
val2 = map(total2, 30, 175, 0, 255);
//val3 = map(total3, 0, 13000, 0, 255);
Serial.write(val1);
Serial.write(val2);
//Serial.write(val3);
//Serial.print(val1);
//delay(50);
![Sensore Capacitivo Acqua Arduino Sensore Capacitivo Acqua Arduino](http://www.dallaf.it/simowp/wp-content/uploads/2015/08/moisutre-scheme.png)
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A');
delay(300); }