Dispenser with Servo that rotates on alarm. ERROR.

I’m in an electronic class at my college and basically my professor threw us into arduino programming for our final project without ever teaching it before. I have no background knowledge of C++ programming or arduino programming. I’ve never used an arduino, nor have I ever programmed before.

If anyone can help me get this code correct so I can at least pass this class, I would be forever grateful!!

Attatched is my code currently.

My error codes are as follows:

Arduino: 1.6.12 (Windows 10), Board: “Arduino/Genuino Uno”

project:30: error: stray ‘\342’ in program

{ When “morningAlarm� time reached do this… if (sensorValue < 341)}

^

project:30: error: stray ‘\200’ in program

project:30: error: stray ‘\234’ in program

project:30: error: stray ‘\342’ in program

project:30: error: stray ‘\200’ in program

project:30: error: stray ‘\235’ in program

project:30: error: stray ‘\342’ in program

project:30: error: stray ‘\200’ in program

project:30: error: stray ‘\246’ in program

project:32: error: stray ‘\342’ in program

If potentiometer value is less than 341 do this… for (int i=1; i<=100; i=i+1 ) Repeat the following code 100 times.

^

project:32: error: stray ‘\200’ in program

project:32: error: stray ‘\246’ in program

project:34: error: stray ‘\342’ in program

Serial.println(“Activate Servo�);

^

project:34: error: stray ‘\200’ in program

project:34: error: stray ‘\234’ in program

project:34: error: stray ‘\342’ in program

project:34: error: stray ‘\200’ in program

project:34: error: stray ‘\235’ in program

project:35: error: stray ‘\342’ in program

Print “Activate Servo� on serial monitor. myservo.write(110,240,true);

^

project:35: error: stray ‘\200’ in program

project:35: error: stray ‘\234’ in program

project:35: error: stray ‘\342’ in program

project:35: error: stray ‘\200’ in program

project:35: error: stray ‘\235’ in program

project:40: error: stray ‘\342’ in program

{ if (sensorValue > 341 && sensorValue < 682) If potentiometer value is between 341 and 682 do this… { for (int i=1; i<=80; i=i+1 ) Repeat the following code 80 times.

^

project:40: error: stray ‘\200’ in program

project:40: error: stray ‘\246’ in program

project:41: error: stray ‘\342’ in program

Serial.println(“Activate Servo�);

^

project:41: error: stray ‘\200’ in program

project:41: error: stray ‘\234’ in program

project:41: error: stray ‘\342’ in program

project:41: error: stray ‘\200’ in program

project:41: error: stray ‘\235’ in program

project:42: error: stray ‘\342’ in program

Print “Activate Servo� on serial monitor. myservo.write(110,240,true);

^

project:42: error: stray ‘\200’ in program

project:42: error: stray ‘\234’ in program

project:42: error: stray ‘\342’ in program

project:42: error: stray ‘\200’ in program

project:42: error: stray ‘\235’ in program

project:46: error: stray ‘\342’ in program

{ if (sensorValue > 682 && sensorValue < 1200) If potentiometer value is between 682 and 1200 do this… { for (int i=1; i<=60; i=i+1 ) Repeat the following code 60 times.

^

project:46: error: stray ‘\200’ in program

project:46: error: stray ‘\246’ in program

project:47: error: stray ‘\342’ in program

Serial.println(“Activate Servo�);

^

project:47: error: stray ‘\200’ in program

project:47: error: stray ‘\234’ in program

project:47: error: stray ‘\342’ in program

project:47: error: stray ‘\200’ in program

project:47: error: stray ‘\235’ in program

In file included from C:\Users\P\Documents\Arduino\project\project.ino:12:0:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h: In function ‘void loop()’:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h:112:16: error: redeclaration of ‘_timer1’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

^

In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

from C:\Users\P\Documents\Arduino\project\project.ino:11:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:16: note: previous declaration ‘loop()::timer16_Sequence_t _timer1’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:12:0:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h:112:25: error: redeclaration of ‘_Nbr_16timers’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

^

In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

from C:\Users\P\Documents\Arduino\project\project.ino:11:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:25: note: previous declaration ‘loop()::timer16_Sequence_t _Nbr_16timers’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:12:0:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h:112:41: error: conflicting declaration ‘typedef enum loop()::timer16_Sequence_t timer16_Sequence_t’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

^

In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

from C:\Users\P\Documents\Arduino\project\project.ino:11:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:41: note: previous declaration as ‘typedef enum loop()::timer16_Sequence_t timer16_Sequence_t’

typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:12:0:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h:133:3: error: conflicting declaration ‘typedef struct loop()::ServoPin_t ServoPin_t’

} ServoPin_t ;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:11:0:

C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:87:3: note: previous declaration as ‘typedef struct loop()::ServoPin_t ServoPin_t’

} ServoPin_t ;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:12:0:

C:\Users\P\Documents\Arduino\libraries\VarSpeedServo-master/VarSpeedServo.h:140:3: error: conflicting declaration ‘typedef struct loop()::servo_t servo_t’

} servo_t;

^

In file included from C:\Users\P\Documents\Arduino\project\project.ino:11:0:

C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:92:3: note: previous declaration as ‘typedef struct loop()::servo_t servo_t’

} servo_t;

