Académique Documents
Professionnel Documents
Culture Documents
com/en/s2/social_invite_m/2606265
temp-mail.org
zbigz
10.40.26
10.24
http://myfastfile.com/
openload.co
http://torrent2ddl.com/ then premiumtoss
http://seedr.cc/
dirrect-torrent
e: lilauy18
Password: Uec7HqyE
/* Motion Controlled desk lamp by using Arduino Relay Safety Box and Ultrasonic
Sensor
Dev: Michalis Vasilakis // Date: 20/5/2015 // www.ardumotive.com
*/
//Libraries
#include <Ultrasonic.h>
//Constants
Ultrasonic ultrasonic(A0,A1);
int relayPin=3;
int ledPin = 4;
int distance;
//Variables
int var;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,HIGH);
//Led on while waiting to set sensor to
stable point and "see" something like a wall.
delay(5000);
//Delay 5 sec...
distance=ultrasonic.Ranging(CM);//Read ranging and save it to distance.
digitalWrite(ledPin, LOW);
//Led off, starting main program
...
Serial.begin(9600);
}
void loop()
{
var=ultrasonic.Ranging(CM); //Read ranging and store it to 'var' variabl
e
Serial.println(var);
//Send high to relayPin when var will be lower from 10% of distance
if ( var < (distance-(distance*0.10))){
digitalWrite(relayPin, HIGH);
}
else{
digitalWrite(relayPin, LOW);
}
delay(500); //Read new value every 0.5sec
}
This is a short code and only 20% of what i have in mind to implement with this
embedded system.
but, i hope it can help anybody who is new in servo control and is in need of a
quick instruction.
i hope it is not to complicated. so what basically happens is that my ultrasonic
sensor is mounted to my servo and is facing a 90 degree angle when it comes acr
oss an obstacle less than or equal to 20cm in this direction the servo will rota
te to the right. please also keep in mind that if 0 gives you a full rotation to
the left then the full right rotation of that servo is 180. Thank you and Enjoy
. :)
#include // include servo library
#define trigpin 5//set trigpin
#define echopin 6//set echopin
Servo myservo;// declare servo name type servo
int duration, distance;//declare variable for unltrasonic sensor
void setup() {
Serial.begin(9600);
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
myservo.attach(2);// attach your servo
myservo.writeMicroseconds(1500);
// put your setup code here, to run once:
}
void loop() {
myservo.write(90);// always set servo to 90 to position it to the middle
//ultrasonic code
digitalWrite(trigpin,HIGH);
_delay_ms(500);
digitalWrite(trigpin, LOW);
duration=pulseIn(echopin,HIGH);
distance=(duration/2)/29.1;
if(distance <=20)// if ultrasonic sensor detects an obstacle less than 20cm in
90 degree angle.
{
myservo.write(0); //servo rotates at full speed to the right
delay(600);
}
else
{
myservo.write(90);// else servo stays at 90 degree angle.
delay(600);
}
Serial.print("cm"); //print distance unit cm
Serial.println(distance);//distance
// put your main code here, to run repeatedly:
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "Ultrasonic.h"
Ultrasonic sonar(2,3);
int sonarPreviousMillis = 0;
unsigned long sonarCurrentMillis;
int sonarInterval = 500;
int range;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int servoVal;
// variable to read the value from the analog pin
int servoPreviousMillis = 0;
unsigned long servoCurrentMillis;
int servoInterval = 5;
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
head();
runSonar();
}
void head(){
servoCurrentMillis = millis();
if(servoCurrentMillis - servoPreviousMillis > servoInterval) {
servoPreviousMillis = servoCurrentMillis;
servoVal = analogRead(potpin);
// reads the value of the potentio
meter (value between 0 and 1023)
servoVal = map(servoVal, 0, 1023, 0, 179);
// scale it to use it with th
e servo (value between 0 and 180)
myservo.write(servoVal);
}
}
void runSonar(){
sonarCurrentMillis = millis();
if(sonarCurrentMillis - sonarPreviousMillis > sonarInterval) {
sonarPreviousMillis = sonarCurrentMillis;
range = sonar.Ranging(CM);
if (range == 0){
Serial.println("too far");
}else{
Serial.print(sonar.Ranging(CM));
Serial.println("cm");
}
}
}
xxxxxxxxxxxxxxxx
#include <Servo\Servo.h>
#define echoPin 7
#define trigPin 8
int maximumRange = 400;
int minimumRange = 0;
int angle;
long duration, distance;
Servo myServo;
void setup()
{
Serial.begin(9600);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
myServo.attach(9);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration / 58.2;
angle = map(distance, minimumRange, maximumRange, 0, 179);
Serial.print("Distance = ");
Serial.print(distance);
Serial.print(" Angle = ");
Serial.println(angle);
myServo.write(angle);
delay(50);
}