Arduino Smart Gym Bar
Very motivating and Interesting Gym bar
Devices & Components
1
Arduino Uno Rev3
1
1Sheeld
1
Ultrasonic Sensor - HC-SR04 (Generic)
1
Breadboard (generic)
1
1Sheeld
1
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
Here's the Code
arduino
1/* This code : Counts the number of Pull ups, 2Plays Music during workout,Post 3 on facebook when U reach a milestone , 4auto Pause Music and Auto reset the counter 5 6Created By: Khatab Salah 7if you need help or have any notices Contact 8 me 9at: Khatab163@gmail.com*/ 10 11#define CUSTOM_SETTINGS 12#define INCLUDE_MUSIC_PLAYER_SHIELD 13#define 14 INCLUDE_TERMINAL_SHIELD 15#define INCLUDE_TEXT_TO_SPEECH_SHIELD 16#define INCLUDE_FACEBOOK_SHIELD 17/* 18 Include 1Sheeld library. */ 19#include <OneSheeld.h> 20/* UltraSonic library. 21 */ 22#include "Ultrasonic.h" 23 24Ultrasonic ultrasonic(11, 10); //(Trig,Echo) 25boolean 26 flag, speechFlag; 27int i,n; 28void setup() 29{ 30 /*Start communication*/ 31 32 OneSheeld.begin(); 33} 34 35void loop() { 36 /* detect motion within 70cm*/ 37if(ultrasonic.Ranging(CM)<70) 38{ 39 40 /* check brevious State of the sensor */ 41 if(flag==0) 42 { 43 /* 44 Display the number on the terminal*/ 45 Terminal.println(n); 46 /* 47 Set the volume. */ 48 MusicPlayer.setVolume(5); 49 /* Turn on the 50 music. */ 51 MusicPlayer.play(); 52 /*change the state of the sensor*/ 53 54 flag=1; 55 /* reset timer*/ 56 i=0; 57 speechFlag 58 = 0; 59 /* increase counter by 1 */ 60 n++; 61 /*Tells the 62 current number using text-to-speech */ 63 String s = ""; 64 s.concat(n); 65 66 TextToSpeech.say(s); 67 } 68 69} 70else if(ultrasonic.Ranging(CM)>=70) 71 72 { 73 /* reset sensor state */ 74 flag=0; 75 /*wait half second Every 76 Iteration */ 77 delay(500); 78 i++; 79 } 80 /* Facebook Post when 81 you achieve a milestone */ 82 if (n=10) 83 { 84 Facebook.post(" yeaaah 85 , a new milestone Achieved :D "); 86 87 } 88 /* Pause music After 89 20 Iteration Away from sensor (10 Seconds) */ 90 if(i>=20) 91 { 92 MusicPlayer.pause(); 93 94 95 } 96 /* Reset Progress after 60 Iteration Away from sensor (30 Seconds*/ 97 98 if(i>=60 && speechFlag == 0) 99 { 100 TextToSpeech.say("You got away 101 for too long, progress reset"); 102 /* Reset Counter */ 103 n=0; 104 105 106 speechFlag = 1; 107 } 108}
Here's the Code
arduino
1/* This code : Counts the number of Pull ups, 2Plays Music during workout,Post on facebook when U reach a milestone , 3auto Pause Music and Auto reset the counter 4Created By: Khatab Salah 5if you need help or have any notices Contact me 6at: Khatab163@gmail.com*/ 7 8#define CUSTOM_SETTINGS 9#define INCLUDE_MUSIC_PLAYER_SHIELD 10#define INCLUDE_TERMINAL_SHIELD 11#define INCLUDE_TEXT_TO_SPEECH_SHIELD 12#define INCLUDE_FACEBOOK_SHIELD 13/* Include 1Sheeld library. */ 14#include <OneSheeld.h> 15/* UltraSonic library. */ 16#include "Ultrasonic.h" 17 18Ultrasonic ultrasonic(11, 10); //(Trig,Echo) 19boolean flag, speechFlag; 20int i,n; 21void setup() 22{ 23 /*Start communication*/ 24 OneSheeld.begin(); 25} 26 27void loop() { 28 /* detect motion within 70cm*/ 29if(ultrasonic.Ranging(CM)<70) 30{ 31 /* check brevious State of the sensor */ 32 if(flag==0) 33 { 34 /* Display the number on the terminal*/ 35 Terminal.println(n); 36 /* Set the volume. */ 37 MusicPlayer.setVolume(5); 38 /* Turn on the music. */ 39 MusicPlayer.play(); 40 /*change the state of the sensor*/ 41 flag=1; 42 /* reset timer*/ 43 i=0; 44 speechFlag = 0; 45 /* increase counter by 1 */ 46 n++; 47 /*Tells the current number using text-to-speech */ 48 String s = ""; 49 s.concat(n); 50 TextToSpeech.say(s); 51 } 52 53} 54else if(ultrasonic.Ranging(CM)>=70) 55 { 56 /* reset sensor state */ 57 flag=0; 58 /*wait half second Every Iteration */ 59 delay(500); 60 i++; 61 } 62 /* Facebook Post when you achieve a milestone */ 63 if (n=10) 64 { 65 Facebook.post(" yeaaah , a new milestone Achieved :D "); 66 67 } 68 /* Pause music After 20 Iteration Away from sensor (10 Seconds) */ 69 if(i>=20) 70 { 71 MusicPlayer.pause(); 72 73 } 74 /* Reset Progress after 60 Iteration Away from sensor (30 Seconds*/ 75 if(i>=60 && speechFlag == 0) 76 { 77 TextToSpeech.say("You got away for too long, progress reset"); 78 /* Reset Counter */ 79 n=0; 80 81 speechFlag = 1; 82 } 83}
Downloadable files
Circuit Diagram
Circuit Diagram
Circuit Diagram
Comments
Only logged in users can leave comments