The project investigates the synchronization of two bodies, bound by a spatial relationship and hierarchy. It has been realized by means of two continuous rotation servo and an ultrasonic sensor, connected to the Arduino.
Il progetto indaga sulla sincronizzazione di due corpi, vincolati da una relazione spaziale e da una gerarchia. E' stato realizzato tramite due servomotori a rotazione continua ed un sensore ad ultrasuoni collegati ad Arduino.
#include <Servo.h>
Servo servo1;  
Servo servo2;
int trig = 7;
int echo = 8;
int led = 11;
int led1 = 12;
 
void setup()
{
   servo1.attach(9);
  servo2.attach(10);
  pinMode( trig, OUTPUT );
  pinMode( echo, INPUT );
  pinMode( led, OUTPUT);
  pinMode( led1, OUTPUT);
  Serial.begin( 9600 );
}
void loop (){
  long durata;
  float dist, rel, r;
  int il;
 
  pinMode(trig, OUTPUT);                       
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(5);
  digitalWrite(trig, LOW);
 
  pinMode(echo,INPUT);
  durata = pulseIn(echo, HIGH);                  
  dist = microsecondsToCentimeters(durata);     
  rel = constrain(dist, 10, 30);              
  r = (rel-10)/20;                               
  il = map(rel, 10, 30, 255, 0);
 
 
  servo1.write(0);                              
  servo2.write(180*r);                         
 
  analogWrite(led, il);
  analogWrite(led1,HIGH);
 
  delay(100);
 
  Serial.print(rel);                            
  Serial.print("  -  ");
  Serial.print(il);
  Serial.println();
}
 
float microsecondsToCentimeters(float microseconds)
{
return microseconds / 29 / 2;

}
Synchroon
Published:

Synchroon

The project investigates the synchronization of two bodies, bound by a spatial relationship and hierarchy. It has been realized by means of two c Read More

Published: