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
Estimated time: 1 week
License: GNU General Public License, version 3 or later (GPL3+)
Items used in this project
Hardware components
View all
Software apps and online services
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:
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- int pin1 = 2;
- int pin2 = 3;
- int pin3 = 5;
- int AnalogPin=A5;
- int Nticks = 0;
- int State;
- int LastState;
- int counter=0;
- int counter_state;
- int prestate=0;
- const float pi = 3.14;
- const float R = 3.45;
- float batAnalog=0;
- int bat=0;
- const int N = 40;
- float distance = 0;
- float distance1=0;
- float distance2=0;
- String thisString;
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- #define OLED_MOSI 9
- #define OLED_CLK 10
- #define OLED_DC 11
- #define OLED_CS 12
- #define OLED_RESET 13
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
- OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- void setup() {
- Serial.begin(9600);
- pinMode (pin1 ,INPUT_PULLUP);
- pinMode (pin2 ,INPUT_PULLUP);
- pinMode(pin3,INPUT);
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
- Serial.println(F("SSD1306 allocation failed"));
- }
- delay(2000);
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- }
- void loop() {
- counter_state=digitalRead(pin3);
- if(counter_state==HIGH && prestate==0)
- {
- if(counter<=3)
- {
- counter++;
- prestate=1;
- }
- }
- else if(counter_state==LOW)
- {
- prestate=0;
- }
- if(counter>3)
- {
- counter=0;
- }
- Serial.print("count");
- Serial.println(counter);
- State = digitalRead(pin1);
- if (State != LastState){
- if (digitalRead(pin2) != State) {
- Nticks ++;
- }
- else {
- Nticks --;
- }
- }
- distance = ((2*pi*R)/N) * Nticks ;
- distance=distance*-1;
- thisString = String(distance);
- LastState = State;
- if (counter==0)
- {
- display.setCursor(10,10);
- display.print(distance);
- display.print(" Cm");
- display.display();
- Serial.println(distance);
- display.clearDisplay();
- }
- if (counter==1)
- {
- distance1=(distance/100);
- display.setCursor(10,10);
- display.print(distance1);
- display.print(" M");
- display.display();
- Serial.println(distance);
- display.clearDisplay();
- }
- if (counter==2)
- {
- distance2=(distance*10);
- display.setCursor(10,10);
- display.print(distance2);
- display.print(" mm");
- display.display();
- Serial.println(distance);
- display.clearDisplay();
- }
- if(counter==3)
- {
- batAnalog=analogRead(A5);
- {
- batAnalog=(batAnalog*5.0)/1024.0;
- delay(500);
- bat=((batAnalog/5.0)*100);
- display.setCursor(10,10);
- display.print("Battery aval ");
- display.print(bat);
- display.print("%");
- display.display();
- Serial.println(bat);
- display.clearDisplay();
- }
- }
- }
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.
Leave your feedback...