Documente Academic
Documente Profesional
Documente Cultură
El cdigo es:
void setup()
{
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop()
{
int val;
val=analogRead(0); //connect mic sensor to Analog 0
Serial.println(val,DEC);//print the sound value to serial
delay(300);
}
Specification
Type: Digital
Supply Voltage:35V
Current:50A
Working temperature:0 70
Output level(HIGH):4V
Output level(LOW):0.4V
Detect angle:110 Degree
Detect distance:7 meters
Size:28mm36mm
Weight:25g
Pin Definition
+:Power 5V
-:GND
OUT:Digital Signal Out
Specification
El cdigo seria :
int IRpin = 1;
void setup() {
Serial.begin(9600);
}
void loop() {
float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if
running 3.3.volts then change 5 to 3.3
float distance = 65*pow(volts, -1.10);
// worked out from graph 65 = theretical
distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance);
// print the distance
delay(100);
// arbitary wait time.
}
Looking at our graph above from the datasheet, this converted value is of no use to us so
we need to convert this value back to the true analog value. How? We take the voltage
rating of the power supply and divide by 1024 to give us a value per step. So for instance:
5v/1024 = 0.0048828125
We take this value and multiply by what the sensor sends back to get our voltage reading.
The next stage is to work out an equation from the graph on the data sheet to get the
theoretical distance from the voltage reading, if we look at the graph between 20 and
150cm you can see that its exponential.
To get our distance on the graph I came up with:
1/Volts * 65
I got 65 by taking the distance on the graph and dividing that by 1/Volts. So now we know
what to multiply our voltage results by to get the distance. This is fine if we just had one
value to read or if this was a linear graph, in that the change in voltage was always the
same amount of distance.
For the exponential change we have to turn our value now into an exponent, a fancy way
of saying x to the power of y. So our formula for distance from voltage reading is now
something like:
IV. Termistores
The DFRobot LM35 Linear Temperature Sensor is based on the semiconductor LM35
temperature sensor. The DFRobot LM35 Linear Temperature Sensor can be used to detect
ambient air temperature. This sensor is produced by National Semiconductor Corporation
and offers a functional range between -40 degree Celsius to 150 degree Celsius. Sensitivity
is 10mV per degree Celsius. The output voltage is proportional to the temperature.
Pin Definition
The definition of gray-scale sensor pin is
1. Signal Output
2. GND
3. Power
Serial.print(dat);
Serial.println("C");
delay(500);
}
La salida generada es:
En el caso del motor elctrico, este se conecta en GND y el otro pin a la lnea 10 digital.
int led=5;
int ntc=0;
int motor=10;
int medida=0;
int nivel=59; //variable que guarda el lmite de temperatura al que se activa el ventilador
valor anterior 700
void setup(){
pinMode(led,OUTPUT);
pinMode(motor,OUTPUT);
Serial.begin(9600);
}
void monitoriza(){ //procedimiento que enva al puerto serie, para ser ledo en el monitor,
Serial.print("La medida es ...");
Serial.println(medida);
//Serial.print();
delay(1000); //para evitar saturar el puerto serie
}
void loop(){
medida=analogRead(ntc);
monitoriza();
if(medida>nivel){ //si la seal del sensor supera el nivel marcado:
digitalWrite(led,HIGH); //se enciende un aviso luminoso
digitalWrite(motor,HIGH); //arranca el motor
}
else{ // si la seal est por debajo del nivel marcado
digitalWrite(led,LOW);
digitalWrite(motor,LOW); // el motor se para
}
}
V. Uso de Relays
El Rel es un dispositivo, que funciona como un interruptor controlado por un circuito elctrico en
el que, por medio de un electroimn, se acciona un juego de uno o varios contactos que permiten
abrir o cerrar otros circuitos elctricos independientes.
De esta forma, podremos separar dos circuitos que funcionen con voltajes diferentes. Uno
a 5V (Arduino) y otro a 220V (la bombilla). Para este ejemplo, se utilizara un circuito de
220V con un mximo de 10A.
Codigo:
int ledPin = 2; // *********** CHANGE TO PIN 2 ************
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Serial.println(valor);
if(valor < threshold){
digitalWrite(relayPin, HIGH); // ENCENDIDO
}else{
digitalWrite(relayPin, LOW); // APAGADO
}
}
void setup(){
Serial.begin(BAUD_RATE);
}
void loop(){
Serial.print(get_temperature());
Serial.println(" C");
delay(1000);
}
void loop() {
Acelerometro
Introduction
The MMA7361 from Freescale is a very nice sensor with easy analog interface. The
MMA7361 is a 3.3V part and outputs an analog voltage for each of the three outputs. This
voltage is in ratio to the measured acceleration and to the supply voltage (ratiometric). It
has selectable sensitivity by dip switch. You will need some extra hardware to convert this
analog signal to a usable digital one. The Arduino is really good option for it. This break
board is especially designed for Arduino which has 3 JST connector that can be easily plug
into our IO/Sensor expansion board.
Specification
Voltage:3.3-8V
Selectable sensitivity:15g/6g
Low power:500A @ measurement mode3A @standby
High sensivity: 800 mV/g @ 1.5g
Interface:Analog Output
Low pass filter
Size:23x26mm
Weight: 5 gram
Programa de prueba:
const unsigned int X_AXIS_PIN = 2;
const unsigned int Y_AXIS_PIN = 1;
delay(1);
buffer[axis][buffer_pos[axis]] = analogRead(PINS[axis]);
buffer_pos[axis] = (buffer_pos[axis] + 1) % BUFFER_SIZE;
long sum = 0;
for (int i = 0; i < BUFFER_SIZE; i++)
sum += buffer[axis][i];
return round(sum / BUFFER_SIZE);
}
int get_x() { return get_axis(0);}
int get_y() { return get_axis(1);}
int get_z() { return get_axis(2);}
void setup() {
// put your setup code here, to run once:
Serial.begin(BAUD_RATE);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(get_x());
Serial.print(" ");
Serial.print(get_y());
Serial.print(" ");
Serial.println(get_z());
}
Specification
Power supply: 3.3v or 5v
Output voltage signal: 0~4.2v
Current: 35mA
Pin definition:
1-Analog output(Blue wire)
2-GND(Black wire)
3-Power(Red wire)
Size: 60x20x5mm
Value range:
1. 0 ~300 : dry soil
2. 300~700 : humid soil
3. 700~950 : in water
Shipping List
Moisture sensor(1 unit)
Analog Sensor Cable (1 unit)
Connection Diagram
Ejemplo
/*
#
#
#
#
#
# 0 ~300
# 300~700
# 700~950
*/
dry soil
humid soil
in water
void setup(){
Serial.begin(57600);
}
void loop(){
Serial.print("Moisture Sensor Value:");
Serial.println(analogRead(0));
delay(100);
}
The analog gas sensor - MQ3 is suitable for detecting alcohol, this sensor can be used in a
Breathalyser.It has a high sensitivity to alcohol and small sensitivity to Benzine. The sensitivity can
be adjusted by the potentiometer.
Specification
Pin Definition
1. Signal Output
2. GND
3. Power
Circuito implementado
Sample Code