Author Topic: ultrasound light lifter  (Read 2165 times)


  • Newbie
  • *
  • Posts: 9
ultrasound light lifter
« on: June 09, 2017, 01:04:06 pm »
hi, i have a few digisparks and sr04 ultrasonic pingers. this will be my first attempt at a project using any kind of arduino type thing so i am hoping for some help from more experienced members.

i want to send a ping and measure the time, i suppose it will be in clock ticks.

if the ping shows more than 25cm i want to activate a bridge (op and inv op) to turn a motor clockwise.

if it is less than 20 cm i want to reverse the bridge and send motor anticlockwise.

if in the zone 20-25cm it is ok to sit and do nothing.

the process must repeat regular but does not really need to be more than every few minutes, or even daily is sufficient.

my last programming experience was in sinclair zx basic. if only i could  run that on the digispark i would be done in minutes, hardware and software!

is my goal realistic or am i wasting my time? i hope to start using modern tech instead of old cmos and ttl logic but dont know where to start.


  • Newbie
  • *
  • Posts: 34
Re: ultrasound light lifter
« Reply #1 on: June 12, 2017, 04:12:44 am »
Connect the Sensor to any two Digispark pins, copy the example code and change the pins in the code.
Code: [Select]
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
* Crated by Dejan Nedelkovski,
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
if (distance > 25){
  //HBridge code
if (distance < 20){
  //HBridge code