Output devices

This week I decided to start working on the code and board I will need for my final project.
I started to make a schema ,for my input I will use a motion sensor to detect wen the ball will stop moving.
for my output I will need a speaker,several leds and a small motor.
  • My first atempt was to conect the Arduino to a buzzer and conect it to a sensor (I don't have the motion sensor now, so I used a photocell sensor instead ).

    I started with an Arduino code that will make a wavy sound as I play with the sensor
  • My second atempt was to conect the piezo sensor and a motor to the Arduino, and control the motor by the movment of the piezo sensor.
  • My theerd atempt was to conect all the components (piezo,speaker,and motor) to the Arduino , and control them the way I want.
  • After I finishet experamenting with the Arduino, I started to desing my board in eagle, you ken dawonlode the schematics/ board files if you want to add samthing or dawonlode thetrace/interior files.
    Mill the board and solder the components on it.

    I used sokets for the piezo sensor and motor and pin for the speaker .
    I conected the FTDI and the AVR to the board and borend the botloder. then check the pin nombers.

    And burn the code on the Attiny 44.
    
    // - LEAD MELODY
    int cycVec[] = {                   1136,1136 ,1073, 1073,     1276, 1276,	1073,	 1136, 	1136, 1136, 1073, 1073,	1701,	 1805, 1136, 1805,     1515,	1515,	1433,	1433,	  1701, 1701, 1433,1515,   1136, 1136, 1073, 1073,    1276, 1276, 1073, 1136,1276,1136};
    int noteDurations [] = {  440	,220	,466	, 466	,       392, 392, 233, 1320, 440	,220, 466, 466, 294, 277,	220, 554, 330, 165,            349, 349, 294, 294,	   174, 990	, 440, 220,       466, 466, 392, 392,           233, 220, 196, 440, 220, 220};
    int noteLength = 34;
    int delayInBetween = 3;
    int BPS = 10;
    
    // this constant won't change:
    const int piezoPin = 2;    // the pin that the piezo is attached to
    const int motorPin = 3;       // the pin that the motor is attached to
    
    long motorTime = 0;
    int piezoState = 0;
    
    
      int ledOne= 10;
      int ledTwo= 9;
      int ledThree= 4;
    
    void setup() {  
      pinMode(piezoPin, INPUT);  // initialize the button pin as a input:
      pinMode(motorPin, OUTPUT);
     pinMode(ledOne, OUTPUT);
     pinMode(ledTwo, OUTPUT);
     pinMode(ledThree, OUTPUT);
    
      // initialize serial communication:
    
    
        int speaker =7;
      pinMode(speaker, OUTPUT);
      for (int m=0;m {
        noteDurations[m] = (noteDurations[m])/BPS;
        //pauseDuration[k] = pauseDuration[k]*1000;
      }
    }
    
    
    void loop() {
      
      //  piezoState = digitalRead(piezoPin);  // read the pushbutton i
      //  Serial.println(piezoState);  
      int speaker =7;
      int temp;
      int cycNum;
      int cyc;
      if ( motorTime == 0 ) {
        if ( detectMovement() ) {
            
          digitalWrite(motorPin, HIGH);
         delay(5000);
          digitalWrite(motorPin, LOW);
         delay(400);
         digitalWrite(ledOne, HIGH);
       delay (30);  
          digitalWrite(ledTwo, HIGH); 
          delay(300);
           digitalWrite(ledThree, HIGH);
           delay (300);
                 digitalWrite(speaker, LOW); 
          digitalWrite(ledOne, LOW);  
          digitalWrite(ledTwo, LOW); 
           digitalWrite(ledThree,LOW);
         
            for (int thisNote = 0; thisNote {
    
        for (int i=0;i {
          digitalWrite(speaker, HIGH);  
         digitalWrite(ledOne, HIGH);  
          digitalWrite(ledTwo, HIGH); 
           digitalWrite(ledThree, HIGH); 
          delayMicroseconds(cycVec[thisNote]);
          digitalWrite(speaker, LOW); 
          digitalWrite(ledOne, LOW);  
          digitalWrite(ledTwo, LOW); 
           digitalWrite(ledThree,LOW);
          delayMicroseconds(cycVec[thisNote]);
        }
       
      }
          
        }
      } 
      else {
        if ( (millis()-motorTime)>10000 ) {
          motorTime = 0;
          digitalWrite(motorPin, LOW);
         // startPlayback(sample, sizeof(sample));   
        } 
      }
    
    
    }
    
    
    You ken dawonlode the Arduino files hare.
    Check evrithing workes on your board and make modefection in the code if nesasery.

    Success.
  •