Hi, my name is Hunter and I am somewhat new to Arduino. I have already created a project using Arduino Uno, but I want to transfer it to LilyPad. But it will not upload and says that it is not in sync. Can anyone help me please??
//Set the temperature pin input float temperature;
int temperaturePin = A0;
//Set temperature variable
float temperature;
//For serial communication set debug to true, for faster code set debug to false
boolean debug = true;
//Set time and cm for distance sensing
long duration, cm;
//Set pins for trig and echo
int buzzer = 8,trig = 10, echo = 9;
void setup()
{
if (debug) {
Serial.begin(9600);
}
pinMode(trig, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
temperature = (getVoltage(temperaturePin) + 0.5) * 100;
if (debug) {
Serial.print("Temperature: ");
Serial.println(temperature);
}
/* Give a short LOW pulse beforehand to ensure a clean HIGH pulse: */
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
//temp. compensated distance
cm = microsecondsToCentimeters(duration, temperature);
//distance without temp.
int old_way_cm = duration/58.2;
controlBuzzer(cm);
if (debug) {
Serial.print("Tempature compensated distance: ");
Serial.print(cm);
Serial.println(" cm");
Serial.print("Distance :");
Serial.println(old_way_cm);
Serial.print("Tempature: ");
Serial.println(temperature);
Serial.print("Duration: ");
Serial.println(duration);
}
delay(50);
}
float getVoltage(int pin)
{
//Converting from 0 to 1024 to 0 to 5v
return (analogRead(pin) * .004882814);
}
long microsecondsToCentimeters(long microseconds, long temp)
{
/*Multiplying the speed of sound through a certain temperature of
air by the //length of time it takes to reach the object and
back, divided by two */
return ((microseconds * (331.3 + 0.606 * temp)) / 2) / 10000;
}
void controlBuzzer(long distance)
{
if (distance <=10000 && distance >= 91){
Serial.print(distance);
Serial.println(" cm");
noTone(buzzer);
}
else if (distance <= 91 && distance >= 61){
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, 100);
delay(300);
noTone(buzzer);
}
else if (distance <= 61 && distance >= 30){
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, 200);
delay(300);
noTone(buzzer);
}
else if (distance <= 30 && distance >= 1){
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, 300);
delay(300);
noTone(buzzer);
}
else {
Serial.println("Out of range");
digitalWrite(buzzer, LOW);
}
}
Sketch uses 7,172 bytes (23%) of program storage space. Maximum is 30,720 bytes.
Global variables use 341 bytes (16%) of dynamic memory, leaving 1,707 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0