irina kim
Published © Apache-2.0

Of the cats, by the cats, for the cats

A toy for your lonely cat when you're not around.

BeginnerShowcase (no instructions)1,081
Of the cats, by the cats, for the cats

Things used in this project

Hardware components

WIZwiki-W7500
WIZnet WIZwiki-W7500
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

schemetic

Code

mbed

C/C++
#include "mbed.h"
#include "stdlib.h"  //For rand function 
#include "Servo.h"
#include "HCSR04.h"
HCSR04 sensor(D11, D12); //(Trig Pin, Echo Pin) 
Servo myservo(D6);
int main()
{
  	int number = 0;
        while(1){ 
		long d = sensor.distance(1);
        	printf("d = %d\r\n",d);   
		myservo = 0.5;   
		if(d<=25)    //25cm
	        {
			number = rand()%11;  //0~10    
			double a = number*0.1;
			printf("%d = %3f\r\n",number,a);                      
			myservo = number*0.1;
		}    
	wait(0.2); 
    }
}

Credits

irina kim

irina kim

12 projects • 24 followers

Comments