Components and supplies
1
Solderless Breadboard Half Size
1
Arduino UNO
1
SparkFun Micro OLED Breakout
1
Jumper wires (generic)
1
Ultrasonic Sensor - HC-SR04 (Generic)
Apps and platforms
1
Arduino IDE
1
sparkfun micro oled library
Project description
Code
Code
c_cpp
1#include <Wire.h> 2 3#include <SPI.h> 4 5#include <SFE_MicroOLED.h> 6#define PIN_RESET 9 // Connect RST to pin 9 7#define PIN_DC 8 // Connect DC to pin 8 8#define PIN_CS 10 // Connect CS to pin 10 9#define DC_JUMPER 0 10MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS); // SPI declaration 11//MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration 12 13int SCREEN_WIDTH = oled.getLCDWidth(); 14int SCREEN_HEIGHT = oled.getLCDHeight(); 15 16 17#define trigPin 3 18#define echoPin 2 19 20 21void setup() 22{ 23 // Serial.begin(9600); 24 pinMode(trigPin, OUTPUT); 25 pinMode(echoPin, INPUT); 26 oled.begin(); 27 oled.clear(PAGE); 28 oled.display(); 29 oled.clear(PAGE); 30 oled.clear(ALL); 31//arduino logo 32 oled.pixel(12,11); 33 oled.pixel(13,11); 34 oled.pixel(14,11); 35 oled.pixel(15,11); 36 oled.pixel(19,11); 37 oled.pixel(20,11); 38 oled.pixel(21,11); 39 oled.pixel(22,11); 40 oled.pixel(11,12); 41 oled.pixel(16,12); 42 oled.pixel(18,12); 43 oled.pixel(20,12); 44 oled.pixel(23,12); 45 oled.pixel(11,13); 46 oled.pixel(12,13); 47 oled.pixel(13,13); 48 oled.pixel(14,13); 49 oled.pixel(16,13); 50 oled.pixel(17,13); 51 oled.pixel(18,13); 52 oled.pixel(19,13); 53 oled.pixel(20,13); 54 oled.pixel(21,13); 55 oled.pixel(23,13); 56 oled.pixel(11,14); 57 oled.pixel(16,14); 58 oled.pixel(18,14); 59 oled.pixel(20,14); 60 oled.pixel(23,14); 61 oled.pixel(12,15); 62 oled.pixel(13,15); 63 oled.pixel(14,15); 64 oled.pixel(15,15); 65 oled.pixel(19,15); 66 oled.pixel(20,15); 67 oled.pixel(21,15); 68 oled.pixel(22,15); 69 oled.circle(17, 13, 8); 70 oled.setFontType(0); // Set the text to small (10 columns, 6 rows worth of characters). 71oled.setCursor(11, 30); 72oled.print("ARDUINO"); 73 oled.display(); 74 oled.clear(PAGE); 75 //arduino logo 76 delay(2000); 77} 78void loop() 79{ 80 oled.clear(PAGE); 81 oled.clear(ALL); 82 83 84 long duration, distance; 85 digitalWrite(trigPin, LOW); 86 delayMicroseconds(2); 87 digitalWrite(trigPin, HIGH); 88 delayMicroseconds(10); 89 digitalWrite(trigPin, LOW); 90 duration = pulseIn(echoPin, HIGH); 91 distance = (duration/2) / 29.1; 92 93//Serial.print(distance/100.0); 94// Serial.println(" m"); 95 96//Serial.print(distance/2.54); 97//Serial.println(" in."); 98 99 100 oled.setFontType(0); // Set the text to small (10 columns, 6 rows worth of characters). 101oled.setCursor(0, 0); // Set the text cursor to the upper-left of the screen. 102oled.print(distance/100.0); // print distance in meters 103oled.print(" m "); 104oled.print(distance/2.54); // Print distance in inches 105oled.print(" in."); 106oled.display(); 107 108 delay(100); 109} 110
Code
c_cpp
1#include <Wire.h> 2 3#include <SPI.h> 4 5#include <SFE_MicroOLED.h> 6#define PIN_RESET 9 // Connect RST to pin 9 7#define PIN_DC 8 // Connect DC to pin 8 8#define PIN_CS 10 // Connect CS to pin 10 9#define DC_JUMPER 0 10MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS); // SPI declaration 11//MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration 12 13int SCREEN_WIDTH = oled.getLCDWidth(); 14int SCREEN_HEIGHT = oled.getLCDHeight(); 15 16 17#define trigPin 3 18#define echoPin 2 19 20 21void setup() 22{ 23 // Serial.begin(9600); 24 pinMode(trigPin, OUTPUT); 25 pinMode(echoPin, INPUT); 26 oled.begin(); 27 oled.clear(PAGE); 28 oled.display(); 29 oled.clear(PAGE); 30 oled.clear(ALL); 31//arduino logo 32 oled.pixel(12,11); 33 oled.pixel(13,11); 34 oled.pixel(14,11); 35 oled.pixel(15,11); 36 oled.pixel(19,11); 37 oled.pixel(20,11); 38 oled.pixel(21,11); 39 oled.pixel(22,11); 40 oled.pixel(11,12); 41 oled.pixel(16,12); 42 oled.pixel(18,12); 43 oled.pixel(20,12); 44 oled.pixel(23,12); 45 oled.pixel(11,13); 46 oled.pixel(12,13); 47 oled.pixel(13,13); 48 oled.pixel(14,13); 49 oled.pixel(16,13); 50 oled.pixel(17,13); 51 oled.pixel(18,13); 52 oled.pixel(19,13); 53 oled.pixel(20,13); 54 oled.pixel(21,13); 55 oled.pixel(23,13); 56 oled.pixel(11,14); 57 oled.pixel(16,14); 58 oled.pixel(18,14); 59 oled.pixel(20,14); 60 oled.pixel(23,14); 61 oled.pixel(12,15); 62 oled.pixel(13,15); 63 oled.pixel(14,15); 64 oled.pixel(15,15); 65 oled.pixel(19,15); 66 oled.pixel(20,15); 67 oled.pixel(21,15); 68 oled.pixel(22,15); 69 oled.circle(17, 13, 8); 70 oled.setFontType(0); // Set the text to small (10 columns, 6 rows worth of characters). 71oled.setCursor(11, 30); 72oled.print("ARDUINO"); 73 oled.display(); 74 oled.clear(PAGE); 75 //arduino logo 76 delay(2000); 77} 78void loop() 79{ 80 oled.clear(PAGE); 81 oled.clear(ALL); 82 83 84 long duration, distance; 85 digitalWrite(trigPin, LOW); 86 delayMicroseconds(2); 87 digitalWrite(trigPin, HIGH); 88 delayMicroseconds(10); 89 digitalWrite(trigPin, LOW); 90 duration = pulseIn(echoPin, HIGH); 91 distance = (duration/2) / 29.1; 92 93//Serial.print(distance/100.0); 94// Serial.println(" m"); 95 96//Serial.print(distance/2.54); 97//Serial.println(" in."); 98 99 100 oled.setFontType(0); // Set the text to small (10 columns, 6 rows worth of characters). 101oled.setCursor(0, 0); // Set the text cursor to the upper-left of the screen. 102oled.print(distance/100.0); // print distance in meters 103oled.print(" m "); 104oled.print(distance/2.54); // Print distance in inches 105oled.print(" in."); 106oled.display(); 107 108 delay(100); 109} 110
Downloadable files
screen hookup
screen hookup

HC-SR04 hookup
HC-SR04 hookup
screen hookup
screen hookup

Comments
Only logged in users can leave comments