Roll It Measure It

About the project

An invention doesn’t have to complicated but it has to be useful for the humankind.

Project info

Difficulty: Moderate

Platforms: ArduinoAtmel

Estimated time: 1 week

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Rotary Encoder Rotary Encoder x 1
Arduino Nano V3 Arduino Nano V3 x 1
Atmega328pb Ind Temp Qfn/mlf Atmega328pb Ind Temp Qfn/mlf x 1
resistors resistors x 1
capacitors capacitors x 1
Lithium Ion Polymer Battery - 3.7v 500mah Lithium Ion Polymer Battery - 3.7v 500mah x 1
Monochrome 0.96" Oled Graphic Display Monochrome 0.96" Oled Graphic Display x 1
tp4056 tp4056 lithium ion battery charger ic x 1
AMS117 AMS117 Low dropout regulator x 1

View all

Software apps and online services

Arduino ide Arduino ide for program the arduino
proteus proteus simulation purpose
eagle eagle schematic and PCB designing
FUSION360 FUSION360 for 3d modelling and rendering

Hand tools and fabrication machines

soldering iron soldering iron x 1
multimeter multimeter x 1

Story



Simulation video link:QINK

I made this circuit only for simulation purpose. So, I didn’t include battery charging circuits and battery here. since I couldn't able to find the rotary encoder in proteus I used a motor encoder for simulation purpose. Here I connected the output A and B of the encoder to GPIO pins of atmega328. And I followed usual connection and program for OLED. and here I represented the rotary encoder using a separate button. And by pressing that you can see variation information like battery percentage, measured distance in different units (mm, cm, M).and by tweaking the program a bit you can assign any functionality to that button. Like one click to measure and double click to battery percentage and so on. Since it just a prototype I didn’t use any filter circuit in rotary encoder. 

Code:


  1. #include <Wire.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_SSD1306.h>
  4.  
  5. int pin1 = 2;
  6. int pin2 = 3;
  7. int pin3 = 5;
  8. int AnalogPin=A5;
  9.  
  10. int Nticks = 0;
  11. int State;
  12. int LastState;
  13. int counter=0;
  14. int counter_state;
  15. int prestate=0;
  16.  
  17. const float pi = 3.14;
  18. const float R = 3.45;
  19. float batAnalog=0;
  20. int bat=0;
  21. const int N = 40;
  22.  
  23. float distance = 0;
  24. float distance1=0;
  25. float distance2=0;
  26. String thisString;
  27.  
  28. #define SCREEN_WIDTH 128
  29. #define SCREEN_HEIGHT 64
  30. #define OLED_MOSI 9
  31. #define OLED_CLK 10
  32. #define OLED_DC 11
  33. #define OLED_CS 12
  34. #define OLED_RESET 13
  35. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
  36. OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  37.  
  38. void setup() {
  39. Serial.begin(9600);
  40. pinMode (pin1 ,INPUT_PULLUP);
  41. pinMode (pin2 ,INPUT_PULLUP);
  42. pinMode(pin3,INPUT);
  43. if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
  44. Serial.println(F("SSD1306 allocation failed"));
  45. }
  46. delay(2000);
  47. display.clearDisplay();
  48. display.setTextSize(1);
  49. display.setTextColor(WHITE);
  50.  
  51. }
  52.  
  53. void loop() {
  54.  
  55. counter_state=digitalRead(pin3);
  56. if(counter_state==HIGH && prestate==0)
  57. {
  58. if(counter<=3)
  59. {
  60. counter++;
  61. prestate=1;
  62. }
  63. }
  64. else if(counter_state==LOW)
  65. {
  66. prestate=0;
  67. }
  68. if(counter>3)
  69. {
  70. counter=0;
  71. }
  72. Serial.print("count");
  73. Serial.println(counter);
  74. State = digitalRead(pin1);
  75. if (State != LastState){
  76. if (digitalRead(pin2) != State) {
  77. Nticks ++;
  78. }
  79. else {
  80. Nticks --;
  81. }
  82. }
  83.  
  84. distance = ((2*pi*R)/N) * Nticks ;
  85. distance=distance*-1;
  86. thisString = String(distance);
  87. LastState = State;
  88.  
  89. if (counter==0)
  90. {
  91. display.setCursor(10,10);
  92. display.print(distance);
  93. display.print(" Cm");
  94. display.display();
  95. Serial.println(distance);
  96. display.clearDisplay();
  97. }
  98. if (counter==1)
  99. {
  100. distance1=(distance/100);
  101. display.setCursor(10,10);
  102. display.print(distance1);
  103. display.print(" M");
  104. display.display();
  105. Serial.println(distance);
  106. display.clearDisplay();
  107. }
  108. if (counter==2)
  109. {
  110. distance2=(distance*10);
  111. display.setCursor(10,10);
  112. display.print(distance2);
  113. display.print(" mm");
  114. display.display();
  115. Serial.println(distance);
  116. display.clearDisplay();
  117. }
  118. if(counter==3)
  119. {
  120. batAnalog=analogRead(A5);
  121. {
  122. batAnalog=(batAnalog*5.0)/1024.0;
  123. delay(500);
  124. bat=((batAnalog/5.0)*100);
  125. display.setCursor(10,10);
  126. display.print("Battery aval ");
  127. display.print(bat);
  128. display.print("%");
  129. display.display();
  130. Serial.println(bat);
  131. display.clearDisplay();
  132. }
  133. }
  134. }


I have made a schematic in eagle that you can refer and I have also made a 3d enclosure for this project.so it will look more cool and easily portable. You can find those files in my GitHub repository. Since I have small amount of time available in midst of my college works, I have added some of the fundamental features only guys. But in future I am planning to add some features to it by integrating some sensors, own designed small encoder to make it compact and a better display panel.so guys stay tuned for updates. 

Guys you may think this not a complicated invention but it is a useful one.as I mentioned earlier 

An invention doesn’t have to complicated but it has to be useful for the humankind. 

And I believe this project satisfies this wise quote. 

Ok guys that’s it. I guess It's time for you to hit your workstation and make something useful that will make the world a better place. 









Schematics, diagrams and documents

PCB

CAD, enclosures and custom parts

3d modeled enclosure

Go to download

Code

roll it

Roll IT code

Credits

Leave your feedback...