^

In file included from C:\Users\P\Documents\Arduino\libraries\TimeAlarms/TimeAlarms.h:7:0,

from C:\Users\P\Documents\Arduino\project\project.ino:13:

C:\Users\P\Documents\Arduino\libraries\arduino_802316/TimeLib.h:33:8: error: expected unqualified-id before string constant

extern “C++” {

^

project:50: error: expected ‘}’ at end of input

myservo.write(0,240,true); Move servo arm back to 0degrees, with a speed of 240 and wait until complete delay(500);}}}

^

exit status 1
stray ‘\342’ in program

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

project.ino (2.05 KB)

You should use the code button </> and properly indent your code so it looks like this and is easy to read

void setup() {
  // put your setup code here, to run once:

}

void loop() {
      // put your main code here, to run repeatedly:

    #include <Servo.h>
    #include <VarSpeedServo.h>
    #include <TimeAlarms.h>
    #include <Time.h>
    #include <TimeLib.h>

    Servo myservo
    const int servopin = 9
    int potpin = 0
    int val

    void setup() {
        Serial.begin(9600); Sets the data rate setTime(8,29,50,1,1,11);
        Manually set the time Alarm.alarmRepeat(8,30,0, MorningAlarm);
        myservo.attach(servoPin); 
        object myservo.write(0,255,true);

        void loop() { 
            int sensorValue = analogRead(A0);
            Serial.println(sensorValue);
            void MorningAlarm() {
                When “morningAlarm” time reached do this… if (sensorValue < 341)
            }
            { 
              If potentiometer value is less than 341 do this… for (int i=1; i<=100; i=i+1 ) Repeat the following code 100 times. 
            }
            Serial.println(“Activate Servo”); 
            Print “Activate Servo” on serial monitor. myservo.write(110,240,true); 
            Move servo arm to 110degrees, with a speed of 240 and wait until complete delay(500);
            myservo.write(0,240,true); 
            Move servo arm back to 0degrees, with a speed of 240 and wait until complete delay(500);
        }
    }

    { 
        if (sensorValue > 341 && sensorValue < 682) If potentiometer value is between 341 and 682 do this… { for (int i=1; i<=80; i=i+1 ) Repeat the following code 80 times. 
            Serial.println(“Activate Servo”); 
            Print “Activate Servo” on serial monitor. myservo.write(110,240,true); 
            Move servo arm to 110degrees, with a speed of 240 and wait until complete delay(500); myservo.write(0,240,true);
            Move servo arm back to 0degrees, with a speed of 240 and wait until complete delay(500);
        }
    }

    { 
        if (sensorValue > 682 && sensorValue < 1200) If potentiometer value is between 682 and 1200 do this… { for (int i=1; i<=60; i=i+1 ) Repeat the following code 60 times.
            Serial.println(“Activate Servo”); 
            Print "Activate Servo" on serial monitor. myservo.write(110,240,true); 
            Move servo arm to 110degrees, with a speed of 240 and wait until complete delay(500); 
            myservo.write(0,240,true); Move servo arm back to 0degrees, with a speed of 240 and wait until complete delay(500);
        }
    }
}

