# data[].attributes.body
int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
// turn the LED on
digitalWrite(13, HIGH);
// pause the program for <sensorValue> millseconds
delay(sensorValue); // Wait for sensorValue millisecond(s)
// turn the LED off
digitalWrite(13, LOW);
// pause the program for <sensorValue> millseconds
delay(sensorValue); // Wait for sensorValue millisecond(s)
}

# data[].attributes.body
const int pinNum [10] = {2,3,4,5,6,7,8,9,10,11}; // create an array of pin numbers
const int numOfPins = 10; // declare number of pins to blink
const int minRate = 50; // set minimum blink speed
const int maxRate = 1000; // set maximum blink speed
/******************************************************************************************/
void setup() {
for (int i = 0; i < numOfPins; i++){ // for loop for setting pins to output
pinMode(pinNum[i], OUTPUT);
};
}
void loop() {
for (int i = 0; i < numOfPins-1; i++){ // for loop going up the LEDs
int pot = analogRead(A0); // read the pot value on analog pin 0
pot = map(pot, 0, 1023, maxRate, minRate); // map the pot reading from 0-1024 to maxRate-minRate
digitalWrite(pinNum[i], HIGH); // sets pin [i] high
delay(pot); // sets the pin [i] HIGH duration to value of pot
digitalWrite(pinNum[i], LOW); // sets the pin low
};
for(int i = numOfPins-1; i > 0; i--) { // for loop going down the LEDs
int pot = analogRead(0); // read the pot value on analog pin 0
pot = map(pot, 0, 1023, maxRate, minRate); // map the pot reading from 0-1024 to maxRate-minRate
digitalWrite(pinNum[i], HIGH); // sets pin [i] high
delay(pot); // sets the pin [i] HIGH duration to value of pot
digitalWrite(pinNum[i], LOW); // sets the pin low
};
}

# data[].attributes.body
int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

pinMode(9, OUTPUT);
}

void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorValue);
// map the sensor reading to a range for the
// speaker
analogWrite(9, map(sensorValue, 0, 1023, 0, 255));
delay(100); // Wait for 100 millisecond(s)
}

# data[].attributes.body
int distanceThreshold = 0;

int cm = 0;

int inches = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);  // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}

void loop()
{
// set threshold distance to activate LEDs
distanceThreshold = 320;
// measure the ping time in cm
cm = 0.01723 * readUltrasonicDistance(7, 6);
// convert to inches by dividing by 2.54
inches = (cm / 2.54);
Serial.print(cm);
Serial.print("cm, ");
Serial.print(inches);
Serial.println("in");
if (cm > distanceThreshold) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= distanceThreshold && cm > distanceThreshold - 100) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= distanceThreshold - 100 && cm > distanceThreshold - 250) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
if (cm <= distanceThreshold - 250 && cm > distanceThreshold - 350) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
if (cm <= distanceThreshold - 350) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(100); // Wait for 100 millisecond(s)
}

# data[].attributes.body
#include <Servo.h>
#include <SoftwareSerial.h>

int pos = 0;
int sensorValue = 0;
int i = 0;

Servo servo_9;

void setup()
{
servo_9.attach(9);
pinMode(A0, INPUT);
// pinMode(13, OUTPUT);
Serial.begin(9600);

}

void loop()
{

sensorValue = analogRead(A0);
pos = map(sensorValue,0,1023,0,180);

Serial.print("sensorValue ");
Serial.println(sensorValue);
Serial.print("pos ");
Serial.println(pos);

for (i = 0; i <= pos; i++) {

// tell servo to go to position in variable 'pos'
servo_9.write(i);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
for (i= pos; i >= 0; i --) {
// tell servo to go to position in variable 'pos'
servo_9.write(i);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
}

# data[].attributes.attachment_link.title
Projet Domotique Arduino Reconnaissance vocale | Simple, Peu couteux #1