7. Input & Output device¶
This week we try the sensors on the arduino board .
First we must to download the sensors form the library.
Then we use an example to try the tempretaure sensor
After that, we try to connect a motor to the board and download a code to try it
I decided to try a sensor that will help me for my final project.
My idea is to have a sensor that can detect the motion of the chess playes to countdown his time for each time he makes a move.
The problem here is that the player must always hit the clock button.
so i was thinking about using motion sensor, then i decided to use a vibration sensor.
So I downloded the library
Then i used the accelerometer code.
This code shows you the values of X,Y and Z coordinate for the board.
I noteced that the z axis is around 0.9 so when i will do some distirbtion it must be chaged to a bigger value.
#include <Arduino_LSM9DS1.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Started");
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
Serial.println();
Serial.println("Acceleration in G's");
Serial.println("X\tY\tZ");
}
void loop() {
float x, y, z;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.println(z);
}
if (z>0.999) {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
delay(1000);
}
so i set these conditios
Unfortunatlly i found the sensor reading is not accurate but i tried to use it.
I want the LED to light up if the sensor feels any differnt in the vibrations.
It worked, but sometime it doesn’t.
I tried to use other sensor that can detect a vibration .
I used the code to take the reading
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(500); // delay in between reads for stability
}
I tried the first one and the reading was so random and don’t have a one value, it always varies
Then i tried the microphone sensor to see if there would be anychanges but again the reading was so random.