I don’t believe I have ever seen a mess like this. There is so much wrong that I don’t know where to start.

You seem to have comments that are not preceeded by //

You are trying to define functions inside other functions. That is not allowed

You have duplicate function names. That is not allowed.

You have code that is not inside any function. That is not allowed.

…R

Here is your program in a form that will compile.

#include <VarSpeedServo.h>
#include <TimeAlarms.h>
#include <TimeLib.h>

VarSpeedServo myservo;

const int servoPin = 9;
const int potPin = A0;

void setup() {
  Serial.begin(9600); // Sets the data rate
  setTime(8, 29, 50, 1, 1, 11);  // Manually set the time
  Alarm.alarmRepeat(8, 30, 0, MorningAlarm);
  myservo.attach(servoPin);  // object myservo.write(0, 255, true);
}

void loop() {
  Serial.println(analogRead(potPin));
  delay(1000);  // Don't want to flood the output
}


// When “morningAlarm” time reached do this…
void MorningAlarm() {
  int sensorValue = analogRead(potPin);
  
  if (sensorValue < 341) {
    // If potentiometer value is less than 341 do this…

    for (int i = 1; i <= 100; i = i + 1 ) {
      // Repeat the following code 100 times.
      Serial.println("Activate Servo");
      myservo.write(110, 240, true); // Move servo arm to 110degrees, with a speed of 240
      delay(500); // Wait until complete
      myservo.write(0, 240, true); // Move servo arm back to 0degrees, with a speed of 240
      delay(500); // Wait until complete
    }
  }

  if (sensorValue > 341 && sensorValue < 682) { // If potentiometer value is between 341 and 682 do this…
    for (int i = 1; i <= 80; i = i + 1 ) {
      // Repeat the following code 80 times.
      Serial.println("Activate Servo");
      myservo.write(110, 240, true);  // Move servo arm to 110degrees, with a speed of 240
      delay(500); // Wait until complete
      myservo.write(0, 240, true);  // Move servo arm back to 0 degrees, with a speed of 240
      delay(500); // Wait until complete
    }
  }

  if (sensorValue > 682 && sensorValue < 1200) {  // Analog input only goes to 1023
    //If potentiometer value is between 682 and 1200 do this…
    for (int i = 1; i <= 60; i = i + 1 ) {
      //Repeat the following code 60 times.
      Serial.println("Activate Servo");
      myservo.write(110, 240, true); // Move servo arm to 110degrees, with a speed of 240 
      delay(500);  // Wait until complete
      myservo.write(0, 240, true); // Move servo arm back to 0degrees, with a speed of 240
      delay(500); // Wait until complete
    }
  }
}

My God.

Dude, do a C++ tutorial. There are heaps of them on the web - pick one. It scarcely needs to be said that

1 - if learning a bit of C++ is a requirement for your course; and
2 - you don't do it; and
3 - you get other people to write your assignments for you,

Then not only do you not deserve to pass your course, you have committed academic fraud. If you feel that you oughtn't have to learn programming to pass an electronics course, I defy you to find an electronic device manufactured these days without a microcontroller. Hell: drills and power saws these days have microcontrollers in them to control the speed and manage heat.

Do a C++ tutorial. There are heaps of them on the web - pick one. Don't complain that your prof hasn't taught you this stuff. Once you get out of high school, your prof isn't there to teach you: they are just there to tell you what to need to study.