Stap 5: Met behulp van een LED en een geringe blootstelling camera te tonen de breedte MaxSonic een object detecteert.
Met behulp van een camara met geringe blootstelling zijn we erin geslaagd om vast te leggen van het lezen van de breedte van de sensoren in een enkel schot. Dit maakt het gemakkelijker op de hoogte van de operats MaxSonic breedte in.
Arduino code:
//Please be respectful by acknowledging the author in the code if you use or modify it.<br>//Author: Bruce Allen//Edited By Runar and Marte 08.10.2014 //Date: 23/07/09 //Digital pin 7 for reading in the pulse width from the MaxSonar device. //This variable is a constant because the pin will not change throughout execution of this code. const int pwPin = 7; int led = 6; //variables needed to store values long pulse, inches, cm; void setup() { //This opens up a serial connection to shoot the results back to the PC console Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { pinMode(pwPin, INPUT); //Used to read in the pulse that is being sent by the MaxSonar device. //Pulse Width representation with a scale factor of 147 uS per Inch. pulse = pulseIn(pwPin, HIGH); //147uS per inch inches = pulse/147; //change inches to centimetres cm = inches * 2.54; Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(1); //If you don't want any distance limiter just remove the next 7 lines. if(cm<30){ digitalWrite(led,HIGH); } else{ digitalWrite(led,LOW); } }
We vonden de code hier http://playground.arduino.cc/Main/MaxSonar een LED en een limiter afstand toegevoegd.