Tilt sensor

De Tilt sensor bevat een balletje. Zodra de Tilt sensor wordt bewogen wordt de stroom kring rond. De Arduino meet of de stroom kring rond is. Via een stukje code zet de Arduino stroom op een andere poort waardoor er een stroomkring rond komt. In deze proefopstelling brand het blauwe ledje als de sensor beweegt. De code die ik hiervoor heb gebruikt komt uit de lijst met voorbeeld codes vanuit de Arduino IDE.

 

Hier zie je het circuit

IMG_20150909_095742

 

De code heb ik veranderd zodat het ledje langer blijft branden, ook als de sensor niet meer beweegt.

 

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 9; // the number of the pushbutton pin
const int ledPin = 11; // the number of the LED pin
 
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
 
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
 
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
 
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH); //Motor input
delay(2000);
Serial.println("AAN");
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Inspiratie

Leave a Reply

Your email address will not be published. Required fields are marked *